3 * Table Definition for Projects
5 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
7 class Pman_Core_DataObjects_Core_project extends DB_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'core_project'; // table name
13 public $id; // int(11) not_null primary_key auto_increment
14 public $name; // string(254) not_null
15 public $remarks; // blob(65535) not_null blob
16 public $owner_id; // int(11)
17 public $code; // string(32) not_null multiple_key
18 public $active; // int(11)
19 public $type; // string(1) not_null
20 public $client_id; // int(11) not_null
21 public $team_id; // int(11) not_null
22 public $file_location; // string(254) not_null
23 public $open_date; // date(10) binary
24 public $open_by; // int(11) not_null
25 public $close_date; // date(10) binary
26 public $countries; // string(128) not_null
27 public $languages; // string(128) not_null
28 public $agency_id; // int(11) not_null
29 public $updated_dt; // datetime(19) not_null binary
32 /* the code above is auto generated do not remove the tag below */
34 function getProjectManagers()
36 $c = DB_DataObject::factory('core_company');
38 if (!$c->find(true)) {
44 $pd = DB_DataObject::factory('ProjectDirectory');
45 $pd->project_id = $this->id;
46 $pd->company_id = $c->id;
52 $pd->selectAdd('distinct (person_id)');
55 while ($pd->fetch()) {
56 $pmids[] = $pd->person_id;
60 $p = DB_DataObject::factory('core_person');
61 $p->whereAdd('id IN ('. implode(',', $pmids) .')');
70 function toEventString() {
72 return ($c && $c->id ? $c->toEventString() : '??'). ':' . $this->name;
76 * apply filter arguemnts
77 * @param $query - see below
78 * @param $authUser - authenticated user
82 * project_search = text string.
83 * project_indaterange - a/c/o
84 * project_filter = ALL || P,N,U ....
86 * // to get a users valid project list - just use array('query' => array('project_filter'=> 'ALL'));
90 function applyFilters($q, $au, $roo)
93 $tn = $this->tableName();
94 if (!empty($q['query']['project_search'])) {
95 $s = $this->escape($q['query']['project_search']);
96 $this->whereAdd(" ({$tn}.code LIKE '$s%')
98 ({$tn}.name LIKE '%$s%')
100 join_client_id_id.name LIKE '%$s%'
103 // types of project to list ... - default is only the open ones...
104 if (!empty($q['query']['project_indaterange'])) {
105 switch($q['query']['project_indaterange']) {
109 $this->whereAdd("{$tn}.close_date >= NOW()");
112 $this->whereAdd("{$tn}.close_date < NOW()");
117 if (empty($q['_is_update_request']) &&
119 (empty($q['query']['project_filter']) || $q['query']['project_filter'] != 'ALL')) {
122 $pf = empty($q['query']['project_filter']) ? 'P,N,U' : $q['query']['project_filter'];
126 $this->whereAddIn("{$tn}.type", explode(',', $pf), 'string');
128 // user projects!!!! - make sure they can only see project they are suppsed to..
129 // only applies to document stuff..
131 //&& $au->hasPerm('Documents.Documents','S') << this is dependant on the doc modules
133 if (!$au->hasPerm('Core.Projects_All','S') ) {
137 $pr = DB_DataObject::factory($tn);
138 $pr->whereAdd("{$tn}.type IN ('N','X')");
139 $prjs = $pr->fetchAll('id');
141 //DB_DataObject::debugLevel(1);
142 $pd = DB_DataObject::factory('ProjectDirectory');
143 $pd->joinAdd(DB_DataObject::factory($tn), 'LEFT');
144 $pd->whereAdd("{$tn}.type NOT IN ('N','X')");
145 $pd->person_id = $au->id;
147 $prjs = array_merge($prjs, $pd->fetchAll('project_id'));
150 ({$tn}.id IN (".implode(',', $prjs)."))
153 $this->whereAdd("1=0"); // can see nothing!!!
157 if (!empty($q['query']['distinct_client_id'])) {
158 // DB_DataObjecT::debuglevel(1);
160 $this->selectAdd('distinct(client_id)');
161 $this->selectAs(DB_DataObject::factory('core_company'), 'client_id_%s','join_client_id_id');
162 $this->groupBy('client_id');
166 // this is clipping related.. -- we should have an API for addons like this.. (and docs)
181 if (empty($this->code)) {
182 $this->code = 'C' + $this->client_id + '-P' + $this->id;
183 $dt = new DateTime();
184 $this->updated_dt = $dt->format('Y-m-d H:i:s');
189 function onUpdate($old)
192 if (empty($this->code)) {
193 $this->code = 'C' + $this->client_id + '-P' + $this->id;
194 $dt = new DateTime();
195 $this->updated_dt = $dt->format('Y-m-d H:i:s');
199 if ($old->code == $this->code) {
203 $opts = HTML_FlexyFramework::get()->Pman;
205 $olddir = $opts['storedir'] . '/' . $old->code;
206 $newdir = $opts['storedir'] . '/' . $this->code;
207 if ( file_exists($olddir)) {
208 rename($olddir, $newdir);
216 if (!$this->prune) { // non-expiring..
220 $d = DB_DataObject::factory('Document');
221 $d->whereAdd("date_rec < NOW - INTERVAL {$this->expires} DAYS");
223 while ($d->fetch()) {
235 * our camp interface uses the format Cxxx-Pyyyyyy to refer to the project.
237 function getByCodeRef($str)
239 $bits = explode('-', $str);
240 if ((count($bits) != 2) || $bits[0][0] != 'C' || $bits[1][0] != 'P' ) {
243 $comp = substr($bits[0], 1);
244 $id = (int) substr($bits[1], 1);
245 return $id && $this->get($id);
253 function setFromRoo($q)
256 if (isset($q['open_date'])) {
257 $this->open_date = date('Y-m-d', strtotime(
258 implode('-', array_reverse(explode('/', $q['open_date'])))
266 * fetch a list of user projects.
267 * if you need to filter open/closed.. then add whereAdds before calling
269 function userProjects($au, $data='id') // COMPANY BASED!!!!
272 $id = (int) $au->company_id;
275 (client_id= $id) OR (agency_id= $id)
278 return empty($data) ? $this->fetchAll() :$this->fetchAll($data);
287 if (!$this->client_id) {
290 $c = DB_DataObject::factory('core_company');
291 $c->get($this->client_id);
299 $c = DB_DataObject::factory('core_group');
300 $c->get($this->team_id);
306 // DEPRICATED - use userProjects
308 function getUserProjects($au, $data='id') // COMPANY BASED!!!!
310 return $this->userProjects($au, $data);
317 * check who is trying to access this. false == access denied..
319 function checkPerm($lvl, $au)
321 return $au->hasPerm("Core.Projects_Member_Of",$lvl) || $au->hasPerm("Core.Projects_All",$lvl);