X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FCore_company.php;h=aca5be848d4448fc36a450ed30657b39263eb7db;hp=0e02579d9e752fd541475f796b4f0911b48badd4;hb=HEAD;hpb=72fa007d6199dd5b1414f919541c6051bdd60c1a diff --git a/DataObjects/Core_company.php b/DataObjects/Core_company.php index 0e02579d..4ae8fb3e 100644 --- a/DataObjects/Core_company.php +++ b/DataObjects/Core_company.php @@ -12,7 +12,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject public $__table = 'core_company'; // table name public $code; // string(32) not_null public $name; // string(128) - public $remarks; // blob(65535) blob + public $remarks; // blob(65535) blobeforeDeleteb public $owner_id; // int(11) not_null public $address; // blob(65535) blob public $tel; // string(32) @@ -35,10 +35,17 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject public $country; // string(4) not_null public $is_system; // int(2) + + public $comptype_id; + public $address1; + public $address2; + public $address3; + + /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - function applyFilters($q, $au) + function applyFilters($q, $au, $roo) { $tn = $this->tableName(); @@ -79,7 +86,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject } if (!empty($q['query']['comptype'])) { - $this->whereAddIn('comptype', explode(',', $q['query']['comptype']), 'string'); + $this->whereAddIn($tn.'.comptype', explode(',', $q['query']['comptype']), 'string'); } @@ -104,14 +111,19 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject ) as comptype_display_name "); - if(!empty($q['query']['name'])){ - $s = $this->escape($q['query']['name']); + if(!empty($q['query']['name']) || !empty($q['search']['name'])){ + + $s = (!empty($q['query']['name'])) ? $this->escape($q['query']['name']) : $this->escape($q['search']['name']); + $this->whereAdd(" {$tn}.name LIKE '%$s%' "); } - if(!empty($q['search']['name_starts'])){ - $s = $this->escape($q['search']['name_starts']); + + if(!empty($q['query']['name_starts']) || !empty($q['search']['name_starts'])){ + + $s = (!empty($q['query']['name_starts'])) ? $this->escape($q['query']['name_starts']) : $this->escape($q['search']['name_starts']); + $this->whereAdd(" {$tn}.name LIKE '$s%' "); @@ -129,7 +141,9 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject { $db = $this->getDatabaseConnection(); $sesPrefix = $db->dsn['database']; - @session_start(); + if (empty($_SERVER['PHP_AUTH_USER'])) { + @session_start(); + } if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) { // in session... $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']); @@ -248,24 +262,63 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject function beforeInsert($q, $roo) { + // we still use comptype in some old systems... + + if(!empty($q['comptype']) && empty($q['comptype_id'])) { + $en = DB_DataObject::Factory('core_enum'); + $en->setFrom(array( + 'etype' => 'COMPTYPE', + 'name' => $q['comptype'], + 'active' => 1 + )); + if($en->find(true)) { + $this->comptype_id = $en->id; + } + } + + if (!empty($q['comptype_id'])) { + $en = DB_DataObject::Factory('core_enum'); + $en->get($q['comptype_id']); + $this->comptype = $en->name; + } + if(!empty($q['_check_name'])){ if($this->checkName()){ $roo->jok('OK'); } - $roo->jerr('EXIST'); + $roo->jerror('NOTICE-EXIST-CHECK','EXIST'); } } function beforeUpdate($old, $q,$roo) { - - if(!empty($q['_flag_delete']) && $q['_flag_delete'] * 1 == 1){ + // we still use comptype in some old systems... + + if(!empty($q['comptype']) && empty($q['comptype_id'])) { + $en = DB_DataObject::Factory('core_enum'); + $en->setFrom(array( + 'etype' => 'COMPTYPE', + 'name' => $q['comptype'], + 'active' => 1 + )); + if($en->find(true)) { + $this->comptype_id = $en->id; + } + } + + if (!empty($q['comptype_id'])) { + $en = DB_DataObject::Factory('core_enum'); + $en->get($q['comptype_id']); + $this->comptype = $en->name; + } + + if(!empty($q['_flag_delete'])){ $this->deleted_dt = $this->sqlValue("NOW()"); $this->deleted_by = $roo->getAuthUser()->id; } - if(!empty($q['_flag_undelete']) && $q['_flag_undelete'] * 1 == 1){ + if(!empty($q['_flag_undelete'])){ $this->deleted_dt = ""; $this->deleted_by = 0; } @@ -274,7 +327,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject $roo->jok('OK'); } - $roo->jerr('EXIST'); + $roo->jerror('NOTICE-EXIST-CHECK','EXIST'); } if(!empty($q['_merge_id'])){ @@ -307,7 +360,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject $img->onid = $this->id; $img->find(); while ($img->fetch()) { - $img->beforeDelete(); + $img->beforeDelete(array(), $roo); $img->delete(); } return true; @@ -451,12 +504,38 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject $companies->insert(); $companies->onInsert(array(), $roo); } + + function owner() + { + if (empty($this->owner_id)) { + return false; + } + static $cache = false; + if ($cache !== false && isset($cache[$this->owner_id])) { + return $cache[$this->owner_id]; + } + $o = DB_DataObject::factory('core_company'); + if (!$o->get($this->owner_id)) { + return false; + } + $cache[$this->owner_id] = $o; + return $o; + + } + + /// look up the company which is the system owner... static function lookupOwner() { + static $cache = false; + if ($cache !== false) { + return clone($cache); // no updating this object.. + } + $enum = DB_DataObject::Factory('core_enum')->lookup('COMPTYPE', 'OWNER' ); $companies = DB_DataObject::factory('core_company'); $companies->comptype_id = $enum; if ($companies->find(true)) { + $cache = clone($companies); return $companies; } return false;