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_groups extends DB_DataObject
20 /* the code below is auto generated do not remove the above tag */
22 public $__table = 'core_groups'; // 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 memberTable()
35 return 'core_group_members';
37 function rightsTable()
39 return 'core_group_rights';
41 function personTable()
43 $ff = HTML_FlexyFramework::get();
44 return empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
49 function applyFilters($q, $au, $roo)
51 if (!empty($q['query']['name_starts'])) {
52 $v = $this->escape($q['query']['name_starts']);
53 $this->whereAdd("{$this->tableName()}.name like '{$v}%'");
57 function toEventString() {
61 function beforeDelete()
63 $x = DB_DataObject::factory($this->tableName());
64 $x->query("DELETE FROM {$this->rightsTable()} WHERE group_id = {$this->id}");
65 $x->query("DELETE FROM {$this->membersTable()} WHERE group_id = {$this->id}");
68 * check who is trying to access this. false == access denied..
70 function checkPerm($lvl, $au)
72 return $au->hasPerm("Core.Groups", $lvl);
74 function onUpdate($old, $req, $roo)
76 $this->ensureLeaderMembership($roo);
78 function onInsert($req, $roo)
80 $this->ensureLeaderMembership($roo);
82 function ensureLeaderMembership($roo)
85 // groups - make sure the leader is a member...
86 if (!$this->type || !$this->leader)
91 $pi = DB_DataObject::factory($this->personTable());
92 $pi->get($this->leader);
94 $p = DB_DataObject::factory($this->membersTable());
95 $p->group_id = $this->id;
96 $p->user_id = $this->leader;
97 //$p->type = 1; //???????
101 $roo->addEvent("ADD", $p, $this->toEventString(). " Added " . $pi->toEventString());
108 $gm = DB_Dataobject::factory($this->membersTable());
109 $gm->group_id = $this->id;
110 return $gm->fetchAll('user_id');
115 function addMember($person)
117 $gm = DB_Dataobject::factory('group_members');
118 $gm->group_id = $this->id;
119 $gm->user_id = $person->id;
126 * grab a list of members - default is the array of person objects..
127 * @param $what = set to 'email' to get a list of email addresses.
132 function members($what = false)
134 $ids = $this->memberIds();
138 //$p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
139 // groups databse is hard coded to person.. so this should not be used for other tables.????
140 $p = DB_Dataobject::factory( 'Person' );
142 $p->whereAdd('id IN ('. implode(',', $ids) .')');
144 return $p->fetchAll($what);
150 function lookup($k,$v = false) {
160 function lookUpMembers($name, $what=false)
162 if (!$this->get('name', $name)) {
165 return $this->members($what);
169 function lookupMembersByGroupId($id, $what=false)
171 if (!$this->get($id)) {
175 return $this->members($what);
178 function postListFilter($ar, $au, $req)
180 if(!empty($req['_direct_return'])){
184 $ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
185 $ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
186 return array_merge($ret, $ar);
190 function initGroups()
193 $g = DB_DataObject::factory($this->tableName());
195 $g->name = 'Administrators';
200 $gr = DB_DataObject::factory('group_rights');
204 function initDatabase($roo, $data)
208 foreach($data as $gi) {
209 $g = DB_DataObject::factory($this->tableName());
216 if(count($g->members()) || empty($gi['members'])){
220 foreach ($gi['members'] as $m){