DataObjects/Core_company.php
[Pman.Core] / DataObjects / Core_company.php
index b913629..3e7a3e5 100644 (file)
@@ -40,7 +40,8 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
     
     function applyFilters($q, $au)
     {
-       $tn = $this->tableName();
+        
+        $tn = $this->tableName();
         $this->selectAdd("i18n_translate('c' , {$tn}.country, 'en') as country_display_name ");
       
         $tn = $this->tableName();
@@ -48,7 +49,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 +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, ',')) {
@@ -102,7 +104,13 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
                 ) as comptype_display_name
         ");
         
-        if(!empty($q['search']['name'])){
+        if(!empty($q['query']['name'])){
+            $s = $this->escape($q['query']['name']);
+            $this->whereAdd("
+                {$tn}.name LIKE '%$s%'
+            ");
+        }
+        if(!empty($q['search']['name'])){ 
             $s = $this->escape($q['search']['name']);
             $this->whereAdd("
                 {$tn}.name LIKE '%$s%'
@@ -121,7 +129,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'];
@@ -244,6 +254,18 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
     
     function beforeInsert($q, $roo)
     {
+        // we still use comptype in some old systems...
+        
+        if(!empty($q['_merge_id'])){
+            $this->merge($q['_merge_id'], $roo);
+        }
+        
+        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');
@@ -255,6 +277,24 @@ 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_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');
@@ -263,10 +303,6 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
             $roo->jerr('EXIST');
         }
         
-        if(!empty($q['_merge_id'])){
-            $this->merge($q['_merge_id'], $roo);
-        }
-        
         if(!empty($this->is_system) && 
             ($old->code != $this->code  ) // used to be not allowed to change name..
         ){
@@ -276,12 +312,18 @@ 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;
@@ -446,7 +488,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
     {
         $affects  = array();
         
-        $all_links = method_exists($this, 'databaseLinks') ? $x->databaseLinks() : $GLOBALS['_DB_DATAOBJECT']['LINKS'][$this->_database];
+        $all_links = $this->databaseLinks();
         
         foreach($all_links as $tbl => $links) {
             foreach($links as $col => $totbl_col) {