DataObjects/Core_event_audit.php
[Pman.Core] / DataObjects / Core_event_audit.php
1 <?php
2 /**
3  * Table Definition for core_event_audit
4  */
5 require_once 'DB/DataObject.php';
6
7 class Pman_Core_DataObjects_Core_event_audit extends DB_DataObject 
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'core_event_audit';             // table name
13     public $id;                              // int(11)  not_null primary_key auto_increment
14     public $event_id;                       // int(11)  not_null multiple_key
15     public $name;                       // string(128)  
16     public $old_audit_id;                        // int(11)  blob
17     public $newvalue;                           // blob(65535)  blob
18
19     
20     /* the code above is auto generated do not remove the tag below */
21     ###END_AUTOCODE
22     
23     /**
24      * get the value, 
25      *
26      */
27     
28     function newvalue($event)
29     {
30         $x = DB_DataObject::factory($event->on_table);
31         $ar = $x->links();
32         // is the name a link..
33         if (!isset($ar[$this->name])) {
34             return $this->value;
35         }
36         if (empty($this->value) ) {
37             return '';
38         }
39         // lr = ProjecT:id
40         // get the current value of that...
41         $lr = explode(':', $ar[$this->name]);
42         $x = DB_DataObject::factory($lr[0]);
43         if (!method_exists($x, 'toEventString')) {
44             return $lr[0] .':'. $this->value;
45         }
46         $x->get($this->value);
47         
48         return $x->toEventString(); // big assumption..        
49     }
50     
51     function oldvalue($event)
52     {
53         if (!$this->old_audit_id) {
54             return 'Unknown';
55         }
56         //var_dump($cg->ontable);
57         $x = DB_DataObject::factory('core_event_audit');
58         $x->get($this->old_audit_id);
59         return $x->newvalue($event);
60         
61     }
62     function findLast($event, $name)
63     {
64          DB_DataObject::debugLevel(1);
65         $x = DB_DataObject::factory('core_event_audit');
66         $x->autoJoin();
67         $x->selectAdd();
68         $x->selectAdd('core_event_audit.id as id');
69
70         $x->name = $name;
71         $x->whereAdd("
72                 join_event_id_id .on_table = '{$event->on_table}' AND
73                 join_event_id_id .on_id    = {$event->on_id}
74         ");
75         $x->orderBy('join_event_id_id.event_when DESC');
76         $x->limit(1);
77         if (!$x->find(true)) {
78             return 0;
79         }
80         return $x->id;
81         
82     }
83     
84      
85 }