X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=DataObjects%2FCore_company.php;h=aca5be848d4448fc36a450ed30657b39263eb7db;hb=586e4eb470252d837ba18b67e4c3c1702131fd1d;hp=571777091431b80b9185239d9b5c09da32fc4fe4;hpb=72d1e6ffa10921261874f0faadb8acfd9743bfb6;p=Pman.Core diff --git a/DataObjects/Core_company.php b/DataObjects/Core_company.php index 57177709..aca5be84 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) @@ -49,9 +49,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject $x = DB_DataObject::factory('core_company'); $x->comptype= 'OWNER'; $x->find(true); - - var_dump('fetch here??');exit; - + if (!empty($q['query']['company_project_id'])) { $add = ''; if (!empty($q['query']['company_include_self'])) { @@ -60,6 +58,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, ',')) { @@ -105,14 +104,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%' "); @@ -124,7 +128,9 @@ 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']; @@ -247,6 +253,26 @@ 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'); @@ -258,6 +284,35 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject 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'); @@ -279,18 +334,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; @@ -449,7 +510,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject { $affects = array(); - $all_links = $x->databaseLinks(); + $all_links = $this->databaseLinks(); foreach($all_links as $tbl => $links) { foreach($links as $col => $totbl_col) {