fix #8131 - chinese translations
[Pman.Core] / DataObjects / Core_event_audit.php
index da326ad..0e578b1 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 /**
- * Table Definition for mtrack_change_audit
+ * Table Definition for core_event_audit
  */
-require_once 'DB/DataObject.php';
+class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
 
 class Pman_Core_DataObjects_Core_event_audit extends DB_DataObject 
 {
@@ -25,7 +25,7 @@ class Pman_Core_DataObjects_Core_event_audit extends DB_DataObject
      *
      */
     
-    function value($event)
+    function newvalue($event)
     {
         $x = DB_DataObject::factory($event->on_table);
         $ar = $x->links();
@@ -45,108 +45,43 @@ class Pman_Core_DataObjects_Core_event_audit extends DB_DataObject
         }
         $x->get($this->value);
         
-        return $x->toEventString(); // big assumption..
-        
-    }
-    function oldvalue($cg)
-    {
-        //var_dump($cg->ontable);
-        $x = DB_DataObject::factory($cg->ontable);
-        
-        $ar = $x->links();
-        if ( !isset($ar[$this->field()])) {
-            return $this->oldvalue;
-        }
-        // lr = ProjecT:id
-        if (empty($this->oldvalue)) {
-            return '';
-        }
-        $lr = explode(':', $ar[$this->field()]);
-        $x = DB_DataObject::factory($lr[0]);
-        $x->get($this->oldvalue);
-        return isset($x->name) ? $x->name : $this->oldvalue; 
-        
+        return $x->toEventString(); // big assumption..        
     }
     
-    function toAuditString($change)
+    function oldvalue($event)
     {
-        $field = $this->field();
-        switch($field) {
-            case 'id':
-            case 'created_id':
-            
-                return false; //??? ignore?
-            case '@components':
-                return false;
-            //  $old = array();
-            //  foreach (preg_split("/\s*,\s*/", $old_values[$field]) as $id) {
-             /*   if (!strlen($id)) continue;
-                $c = get_component($id);
-                $old[$id] = $c->name;
-              }
-              $value = $T->getComponents();
-              $field = 'Component';
-              break;
-             */
-            case '@milestones':
-                return false;
-            //  $old = array();
-            //  foreach (preg_split("/\s*,\s*/", $old_values[$field]) as $id) {
-              /*  if (!strlen($id)) continue;
-                $m = get_milestone($id);
-                $old[$id] = $m->name;
-              }
-              $value = array();
-              $value = $T->getMilestones();
-              $field = 'Milestone';
-              break;
-              */
-            case '@keywords':
-                return false;
-            
-            default:
-                $oldvalue = $this->oldvalue($change);
-                $value = $this->value($change);
-                
-                $field = preg_replace('/_id$/', '', $this->field());
-                $field = ucfirst(str_replace('_', ' ', $field));
-                
-                if ( ($oldvalue == $value)  ||
-                    (!strlen($oldvalue) && !strlen($value))) {
-                    return false;
-                }
-                $lb = strpos($oldvalue,"\n") > -1 || strpos($value,"\n") > -1 ? "\n\n" : '';
-                $lbs = $lb == '' ? '' : "\n\n---\n\n";
-                if (!strlen($oldvalue)) {
-                    return " * Set {$field} to: {$lbs}{$value}{$lbs}";
-                }
-                       
-                if (!strlen($value)) {
-                    return  " * Removed {$lb}{$field} - was: {$lbs}{$oldvalue}";
-                    
-                }
-                
-                return " * Changed {$field} from : {$lbs}{$oldvalue} {$lbs} to {$lbs}{$value}{$lbs}";
-                
+        if (!$this->old_audit_id) {
+            return 'Unknown';
         }
+        //var_dump($cg->ontable);
+        $x = DB_DataObject::factory('core_event_audit');
+        $x->get($this->old_audit_id);
+        return $x->newvalue($event);
+        
     }
-    
-    function toJSONArray($change)
+    function findLast($event, $name)
     {
-        $ret=  $this->toArray();
-        // now add the value strings..
+        //DB_DataObject::debugLevel(1);
+        $x = DB_DataObject::factory('core_event_audit');
+        $x->autoJoin();
+         
         
-        $field = preg_replace('/_id$/', '', $this->field());
-        $field = ucfirst(str_replace('_', ' ', $field));
-                
-        $ret['field_str'] = $field;
+        $x->selectAdd();
+        $x->selectAdd('core_event_audit.id as id');
 
-        $ret['oldvalue_str'] = $this->oldvalue($change);
-        $ret['value_str'] = $this->value($change);
-        return $ret;
+        $x->name = $name;
+        $x->whereAdd("
+                join_event_id_id.on_table = '{$event->on_table}' AND
+                join_event_id_id.on_id    = {$event->on_id}
+        ");
+        $x->orderBy('join_event_id_id.event_when DESC');
+        $x->limit(1);
+        if (!$x->find(true)) {
+            return 0;
+        }
+        return $x->id;
         
     }
     
-    
-    
+     
 }
\ No newline at end of file