fix #8131 - chinese translations
[Pman.Core] / DataObjects / Core_group_member.php
1 <?php
2 /**
3  * Table Definition for Group_Members
4  */
5 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
6
7 class Pman_Core_DataObjects_Core_group_member extends DB_DataObject 
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'core_group_member';                   // 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    
22     
23     var $inAdmin = false;
24     
25     
26     function change($person, $group, $state)
27     {
28         $gm = DB_DataObject::factory($this->tableName());
29         $gm->group_id = $group->id;
30         $gm->user_id = $person->id;
31         $gm->find(true);
32         if ($state) {
33             if (!$gm->id) {
34                 $gm->insert();
35             }
36             return;
37         }
38         // remove..
39         if ($gm->id) {
40             $gm->delete();
41         }
42         
43     }
44     
45     function group()
46     {
47         $grp = DB_DataObject::factory('core_group');
48         $grp->get($this->group_id);
49         return $grp;
50         
51     }
52     
53     /**
54      * Get a list of memberships for a person
55      * @param Pman_Core_DataObjects_Person $person who
56      * @param String column to fetch.. eg. group_id or 'name'
57      *
58      */
59     
60     
61     function listGroupMembership($person, $arrayof = 'group_id') 
62     {
63         $this->inAdmin = false;
64         $t = clone($this);
65         //DB_DataObject::debugLevel(1);
66          
67         $grp = DB_DataObject::factory('core_group');
68         $t->joinAdd($grp , 'LEFT');
69         //$person->id = (int)$person->id;
70         $t->whereAdd("
71             user_id = {$person->id}
72         ");
73         $t->selectAdd();
74         $t->selectAdd("distinct(group_id), {$grp->tableName()}.name as name");
75         $t->whereAdd('group_id IS NOT NULL');
76         
77         $t->find();
78         
79         $ret = array() ;
80        // $ret = $arrayof == 'group_id' ? array(0) : array();
81         // default member of 'All groups'!!
82         
83         while ($t->fetch()) {
84             $ret[] = $t->$arrayof;
85             if ($t->name == 'Administrators') { /// mmh... bit risky?
86                 $this->inAdmin = true;
87             }
88         }
89         if ($arrayof == 'group_id' && !count($ret)) {
90             $ret = array(0); /// default if they are not a member of any group.
91         }
92         //var_dump($ret);
93         return $ret;
94         
95     }
96     
97     function checkPerm($lvl, $au) 
98     {
99         // not sure if this is correct - but we need it on texon
100         return  $au->hasPerm("Core.Staff", $lvl);
101     
102     }
103     
104 }