DataObjects/Group_Members.php
[Pman.Core] / DataObjects / Group_Members.php
1 <?php
2 /**
3  * Table Definition for Group_Members
4  */
5 require_once 'DB/DataObject.php';
6
7 class Pman_Core_DataObjects_Group_Members extends DB_DataObject 
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'Group_Members';                   // table name
13     public $group_id;                        // int(11)  
14     public $id;                              // int(11)  not_null primary_key auto_increment
15     public $user_id;                         // int(11)  not_null
16
17   
18     /* the code above is auto generated do not remove the tag below */
19     ###END_AUTOCODE
20     
21     var $inAdmin = false;
22     
23     /**
24      * Get a list of memberships for a person
25      * @param Pman_Core_DataObjects_Person $person who
26      * @param String column to fetch.. eg. group_id or 'name'
27      *
28      */
29     
30     function listGroupMembership($person, $arrayof = 'group_id') 
31     {
32         $this->inAdmin = false;
33         $t = clone($this);
34         //DB_DataObject::debugLevel(1);
35          
36         
37         $t->joinAdd(DB_DataObject::factory('Groups'), 'LEFT');
38         //$person->id = (int)$person->id;
39         $t->whereAdd("
40             user_id = {$person->id}
41         ");
42         $t->selectAdd();
43         $t->selectAdd('distinct(group_id), Groups.name as name');
44         
45         $t->find();
46         
47         $ret = $arrayof == 'group_id' ? array(0) : array();
48         // default member of 'All groups'!!
49         
50         while ($t->fetch()) {
51             $ret[] = $t->$arrayof;
52             if ($t->name == 'Administrators') { /// mmh... bit risky?
53                 $this->inAdmin = true;
54             }
55         }
56         return $ret;
57         
58     }
59     function checkPerm($lvl, $au) 
60     {
61         return false;
62     } 
63    
64 }