diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Psecio/Gatekeeper/GroupModel.php | 9 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/UserCollection.php | 26 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/Psecio/Gatekeeper/GroupModel.php b/src/Psecio/Gatekeeper/GroupModel.php index 137f00c..69d37d8 100644 --- a/src/Psecio/Gatekeeper/GroupModel.php +++ b/src/Psecio/Gatekeeper/GroupModel.php @@ -34,6 +34,15 @@ class GroupModel extends \Psecio\Gatekeeper\Model\Mysql 'description' => 'Date Updated', 'column' => 'updated', 'type' => 'datetime' + ), + 'users' => array( + 'description' => 'Users belonging to this group', + 'type' => 'relation', + 'relation' => array( + 'model' => '\\Psecio\\Gatekeeper\\UserCollection', + 'method' => 'findByGroupId', + 'local' => 'id' + ) ) ); diff --git a/src/Psecio/Gatekeeper/UserCollection.php b/src/Psecio/Gatekeeper/UserCollection.php new file mode 100644 index 0000000..74c2488 --- /dev/null +++ b/src/Psecio/Gatekeeper/UserCollection.php @@ -0,0 +1,26 @@ +<?php + +namespace Psecio\Gatekeeper; + +class UserCollection extends \Psecio\Gatekeeper\Collection\Mysql +{ + /** + * Find the users belonging to the given group + * + * @param integer $group Group ID + */ + public function findByGroupId($groupId) + { + $data = array('groupId' => $groupId); + $sql = 'select u.* from users u, user_group ug' + .' where ug.group_id = :groupId' + .' and ug.user_id = u.id'; + + $results = $this->fetch($sql, $data); + + foreach ($results as $result) { + $user = new UserModel($this->getDb(), $result); + $this->add($user); + } + } +}
\ No newline at end of file |