fix #8131 - chinese translations
[Pman.Core] / DataObjects / Core_project.php
index eed83fb..5cc1f55 100644 (file)
@@ -27,6 +27,8 @@ class Pman_Core_DataObjects_Core_project extends DB_DataObject
     public $languages;                       // string(128)  not_null
     public $agency_id;                       // int(11)  not_null
     public $updated_dt;                      // datetime(19)  not_null binary
+    public $deleted_by;                      // INT
+    public $deleted_dt;                      // datetime(19)  not_null binary
 
     
     /* the code above is auto generated do not remove the tag below */
@@ -87,13 +89,21 @@ class Pman_Core_DataObjects_Core_project extends DB_DataObject
      * 
      */
     
-    function applyFilters($q, $au)
+    function applyFilters($q, $au, $roo)
     {
-         
+        if (empty($q['_show_deleted']) && empty($q['_is_update_request'])) {
+            $this->whereAdd('core_project.deleted_by = 0');
+        }
+        
         $tn = $this->tableName();
         if (!empty($q['query']['project_search'])) {
             $s = $this->escape($q['query']['project_search']);
-            $this->whereAdd(" ({$tn}.code LIKE '$s%') OR ({$tn}.name LIKE '%$s%')");
+            $this->whereAdd(" ({$tn}.code LIKE '$s%')
+                            OR
+                            ({$tn}.name LIKE '%$s%')
+                            OR
+                            join_client_id_id.name LIKE '%$s%'
+                ");
         }
         // types of project to list ... - default is only the open ones...
         if (!empty($q['query']['project_indaterange'])) {
@@ -101,7 +111,7 @@ class Pman_Core_DataObjects_Core_project extends DB_DataObject
                 case 'A': // all
                     break; 
                 case 'C': // current
-                     $this->whereAdd("{$tn}.close_date >= NOW()");
+                     $this->whereAdd("{$tn}.close_date is NULL OR {$tn}.close_date >= NOW()");
                     break;
                 case 'O': // old
                     $this->whereAdd("{$tn}.close_date < NOW()");
@@ -109,7 +119,9 @@ class Pman_Core_DataObjects_Core_project extends DB_DataObject
                }
         }
         
-        if (empty($q['query']['project_filter'])  || $q['query']['project_filter'] != 'ALL') {
+        if (empty($q['_is_update_request']) &&
+            
+            (empty($q['query']['project_filter'])  || $q['query']['project_filter'] != 'ALL')) {
             
                
             $pf = empty($q['query']['project_filter']) ? 'P,N,U' : $q['query']['project_filter'];
@@ -123,7 +135,7 @@ class Pman_Core_DataObjects_Core_project extends DB_DataObject
         
         //&& $au->hasPerm('Documents.Documents','S') << this is dependant on the doc modules
           
-        if (!$au->hasPerm('Core.Projects_All','S') ) {
+        if (php_sapi_name() != 'cli' && !$au->hasPerm('Core.Projects_All','S') ) {
             
             
             
@@ -151,7 +163,7 @@ class Pman_Core_DataObjects_Core_project extends DB_DataObject
           // DB_DataObjecT::debuglevel(1);
             $this->selectAdd();
             $this->selectAdd('distinct(client_id)');
-            $this->selectAs(DB_DataObject::factory('Companies'), 'client_id_%s','join_client_id_id');
+            $this->selectAs(DB_DataObject::factory('core_company'), 'client_id_%s','join_client_id_id');
             $this->groupBy('client_id');
              
         }
@@ -167,8 +179,22 @@ class Pman_Core_DataObjects_Core_project extends DB_DataObject
         
         
     }
+    
+    function beforeUpdate($old, $q, $roo)
+    {
+        if (!empty($q['_flag_deleted'])) {
+            //DB_DataObject::DebugLevel(1);
+            $this->deleted_by = $roo->getAuthUser()->id;
+            $this->deleted_dt = date("Y-m-d H:i:s");
+        }
+        if (!empty($q['_flag_undeleted'])) {
+            $this->deleted_by = 0;
+            $this->deleted_dt = '1000-01-01 00:00:00';
+        }
+    }
+    
  
-    function onInsert()
+    function onInsert($request,$roo,$event)
     {
         $oo = clone($this);
         if (empty($this->code)) {
@@ -179,7 +205,7 @@ class Pman_Core_DataObjects_Core_project extends DB_DataObject
         }
     }
     
-    function onUpdate($old)
+    function onUpdate($old, $request, $roo,$event)
     {
         $oo = clone($this);
         if (empty($this->code)) {
@@ -314,4 +340,23 @@ class Pman_Core_DataObjects_Core_project extends DB_DataObject
         return $au->hasPerm("Core.Projects_Member_Of",$lvl) || $au->hasPerm("Core.Projects_All",$lvl);
     }
     
+    static $cache = array();
+    function cacheLoad($id)
+    {
+        if (isset(self::$cache[$id])) {
+            return self::$cache[$id];
+        }
+        $n = $this->factorySelf();
+        $n->get($id);
+        $n->cacheSave();
+        return $n;
+    }
+    
+    function cacheSave()
+    {
+        self::$cache[$this->id] = $this;
+    }
+    
+    
+    
 }