9741dcd7194ae521cee06d90dea7afcb1bbe6cb3
[Pman.MTrack] / DataObjects / Mtrack_change_audit.php
1 <?php
2 /**
3  * Table Definition for mtrack_change_audit
4  */
5 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
6
7 class Pman_MTrack_DataObjects_Mtrack_change_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 = 'mtrack_change_audit';             // table name
13     public $id;                              // int(11)  not_null primary_key auto_increment
14     public $change_id;                       // int(11)  not_null multiple_key
15     public $ticket_change_id;                  // int(11)  not_null multiple_key
16
17     public $fieldname;                       // string(128)  
18     public $action;                          // string(16)  
19     public $oldvalue;                        // blob(65535)  blob
20     public $value;                           // blob(65535)  blob
21
22     
23     /* the code above is auto generated do not remove the tag below */
24     ###END_AUTOCODE
25     function field()
26     {
27         $ar = explode(':', $this->fieldname);
28         return array_pop($ar);
29         
30     }
31     function value($cg)
32     {
33         $x = DB_DataObject::factory($cg->ontable);
34         $ar = $x->links();
35         if (!isset($ar[$this->field()])) {
36             return $this->value;
37         }
38         if (empty($this->value) ) {
39             $this->value = 0;
40             return '';
41         }
42         // lr = ProjecT:id
43         
44         $lr = explode(':', $ar[$this->field()]);
45         $x = DB_DataObject::factory($lr[0]);
46         $x->get($this->value);
47         return isset($x->name) ? $x->name : $this->value; // big assumption..
48         
49         
50         
51     }
52     function oldvalue($cg)
53     {
54         //var_dump($cg->ontable);
55         $x = DB_DataObject::factory($cg->ontable);
56         
57         $ar = $x->links();
58         if ( !isset($ar[$this->field()])) {
59             return $this->oldvalue;
60         }
61         // lr = ProjecT:id
62         if (empty($this->oldvalue)) {
63             $this->oldvalue = 0;
64             return '';
65         }
66         $lr = explode(':', $ar[$this->field()]);
67         $x = DB_DataObject::factory($lr[0]);
68         $x->get($this->oldvalue);
69         return isset($x->name) ? $x->name : $this->oldvalue; 
70         
71     }
72     
73     function toAuditString($change)
74     {
75         $field = $this->field();
76         switch($field) {
77             case 'id':
78             case 'created_id':
79             
80                 return false; //??? ignore?
81             case '@components':
82                 return false;
83             //  $old = array();
84             //  foreach (preg_split("/\s*,\s*/", $old_values[$field]) as $id) {
85              /*   if (!strlen($id)) continue;
86                 $c = get_component($id);
87                 $old[$id] = $c->name;
88               }
89               $value = $T->getComponents();
90               $field = 'Component';
91               break;
92              */
93             case '@milestones':
94                 return false;
95             //  $old = array();
96             //  foreach (preg_split("/\s*,\s*/", $old_values[$field]) as $id) {
97               /*  if (!strlen($id)) continue;
98                 $m = get_milestone($id);
99                 $old[$id] = $m->name;
100               }
101               $value = array();
102               $value = $T->getMilestones();
103               $field = 'Milestone';
104               break;
105               */
106             case '@keywords':
107                 return false;
108             
109             default:
110                 $oldvalue = $this->oldvalue($change);
111                 $value = $this->value($change);
112                 
113                 
114                 
115                 $field = preg_replace('/_id$/', '', $this->field());
116                 $field = ucfirst(str_replace('_', ' ', $field));
117                 
118                 if ( ($oldvalue == $value)  ||
119                     (!strlen($oldvalue) && !strlen($value))) {
120                     return false;
121                 }
122                 $lb = strpos($oldvalue,"\n") > -1 || strpos($value,"\n") > -1 ? "\n\n" : '';
123                 $lbs = $lb == '' ? '' : "\n\n---\n\n";
124                 if (!strlen($oldvalue)) {
125                     return " * Set {$field} to: {$lbs}{$value}{$lbs}";
126                 }
127                        
128                 if (!strlen($value)) {
129                     return  " * Removed {$lb}{$field} - was: {$lbs}{$oldvalue}";
130                     
131                 }
132                 
133                 return " * Changed {$field} from : {$lbs}{$oldvalue} {$lbs} to {$lbs}{$value}{$lbs}";
134                 
135         }
136     }
137     
138     function toJSONArray($change)
139     {
140         $ret=  $this->toArray();
141         // now add the value strings..
142         
143         $field = preg_replace('/_id$/', '', $this->field());
144         $field = ucfirst(str_replace('_', ' ', $field));
145                 
146         $ret['field_str'] = $field;
147
148         $ret['oldvalue_str'] = $this->oldvalue($change);
149         $ret['value_str'] = $this->value($change);
150         
151         if ($this->value == $this->oldvalue) {
152             return false;
153         }
154         
155         
156         
157         
158         return $ret;
159         
160     }
161     
162     
163     
164 }