init
[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     function listGroupMembership($person, $arrayof = 'group_id') 
23     {
24         $this->inAdmin = false;
25         $t = clone($this);
26         //DB_DataObject::debugLevel(1);
27          
28         
29         $t->joinAdd(DB_DataObject::factory('Groups'), 'LEFT');
30         //$person->id = (int)$person->id;
31         $t->whereAdd("
32             user_id = {$person->id}
33         ");
34         $t->selectAdd();
35         $t->selectAdd('distinct(group_id), Groups.name as name');
36         
37         $t->find();
38         
39         $ret = $arrayof == 'group_id' ? array(0) : array(); // default member of 'All groups'!!
40         
41         while ($t->fetch()) {
42             $ret[] = $t->$arrayof;
43             if ($t->name == 'Administrators') { /// mmh... bit risky?
44                 $this->inAdmin = true;
45             }
46         }
47         return $ret;
48         
49     }
50     function checkPerm($lvl, $au) 
51     {
52         return false;
53     } 
54     function fetchAll($k= false) {
55         if ($k !== false) {
56             $this->selectAdd();
57             $this->selectAdd($k);
58         }
59         
60         $this->find();
61         $ret = array();
62         while ($this->fetch()) {
63             $ret[] = $k === false ? clone($this) : $this->$k;
64         }
65         return $ret;
66          
67     }
68 }