summaryrefslogtreecommitdiffstats
path: root/src/Psecio/Gatekeeper/UserCollection.php
blob: 805ad527a727bbfb2f7c737797e8cd6ead65702a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

namespace Psecio\Gatekeeper;

class UserCollection extends \Psecio\Gatekeeper\Collection\Mysql
{
    /**
     * Find the users belonging to the given group
     *
     * @param integer $groupId Group ID
     */
    public function findByGroupId($groupId)
    {
        $prefix = $this->getPrefix();
        $data = array('groupId' => $groupId);
        $sql = 'select u.* from '.$prefix.'users u, '.$prefix.'user_group ug'
            .' where ug.group_id = :groupId'
            .' and ug.user_id = u.id';

        $results = $this->getDb()->fetch($sql, $data);

        foreach ($results as $result) {
            $user = new UserModel($this->getDb(), $result);
            $this->add($user);
        }
    }
}