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;
96 $ids = $this->memberIds();
100 $p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
101 $p->whereAdd('id IN ('. implode(',', $ids) .')');
103 return $p->fetchAll();
108 function postListFilter($ar, $au, $req)
111 $ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
112 $ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
113 return array_merge($ret, $ar);
114 //$ret[] = array( 'id' => 999999, 'name' => 'ADMINISTRATORS');
118 function initGroups()
121 $g = DB_DataObject::factory('Groups');
123 $g->name = 'Administrators';
128 $gr = DB_DataObject::factory('group_rights');