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 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());
107 function memberCount()
109 $gm = DB_Dataobject::factory($this->membersTable());
110 $gm->group_id = $this->id;
116 $gm = DB_Dataobject::factory($this->membersTable());
117 $gm->group_id = $this->id;
118 return $gm->fetchAll('user_id');
123 function addMember($person)
125 $gm = DB_Dataobject::factory($this->membersTable());
126 $gm->group_id = $this->id;
127 $gm->user_id = $person->id;
134 * grab a list of members - default is the array of person objects..
135 * @param $what = set to 'email' to get a list of email addresses.
140 function members($what = false)
142 $ids = $this->memberIds();
146 //$p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
147 // groups databse is hard coded to person.. so this should not be used for other tables.????
148 $p = DB_Dataobject::factory( 'Person' );
150 $p->whereAdd('id IN ('. implode(',', $ids) .')');
152 return $p->fetchAll($what);
158 function lookup($k,$v = false) {
168 function lookUpMembers($name, $what=false)
170 if (!$this->get('name', $name)) {
173 return $this->members($what);
177 function lookupMembersByGroupId($id, $what=false)
179 if (!$this->get($id)) {
183 return $this->members($what);
186 function postListFilter($ar, $au, $req)
188 if(!empty($req['_direct_return'])){
192 $ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
193 $ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
194 return array_merge($ret, $ar);
198 function initGroups()
201 $g = DB_DataObject::factory($this->tableName());
203 $g->name = 'Administrators';
208 $gr = DB_DataObject::factory($this->rightsTable());
212 function initDatabase($roo, $data)
216 foreach($data as $gi) {
217 $g = DB_DataObject::factory($this->tableName());
224 if(count($g->members()) || empty($gi['members'])){
228 foreach ($gi['members'] as $m){