summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Cornutt <chris.cornutt@hp.com>2014-12-12 15:10:20 -0600
committerChris Cornutt <chris.cornutt@hp.com>2014-12-12 15:10:20 -0600
commit0b5d8e41f2019359bf2db38d73e6891dbddfcbe6 (patch)
tree6776eb65cff49d302482e50fa5d60fc86c4781f8 /src
parente1936c4a90f2db43ab61d02461ee89db1fc8c61e (diff)
downloadgatekeeper-0b5d8e41f2019359bf2db38d73e6891dbddfcbe6.zip
gatekeeper-0b5d8e41f2019359bf2db38d73e6891dbddfcbe6.tar.gz
gatekeeper-0b5d8e41f2019359bf2db38d73e6891dbddfcbe6.tar.bz2
adding the User collection and linking it to the Group model
Diffstat (limited to 'src')
-rw-r--r--src/Psecio/Gatekeeper/GroupModel.php9
-rw-r--r--src/Psecio/Gatekeeper/UserCollection.php26
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