X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FCore_company.php;h=aca5be848d4448fc36a450ed30657b39263eb7db;hp=13ddb6b68bafe0bffc2b54c32f4a174a6b7d9c90;hb=HEAD;hpb=5d4ac076dc4f620fbb91944eead3e0af66216a03 diff --git a/DataObjects/Core_company.php b/DataObjects/Core_company.php index 13ddb6b6..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,12 +35,20 @@ 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(); + + $tn = $this->tableName(); $this->selectAdd("i18n_translate('c' , {$tn}.country, 'en') as country_display_name "); $tn = $this->tableName(); @@ -48,7 +56,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject $x = DB_DataObject::factory('core_company'); $x->comptype= 'OWNER'; $x->find(true); - + if (!empty($q['query']['company_project_id'])) { $add = ''; if (!empty($q['query']['company_include_self'])) { @@ -57,6 +65,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject if (!empty($q['query']['company_not_self'])) { $add = " AND {$tn}.id != {$x->id}"; } + $pids = array(); $pid = $q['query']['company_project_id']; if (strpos($pid, ',')) { @@ -77,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'); } @@ -102,14 +111,19 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject ) as comptype_display_name "); - if(!empty($q['search']['name'])){ - $s = $this->escape($q['search']['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%' "); @@ -121,11 +135,15 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject } // ---------- AUTHENTICATION - function isAuth() + // not sure where authetnication via company is used?? posibly media-outreach + + function isAuth() { $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']); @@ -244,23 +262,72 @@ 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) { + // 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'])){ + $this->deleted_dt = ""; + $this->deleted_by = 0; + } if(!empty($q['_check_name'])){ if($this->checkName()){ $roo->jok('OK'); } - $roo->jerr('EXIST'); + $roo->jerror('NOTICE-EXIST-CHECK','EXIST'); } if(!empty($q['_merge_id'])){ @@ -276,18 +343,24 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject function beforeDelete($req, $roo) { + // should check for members.... if(!empty($this->is_system) && ($old->code != $this->code || $old->name != $this->name) ){ $roo->jerr('This company is not allow to delete'); } + + + } + function onDelete($req, $roo) + { $img = DB_DataObject::factory('Images'); $img->ontable = $this->tableName(); $img->onid = $this->id; $img->find(); while ($img->fetch()) { - $img->beforeDelete(); + $img->beforeDelete(array(), $roo); $img->delete(); } return true; @@ -431,12 +504,38 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject $companies->insert(); $companies->onInsert(array(), $roo); } - function lookupOwner() + + 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; @@ -446,7 +545,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject { $affects = array(); - $all_links = $GLOBALS['_DB_DATAOBJECT']['LINKS'][$this->_database]; + $all_links = $this->databaseLinks(); foreach($all_links as $tbl => $links) { foreach($links as $col => $totbl_col) {