3 * Table Definition for ProjectDirectory
5 * Note - projectdirectory is linked to this - due to an issue with postgres - we should keep to lowercase names only for tables..
8 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
10 class Pman_Core_DataObjects_ProjectDirectory extends DB_DataObject
13 /* the code below is auto generated do not remove the above tag */
15 public $__table = 'ProjectDirectory'; // table name
16 public $id; // int(11) not_null primary_key auto_increment
17 public $project_id; // int(11) not_null
18 public $person_id; // int(11) not_null
19 public $ispm; // int(11) not_null
20 public $role; // string(16) not_null
23 /* the code above is auto generated do not remove the tag below */
29 $p = DB_DataObject::factory('core_person');
30 $p->get($this->person_id);
34 function toEventString() {
36 // this is weird... company is in the person.. - effieciency??
38 $c = DB_DataObject::factory('core_company');
39 $c->get($this->company_id);
40 $pr = DB_DataObject::factory('core_project');
41 $pr->get($this->project_id);
43 return $pr->code . ' '. $p->name . '('. $c->name .')';
46 function personMemberOf($pe, $pr) {
47 $this->person_id = $pe->id;
48 $this->project_id = $pr->id;
50 if ($this->find(true)) {
56 function ensureProjectMember($pr, $pe) // used where?
58 if ($this->personMemberOf($pe, $pr)) {
61 $this->company_id = $pe->company_id;
62 $this->office_id = $pe->office_id;
63 $this->role = $pe->role;
68 * project id's for a user.
69 * @param DB_DataObject_Core_Person|array - who, or list of people.
70 * @return array id's of the project they are a member of..
72 function projects($au)
75 $p = DB_DataObject::Factory('core_project');
76 $p->get('code', '*PUBLIC');
83 $c->whereAddIn('person_id', $au, 'int');
85 $c->person_id = $au->id;
88 // people may have multiple roles for a project..
89 $c->selectAdd("distinct({$this->tableName()}.project_id) as project_id");
90 return $c->fetchAll('project_id');
93 * project id's for a user.
94 * @param DB_DataObject_Core_Person - who
95 * @return array id's of the project they are a member of..
100 //echo '<PRE>';print_R($this);exit;
103 $c->whereAddIn("{$this->tableName()}.project_id", $pr, 'int');
105 $c->project_id = $pr->id;
108 $c->selectAdd("{$this->tableName()}.person_id as person_id");
109 return $c->fetchAll('person_id');
115 function checkPerm($lvl, $au)
117 return $au->hasPerm('Documents.Project_Directory', $lvl);
119 function setFromRoo($ar,$roo)
124 ($this->project_id == $roo->old->project_id) &&
125 ($this->person_id == $roo->old->person_id) &&
126 ($this->company_id == $roo->old->company_id) )
131 $xx = DB_Dataobject::factory('ProjectDirectory');
133 'project_id' => $this->project_id,
134 'person_id' => $this->person_id,
135 'company_id' => $this->company_id,
139 return "Duplicate entry found Project Directory entry";
144 function applyFilters($q, $au)
146 //DB_DAtaObject::debugLevel(1); var_dump($q);
148 // otherwise only the project they are involved with..
150 // can see - their projects + their personal mail...
151 if (!empty($q['project_id_ar'])) {
152 // can filter projects!
153 $this->whereAddIn('ProjectDirectory.project_id', explode(',',$q['project_id_ar']), 'int');
157 if (!empty($q['query']['company_ids'])) {
158 $this->whereAddIn('ProjectDirectory.company_id', explode(',',$q['query']['company_ids']), 'int');
161 // whos should they see as far as personal contacts.!?!?
162 // their projects... and their mail or.. just their mail if no projects..
165 /// ------------ PERMISSION FILTERERIN!!!!!!
167 if ($au->hasPerm('Core.Projects_All', 'S')) {
168 return; // can see it all!!!
172 $pr = DB_DataObject::factory('core_project');
173 $pr->whereAdd("Projects.type IN ('N','X')");
174 $prjs = $pr->fetchAll('id');
177 $pd = DB_DataObject::factory('ProjectDirectory');
178 $pd->joinAdd(DB_DataObject::factory('core_project'), 'LEFT');
179 $pd->whereAdd("Projects.type NOT IN ('N','X')");
180 $pd->person_id = $au->id;
182 $prjs = array_merge($prjs, $pd->fetchAll('project_id'));
185 (ProjectDirectory.project_id IN (".implode(',', $prjs)."))
190 $this->whereAdd("1=0"); // can see nothing!!!