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
30 public $deleted_by; // INT
31 public $deleted_dt; // datetime(19) not_null binary
34 /* the code above is auto generated do not remove the tag below */
36 function getProjectManagers()
38 $c = DB_DataObject::factory('core_company');
40 if (!$c->find(true)) {
46 $pd = DB_DataObject::factory('ProjectDirectory');
47 $pd->project_id = $this->id;
48 $pd->company_id = $c->id;
54 $pd->selectAdd('distinct (person_id)');
57 while ($pd->fetch()) {
58 $pmids[] = $pd->person_id;
62 $p = DB_DataObject::factory('core_person');
63 $p->whereAdd('id IN ('. implode(',', $pmids) .')');
72 function toEventString() {
74 return ($c && $c->id ? $c->toEventString() : '??'). ':' . $this->name;
78 * apply filter arguemnts
79 * @param $query - see below
80 * @param $authUser - authenticated user
84 * project_search = text string.
85 * project_indaterange - a/c/o
86 * project_filter = ALL || P,N,U ....
88 * // to get a users valid project list - just use array('query' => array('project_filter'=> 'ALL'));
92 function applyFilters($q, $au, $roo)
94 if (empty($q['_show_deleted']) && empty($q['_is_update_request'])) {
95 $this->whereAdd('core_project.deleted_by = 0');
98 $tn = $this->tableName();
99 if (!empty($q['query']['project_search'])) {
100 $s = $this->escape($q['query']['project_search']);
101 $this->whereAdd(" ({$tn}.code LIKE '$s%')
103 ({$tn}.name LIKE '%$s%')
105 join_client_id_id.name LIKE '%$s%'
108 // types of project to list ... - default is only the open ones...
109 if (!empty($q['query']['project_indaterange'])) {
110 switch($q['query']['project_indaterange']) {
114 $this->whereAdd("{$tn}.close_date is NULL OR {$tn}.close_date >= NOW()");
117 $this->whereAdd("{$tn}.close_date < NOW()");
122 if (empty($q['_is_update_request']) &&
124 (empty($q['query']['project_filter']) || $q['query']['project_filter'] != 'ALL')) {
127 $pf = empty($q['query']['project_filter']) ? 'P,N,U' : $q['query']['project_filter'];
131 $this->whereAddIn("{$tn}.type", explode(',', $pf), 'string');
133 // user projects!!!! - make sure they can only see project they are suppsed to..
134 // only applies to document stuff..
136 //&& $au->hasPerm('Documents.Documents','S') << this is dependant on the doc modules
138 if (php_sapi_name() != 'cli' && !$au->hasPerm('Core.Projects_All','S') ) {
142 $pr = DB_DataObject::factory($tn);
143 $pr->whereAdd("{$tn}.type IN ('N','X')");
144 $prjs = $pr->fetchAll('id');
146 //DB_DataObject::debugLevel(1);
147 $pd = DB_DataObject::factory('ProjectDirectory');
148 $pd->joinAdd(DB_DataObject::factory($tn), 'LEFT');
149 $pd->whereAdd("{$tn}.type NOT IN ('N','X')");
150 $pd->person_id = $au->id;
152 $prjs = array_merge($prjs, $pd->fetchAll('project_id'));
155 ({$tn}.id IN (".implode(',', $prjs)."))
158 $this->whereAdd("1=0"); // can see nothing!!!
162 if (!empty($q['query']['distinct_client_id'])) {
163 // DB_DataObjecT::debuglevel(1);
165 $this->selectAdd('distinct(client_id)');
166 $this->selectAs(DB_DataObject::factory('core_company'), 'client_id_%s','join_client_id_id');
167 $this->groupBy('client_id');
171 // this is clipping related.. -- we should have an API for addons like this.. (and docs)
183 function beforeUpdate($old, $q, $roo)
185 if (!empty($q['_flag_deleted'])) {
186 //DB_DataObject::DebugLevel(1);
187 $this->deleted_by = $roo->getAuthUser()->id;
188 $this->deleted_dt = date("Y-m-d H:i:s");
190 if (!empty($q['_flag_undeleted'])) {
191 $this->deleted_by = 0;
192 $this->deleted_dt = '1000-01-01 00:00:00';
197 function onInsert($request,$roo,$event)
200 if (empty($this->code)) {
201 $this->code = 'C' + $this->client_id + '-P' + $this->id;
202 $dt = new DateTime();
203 $this->updated_dt = $dt->format('Y-m-d H:i:s');
208 function onUpdate($old, $request, $roo,$event)
211 if (empty($this->code)) {
212 $this->code = 'C' + $this->client_id + '-P' + $this->id;
213 $dt = new DateTime();
214 $this->updated_dt = $dt->format('Y-m-d H:i:s');
218 if ($old->code == $this->code) {
222 $opts = HTML_FlexyFramework::get()->Pman;
224 $olddir = $opts['storedir'] . '/' . $old->code;
225 $newdir = $opts['storedir'] . '/' . $this->code;
226 if ( file_exists($olddir)) {
227 rename($olddir, $newdir);
235 if (!$this->prune) { // non-expiring..
239 $d = DB_DataObject::factory('Document');
240 $d->whereAdd("date_rec < NOW - INTERVAL {$this->expires} DAYS");
242 while ($d->fetch()) {
254 * our camp interface uses the format Cxxx-Pyyyyyy to refer to the project.
256 function getByCodeRef($str)
258 $bits = explode('-', $str);
259 if ((count($bits) != 2) || $bits[0][0] != 'C' || $bits[1][0] != 'P' ) {
262 $comp = substr($bits[0], 1);
263 $id = (int) substr($bits[1], 1);
264 return $id && $this->get($id);
272 function setFromRoo($q)
275 if (isset($q['open_date'])) {
276 $this->open_date = date('Y-m-d', strtotime(
277 implode('-', array_reverse(explode('/', $q['open_date'])))
285 * fetch a list of user projects.
286 * if you need to filter open/closed.. then add whereAdds before calling
288 function userProjects($au, $data='id') // COMPANY BASED!!!!
291 $id = (int) $au->company_id;
294 (client_id= $id) OR (agency_id= $id)
297 return empty($data) ? $this->fetchAll() :$this->fetchAll($data);
306 if (!$this->client_id) {
309 $c = DB_DataObject::factory('core_company');
310 $c->get($this->client_id);
318 $c = DB_DataObject::factory('core_group');
319 $c->get($this->team_id);
325 // DEPRICATED - use userProjects
327 function getUserProjects($au, $data='id') // COMPANY BASED!!!!
329 return $this->userProjects($au, $data);
336 * check who is trying to access this. false == access denied..
338 function checkPerm($lvl, $au)
340 return $au->hasPerm("Core.Projects_Member_Of",$lvl) || $au->hasPerm("Core.Projects_All",$lvl);
343 static $cache = array();
344 function cacheLoad($id)
346 if (isset(self::$cache[$id])) {
347 return self::$cache[$id];
349 $n = $this->factorySelf();
357 self::$cache[$this->id] = $this;