###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
- public $__table = 'Projects'; // table name
+ public $__table = 'Projects'; // table name
public $id; // int(11) not_null primary_key auto_increment
public $name; // string(254) not_null
public $remarks; // blob(65535) not_null blob
public $file_location; // string(254) not_null
public $open_date; // date(10) binary
public $open_by; // int(11) not_null
+ public $close_date; // date(10) binary
public $countries; // string(128) not_null
public $languages; // string(128) not_null
- public $close_date; // date(10) binary
public $agency_id; // int(11) not_null
+ public $updated_dt; // datetime(19) not_null binary
/* the code above is auto generated do not remove the tag below */
}
function toEventString() {
- return $this->client()->toEventString() . ':' . $this->name;
+ $c = $this->client();
+ return ($c->id ? $c->toEventString() : '??'). ':' . $this->name;
}
/**
$pf = empty($q['query']['project_filter']) ? 'P,N,U' : $q['query']['project_filter'];
- $bits= explode(',' ,$pf);
- foreach($bits as $i=>$k) {
- $bits[$i] = $this->escape($k);
- }
- $this->whereAdd("Projects.type in ('". implode("','", $bits) . "')");
+
+
+
+ $this->whereAddIn("Projects.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') &&
- $au->hasPerm('Documents.Documents','S')) {
+ if (!$au->hasPerm('Core.Projects_All','S') ) {
$pr->whereAdd("Projects.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')");
// this is clipping related.. -- we should have an API for addons like this.. (and docs)
- if ($au->company()->comptype == 'SUPPLIER') {
- $pr = DB_DataObject::factory('CampaignAssign');
- $pr->supplier_id = $au->company_id;
- $prjs = $pr->fetchAll('project_id');
- if (count($prjs)) {
- $this->whereAdd("
- (Projects.id IN (".implode(',', $prjs)."))
- ");
- } else {
- $this->whereAdd("1=0"); // can see nothing!!!
- }
- }
- if ($au->company()->comptype == 'CLIENT') {
- $this->client_id = $au->company()->id; // can see nothing!!!
-
- }
+
+
+
+
}
- function whereAddIn($key, $list, $type) {
- $ar = array();
- foreach($list as $k) {
- $ar[] = $type =='int' ? (int)$k : $this->escape($k);
- }
- if (!$ar) {
- return;
- }
- $this->whereAdd("$key IN (". implode(',', $ar). ')');
- }
+
function onInsert()
{
$oo = clone($this);
if (empty($this->code)) {
$this->code = 'C' + $this->client_id + '-P' + $this->id;
+ $dt = new DateTime();
+ $this->updated_dt = $dt->format('Y-m-d H:i:s');
$this->update($oo);
}
}
$oo = clone($this);
if (empty($this->code)) {
$this->code = 'C' + $this->client_id + '-P' + $this->id;
+ $dt = new DateTime();
+ $this->updated_dt = $dt->format('Y-m-d H:i:s');
$this->update($oo);
}
$olddir = $opts['storedir'] . '/' . $old->code;
$newdir = $opts['storedir'] . '/' . $this->code;
if ( file_exists($olddir)) {
- move ($olddir, $newdir);
+ move($olddir, $newdir);
}
}
-
- function i18toArray($type, $str)
- {
- if (empty($str)) {
- return array();
- }
- static $au;
- static $langs;
- static $cts;
-
- if (!$au) {
- $u = DB_DataObject::factory('Person');
- $au =$u->getAuthUser();
- $lang = empty($au->lang ) ? 'en' : $au->lang;
- $lbits = explode('_', strtoupper($lang));
- // no validation here!!!!
- require_once 'I18Nv2/Language.php';
- require_once 'I18Nv2/Country.php';
- $langs = new I18Nv2_Language($lbits[0]); // locale support not there??
- $cts = new I18Nv2_Country($lbits[0]); // lo
-
- }
- $lk = $type == 'c' ? $cts : $langs;
- $ar =explode(',', $str);
- $ret = array();
- foreach($ar as $k) {
- $ret[] = array('code'=>$k, 'title' => $lk->getName($k));
- }
- return $ret;
- // work out locale...
-
-
-
-
- }
+
- function toRooArray($req= array()) {
- $ret = parent::toArray();
- // sor tout
- $ret['countrylist'] = $this->I18toArray('c',$ret['countries']);
- $ret['languagelist'] = $this->I18toArray('l',$ret['languages']);
- return $ret;
- }
+
function setFromRoo($q)
{
$this->setFrom($q);
return true;
}
- function fetchAll($k= false) {
- if ($k !== false) {
- $this->selectAdd();
- $this->selectAdd($k);
- }
-
- $this->find();
- $ret = array();
- while ($this->fetch()) {
- $ret[] = $k === false ? clone($this) : $this->$k;
- }
- return $ret;
-
- }
/**
* fetch a list of user projects.
* if you need to filter open/closed.. then add whereAdds before calling
*/
- function getUserProjects($au, $data='id') // COMPANY BASED!!!!
+ function userProjects($au, $data='id') // COMPANY BASED!!!!
{
+
$id = (int) $au->company_id;
+
$this->whereAdd("
(client_id= $id) OR (agency_id= $id)
");
- if (!empty($data)) {
- $this->selectAdd();
- $this->selectAdd($data);
- }
- $this->find();
- $ret = array();
- while ($this->fetch()) {
- $ret[] = empty($data) ? clone($this) : $this->$data;
- }
- return $ret;
+
+ return empty($data) ? $this->fetchAll() :$this->fetchAll($data);
+
+
+ }
+
+ // DEPRICATED - use userProjects
+
+ function getUserProjects($au, $data='id') // COMPANY BASED!!!!
+ {
+ return $this->userProjects($au, $data);
+
}
{
return $au->hasPerm("Core.Projects_Member_Of",$lvl) || $au->hasPerm("Core.Projects_All",$lvl);
}
+
}