3 * Table Definition for Groups
7 * 0 = permission group..
12 * NOTE - used to be called Groups ....
15 require_once 'DB/DataObject.php';
17 class Pman_Core_DataObjects_Core_group extends DB_DataObject
20 /* the code below is auto generated do not remove the above tag */
22 public $__table = 'core_group'; // table name
23 public $id; // int(11) not_null primary_key auto_increment
24 public $name; // string(64) not_null
25 public $type; // int(11)
26 public $leader; // int(11) not_null
27 public $is_system; // used by timesheets?
29 /* the code above is auto generated do not remove the tag below */
33 function personTable()
35 $ff = HTML_FlexyFramework::get();
36 return empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
41 function applyFilters($q, $au, $roo)
43 if (!empty($q['query']['name_starts'])) {
44 $v = $this->escape($q['query']['name_starts']);
45 $this->whereAdd("{$this->tableName()}.name like '{$v}%'");
49 function toEventString() {
53 function beforeDelete()
55 $x = DB_DataObject::factory('core_group_right');
56 $x->query("DELETE FROM {$x->tableName()} WHERE group_id = {$this->id}");
57 $x = DB_DataObject::factory('core_group_member');
58 $x->query("DELETE FROM {$x->tableName()} WHERE group_id = {$this->id}");
61 * check who is trying to access this. false == access denied..
63 function checkPerm($lvl, $au)
65 return $au->hasPerm("Core.Groups", $lvl);
67 function onUpdate($old, $req, $roo)
69 $this->ensureLeaderMembership($roo);
71 function onInsert($req, $roo)
73 $this->ensureLeaderMembership($roo);
75 function ensureLeaderMembership($roo)
78 // groups - make sure the leader is a member...
79 if (!$this->type || !$this->leader)
84 $pi = DB_DataObject::factory('Person');
85 $pi->get($this->leader);
87 $p = DB_DataObject::factory('core_group_member');
88 $p->group_id = $this->id;
89 $p->user_id = $this->leader;
90 //$p->type = 1; //???????
94 $roo->addEvent("ADD", $p, $this->toEventString(). " Added " . $pi->toEventString());
100 function memberCount()
102 $gm = DB_Dataobject::factory('core_group_member');
103 $gm->group_id = $this->id;
109 $gm = DB_Dataobject::factory('core_group_member');
110 $gm->group_id = $this->id;
111 return $gm->fetchAll('user_id');
116 function addMember($person)
118 $gm = DB_Dataobject::factory('core_group_member');
119 $gm->group_id = $this->id;
120 $gm->user_id = $person->id;
127 * grab a list of members - default is the array of person objects..
128 * @param $what = set to 'email' to get a list of email addresses.
133 function members($what = false)
135 $ids = $this->memberIds();
139 //$p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
140 // groups databse is hard coded to person.. so this should not be used for other tables.????
141 $p = DB_Dataobject::factory( 'Person' );
143 $p->whereAdd('id IN ('. implode(',', $ids) .')');
145 return $p->fetchAll($what);
151 function lookup($k,$v = false) {
161 function lookUpMembers($name, $what=false)
163 if (!$this->get('name', $name)) {
166 return $this->members($what);
170 function lookupMembersByGroupId($id, $what=false)
172 if (!$this->get($id)) {
176 return $this->members($what);
179 function postListFilter($ar, $au, $req)
181 if(!empty($req['_direct_return'])){
185 $ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
186 $ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
187 return array_merge($ret, $ar);
191 function initGroups()
194 $g = DB_DataObject::factory($this->tableName());
196 $g->name = 'Administrators';
201 $gr = DB_DataObject::factory('core_group_right');
205 function initDatabase($roo, $data)
209 foreach($data as $gi) {
210 $g = DB_DataObject::factory($this->tableName());
217 if(count($g->members()) || empty($gi['members'])){
221 foreach ($gi['members'] as $m){