3 * Table Definition for Groups
5 require_once 'DB/DataObject.php';
7 class Pman_Core_DataObjects_Groups extends DB_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'Groups'; // table name
13 public $id; // int(11) not_null primary_key auto_increment
14 public $name; // string(64) not_null
15 public $type; // int(11)
16 public $leader; // int(11) not_null
19 /* the code above is auto generated do not remove the tag below */
24 function toEventString() {
28 function beforeDelete()
30 $x = DB_DataObject::factory('Groups');
31 $x->query("DELETE FROM group_rights WHERE group_id = {$this->id}");
32 $x->query("DELETE FROM group_members WHERE group_id = {$this->id}");
35 * check who is trying to access this. false == access denied..
37 function checkPerm($lvl, $au)
39 return $au->hasPerm("Core.Groups", $lvl);
41 function onUpdate($old, $req, $roo)
43 $this->ensureLeaderMembership($roo);
45 function onInsert($req, $roo)
47 $this->ensureLeaderMembership($roo);
49 function ensureLeaderMembership($roo)
52 // groups - make sure the leader is a member...
53 if (!$this->type || !$this->leader)
58 $pi = DB_DataObject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
59 $pi->get($this->leader);
61 $p = DB_DataObject::factory('group_members');
62 $p->group_id = $this->id;
63 $p->user_id = $this->leader;
64 //$p->type = 1; //???????
68 $roo->addEvent("ADD", $p, $this->toEventString(). " Added " . $pi->toEventString());
75 $gm = DB_Dataobject::factory('group_members');
76 $gm->group_id = $this->id;
77 return $gm->fetchAll('user_id');
82 function addMember($person)
84 $gm = DB_Dataobject::factory('group_members');
85 $gm->group_id = $this->id;
86 $gm->user_id = $person->id;
93 * grab a list of members - default is the array of person objects..
94 * @param $what = set to 'email' to get a list of email addresses.
99 function members($what = false)
101 $ids = $this->memberIds();
105 //$p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
106 // groups databse is hard coded to person.. so this should not be used for other tables.????
107 $p = DB_Dataobject::factory( 'Person' );
109 $p->whereAdd('id IN ('. implode(',', $ids) .')');
111 return $p->fetchAll($what);
114 function lookup($k,$v = false) {
124 function postListFilter($ar, $au, $req)
127 $ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
128 $ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
129 return array_merge($ret, $ar);
130 //$ret[] = array( 'id' => 999999, 'name' => 'ADMINISTRATORS');
134 function initGroups()
137 $g = DB_DataObject::factory('Groups');
139 $g->name = 'Administrators';
144 $gr = DB_DataObject::factory('group_rights');