3 * Table Definition for Groups
7 * 0 = permission group..
13 require_once 'DB/DataObject.php';
15 class Pman_Core_DataObjects_Groups extends DB_DataObject
18 /* the code below is auto generated do not remove the above tag */
20 public $__table = 'Groups'; // table name
21 public $id; // int(11) not_null primary_key auto_increment
22 public $name; // string(64) not_null
23 public $type; // int(11)
24 public $leader; // int(11) not_null
27 /* the code above is auto generated do not remove the tag below */
32 function toEventString() {
36 function beforeDelete()
38 $x = DB_DataObject::factory('Groups');
39 $x->query("DELETE FROM group_rights WHERE group_id = {$this->id}");
40 $x->query("DELETE FROM group_members WHERE group_id = {$this->id}");
43 * check who is trying to access this. false == access denied..
45 function checkPerm($lvl, $au)
47 return $au->hasPerm("Core.Groups", $lvl);
49 function onUpdate($old, $req, $roo)
51 $this->ensureLeaderMembership($roo);
53 function onInsert($req, $roo)
55 $this->ensureLeaderMembership($roo);
57 function ensureLeaderMembership($roo)
60 // groups - make sure the leader is a member...
61 if (!$this->type || !$this->leader)
66 $pi = DB_DataObject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
67 $pi->get($this->leader);
69 $p = DB_DataObject::factory('group_members');
70 $p->group_id = $this->id;
71 $p->user_id = $this->leader;
72 //$p->type = 1; //???????
76 $roo->addEvent("ADD", $p, $this->toEventString(). " Added " . $pi->toEventString());
83 $gm = DB_Dataobject::factory('group_members');
84 $gm->group_id = $this->id;
85 return $gm->fetchAll('user_id');
90 function addMember($person)
92 $gm = DB_Dataobject::factory('group_members');
93 $gm->group_id = $this->id;
94 $gm->user_id = $person->id;
101 * grab a list of members - default is the array of person objects..
102 * @param $what = set to 'email' to get a list of email addresses.
107 function members($what = false)
109 $ids = $this->memberIds();
113 //$p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
114 // groups databse is hard coded to person.. so this should not be used for other tables.????
115 $p = DB_Dataobject::factory( 'Person' );
117 $p->whereAdd('id IN ('. implode(',', $ids) .')');
119 return $p->fetchAll($what);
122 function lookup($k,$v = false) {
132 function lookUpMembers($name, $what=false)
134 if (!$this->get('name', $name)) {
137 return $this->members($what);
141 function lookupMembersByGroupId($id, $what=false)
143 if (!$this->get($id)) {
147 return $this->members($what);
150 function postListFilter($ar, $au, $req)
152 if(!empty($req['_direct_return'])){
156 $ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
157 $ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
158 return array_merge($ret, $ar);
162 function initGroups()
165 $g = DB_DataObject::factory('Groups');
167 $g->name = 'Administrators';
172 $gr = DB_DataObject::factory('group_rights');
176 function initDatabase($roo, $data)
180 foreach($data as $gi) {
181 $g = DB_DataObject::factory('Groups');
188 if(count($g->members()) || empty($gi['members'])){
192 foreach ($gi['members'] as $m){