DataObjects/Core_domain.php
[Pman.Core] / DataObjects / Companies.php
index 386a6da..7aebca3 100644 (file)
@@ -40,6 +40,9 @@ class Pman_Core_DataObjects_Companies extends DB_DataObject
     
     function applyFilters($q, $au)
     {
+       $tn = $this->tableName();
+        $this->selectAdd("i18n_translate('c' , {$tn}.country, 'en') as country_display_name ");
+      
         $tn = $this->tableName();
         //DB_DataObject::debugLevel(1);
         $x = DB_DataObject::factory('Companies');
@@ -49,10 +52,10 @@ class Pman_Core_DataObjects_Companies extends DB_DataObject
         if (!empty($q['query']['company_project_id'])) {
             $add = '';
             if (!empty($q['query']['company_include_self'])) {
-                $add = ' OR Companies.id = ' . $x->id;
+                $add = " OR {$tn}.id = {$x->id}";
             }
             if (!empty($q['query']['company_not_self'])) {
-                $add = ' AND Companies.id != ' . $x->id;
+                $add = " AND {$tn}.id != {$x->id}";
             }
             $pids = array();
             $pid = $q['query']['company_project_id'];
@@ -67,7 +70,7 @@ class Pman_Core_DataObjects_Companies extends DB_DataObject
             
             
             $pids = implode(',', $pids);
-            $this->whereAdd("Companies.id IN (
+            $this->whereAdd("{$tn}.id IN (
                 SELECT distinct(company_id) FROM ProjectDirectory where project_id IN ($pids)
             ) $add" );
              
@@ -99,13 +102,18 @@ class Pman_Core_DataObjects_Companies extends DB_DataObject
                 ) as comptype_display_name
         ");
         
-        if(!empty($q['query']['name'])){
-            $s = $this->escape($q['query']['name']);
+        if(!empty($q['search']['name'])){
+            $s = $this->escape($q['search']['name']);
             $this->whereAdd("
                 {$tn}.name LIKE '%$s%'
             ");
         }
-         
+          if(!empty($q['search']['name_starts'])){
+            $s = $this->escape($q['search']['name_starts']);
+            $this->whereAdd("
+                {$tn}.name LIKE '$s%'
+            ");
+        }
     }
     
     function toEventString() {
@@ -240,7 +248,7 @@ class Pman_Core_DataObjects_Companies extends DB_DataObject
     function beforeUpdate($old, $q,$roo)
     {
         if(!empty($this->is_system) && 
-            ($old->code != $this->code || $old->name != $this->name)
+            ($old->code != $this->code  ) // used to be not allowed to change name..
         ){
             $roo->jerr('This company is not allow to editing Ref. or Company Name...');
         }