X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FCore_event_audit.php;h=0e578b10f1ee58be2c9e19bd296f6a9da28a5abf;hp=da326ad3568dce78e1c18275875b96cb75d55a1e;hb=HEAD;hpb=f788b6891a4f0e47547a58d106e3f524ffa86c52 diff --git a/DataObjects/Core_event_audit.php b/DataObjects/Core_event_audit.php index da326ad3..0e578b10 100644 --- a/DataObjects/Core_event_audit.php +++ b/DataObjects/Core_event_audit.php @@ -1,8 +1,8 @@ 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