/**
* Table Definition for Projects
*/
-require_once 'DB/DataObject.php';
+class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
-class Pman_Core_DataObjects_Core_projects extends DB_DataObject
+class Pman_Core_DataObjects_Core_project extends DB_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $languages; // string(128) not_null
public $agency_id; // int(11) not_null
public $updated_dt; // datetime(19) not_null binary
+ public $deleted_by; // INT
+ public $deleted_dt; // datetime(19) not_null binary
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
function getProjectManagers()
{
- $c = DB_DataObject::factory('Companies');
+ $c = DB_DataObject::factory('core_company');
$c->isOwner = 1;
if (!$c->find(true)) {
return array();
}
$ret = array();
- $p = DB_DataObject::factory('Person');
+ $p = DB_DataObject::factory('core_person');
$p->whereAdd('id IN ('. implode(',', $pmids) .')');
$p->find();
while ($p->fetch()) {
function toEventString() {
$c = $this->client();
- return ($c->id ? $c->toEventString() : '??'). ':' . $this->name;
+ return ($c && $c->id ? $c->toEventString() : '??'). ':' . $this->name;
}
/**
*
*/
- function applyFilters($q, $au)
+ function applyFilters($q, $au, $roo)
{
-
+ if (empty($q['_show_deleted']) && empty($q['_is_update_request'])) {
+ $this->whereAdd('core_project.deleted_by = 0');
+ }
+
+ $tn = $this->tableName();
if (!empty($q['query']['project_search'])) {
$s = $this->escape($q['query']['project_search']);
- $this->whereAdd(" (Projects.code LIKE '$s%') OR (Projects.name LIKE '%$s%')");
+ $this->whereAdd(" ({$tn}.code LIKE '$s%')
+ OR
+ ({$tn}.name LIKE '%$s%')
+ OR
+ join_client_id_id.name LIKE '%$s%'
+ ");
}
// types of project to list ... - default is only the open ones...
if (!empty($q['query']['project_indaterange'])) {
case 'A': // all
break;
case 'C': // current
- $this->whereAdd('Projects.close_date >= NOW()');
+ $this->whereAdd("{$tn}.close_date is NULL OR {$tn}.close_date >= NOW()");
break;
case 'O': // old
- $this->whereAdd('Projects.close_date < NOW()');
+ $this->whereAdd("{$tn}.close_date < NOW()");
break;
}
}
- if (empty($q['query']['project_filter']) || $q['query']['project_filter'] != 'ALL') {
+ if (empty($q['_is_update_request']) &&
+
+ (empty($q['query']['project_filter']) || $q['query']['project_filter'] != 'ALL')) {
$pf = empty($q['query']['project_filter']) ? 'P,N,U' : $q['query']['project_filter'];
- $this->whereAddIn("Projects.type", explode(',', $pf), 'string');
+ $this->whereAddIn("{$tn}.type", explode(',', $pf), 'string');
}
// user projects!!!! - make sure they can only see project they are suppsed to..
// only applies to document stuff..
//&& $au->hasPerm('Documents.Documents','S') << this is dependant on the doc modules
- if (!$au->hasPerm('Core.Projects_All','S') ) {
+ if (php_sapi_name() != 'cli' && !$au->hasPerm('Core.Projects_All','S') ) {
- $pr = DB_DataObject::factory('Projects');
- $pr->whereAdd("Projects.type IN ('N','X')");
+ $pr = DB_DataObject::factory($tn);
+ $pr->whereAdd("{$tn}.type IN ('N','X')");
$prjs = $pr->fetchAll('id');
//DB_DataObject::debugLevel(1);
$pd = DB_DataObject::factory('ProjectDirectory');
- $pd->joinAdd(DB_DataObject::factory('Projects'), 'LEFT');
- $pd->whereAdd("Projects.type NOT IN ('N','X')");
+ $pd->joinAdd(DB_DataObject::factory($tn), 'LEFT');
+ $pd->whereAdd("{$tn}.type NOT IN ('N','X')");
$pd->person_id = $au->id;
$prjs = array_merge($prjs, $pd->fetchAll('project_id'));
if (count($prjs)) {
$this->whereAdd("
- (Projects.id IN (".implode(',', $prjs)."))
+ ({$tn}.id IN (".implode(',', $prjs)."))
");
} else {
$this->whereAdd("1=0"); // can see nothing!!!
// DB_DataObjecT::debuglevel(1);
$this->selectAdd();
$this->selectAdd('distinct(client_id)');
- $this->selectAs(DB_DataObject::factory('Companies'), 'client_id_%s','join_client_id_id');
+ $this->selectAs(DB_DataObject::factory('core_company'), 'client_id_%s','join_client_id_id');
$this->groupBy('client_id');
}
}
+
+ function beforeUpdate($old, $q, $roo)
+ {
+ if (!empty($q['_flag_deleted'])) {
+ //DB_DataObject::DebugLevel(1);
+ $this->deleted_by = $roo->getAuthUser()->id;
+ $this->deleted_dt = date("Y-m-d H:i:s");
+ }
+ if (!empty($q['_flag_undeleted'])) {
+ $this->deleted_by = 0;
+ $this->deleted_dt = '1000-01-01 00:00:00';
+ }
+ }
+
- function onInsert()
+ function onInsert($request,$roo,$event)
{
$oo = clone($this);
if (empty($this->code)) {
}
}
- function onUpdate($old)
+ function onUpdate($old, $request, $roo,$event)
{
$oo = clone($this);
if (empty($this->code)) {
}
+
+
+ function client()
+ {
+ if (!$this->client_id) {
+ return false;
+ }
+ $c = DB_DataObject::factory('core_company');
+ $c->get($this->client_id);
+ return $c;
+ }
+
+
+
+ function team()
+ {
+ $c = DB_DataObject::factory('core_group');
+ $c->get($this->team_id);
+ return $c;
+ }
+
+
+
// DEPRICATED - use userProjects
function getUserProjects($au, $data='id') // COMPANY BASED!!!!
}
- function client()
- {
- $c = DB_DataObject::factory('Companies');
- $c->get($this->client_id);
- return $c;
- }
-
/**
* check who is trying to access this. false == access denied..
*/
return $au->hasPerm("Core.Projects_Member_Of",$lvl) || $au->hasPerm("Core.Projects_All",$lvl);
}
+ static $cache = array();
+ function cacheLoad($id)
+ {
+ if (isset(self::$cache[$id])) {
+ return self::$cache[$id];
+ }
+ $n = $this->factorySelf();
+ $n->get($id);
+ $n->cacheSave();
+ return $n;
+ }
+
+ function cacheSave()
+ {
+ self::$cache[$this->id] = $this;
+ }
+
+
+
}