3 * Table Definition for Events
5 require_once 'DB/DataObject.php';
7 class Pman_Core_DataObjects_Events extends DB_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'Events'; // table name
13 public $id; // int(11) not_null primary_key auto_increment
14 public $person_name; // string(128)
15 public $event_when; // datetime(19) binary
16 public $action; // string(32)
17 public $ipaddr; // string(16)
18 public $on_id; // int(11)
19 public $on_table; // string(64)
20 public $person_id; // int(11)
21 public $remarks; // blob(65535) blob
24 /* the code above is auto generated do not remove the tag below */
27 * check who is trying to access this. false == access denied..
29 function checkPerm($lvl, $au)
31 return $lvl == 'S' && $au->hasPerm("Admin.Admin_Tab", $lvl);
35 * Initialize an event - ready to insert..
37 * @param {String} action - group/name of event
38 * @param {DataObject|false} obj - dataobject action occured on.
39 * @param {String} any remarks
42 function init($act, $obj, $remarks)
44 $pg = HTML_FlexyFramework::get()->page;
45 $au = $pg->getAuthUser();
47 $this->person_name = $au && !empty($au->name) ? $au->name : '';
48 $this->person_id = $au ? $au->id : '';
49 $this->ipaddr = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : 'cli';
51 $this->on_table = $obj ? $obj->tableName() : '';
52 $pk = $obj ? $obj->keys() : false;
53 $this->on_id = $obj && $pk ? $obj->{$pk[0]}: 0;
55 // should this really go in remarks? -
56 if ($obj && method_exists($obj,'toEventString')) {
57 $rem[] = $obj->toEventString() ;
60 $this->remarks = implode(' : ', $rem);
64 * Generate an audit for this field.
66 * @param {DB_DataObject} new data
67 * @param {DB_DataObject} old data
69 * @return {int} number of entries logged.
72 function audit($new, $old = false)
75 return 0; // they are the same...
79 foreach(array_keys($new->table()) as $k) {
80 // should we JSON serialize this?
81 $n = empty($new->$k) ? '' : $new->$k;
82 $o = empty($old->$k) || empty($old->$k) ? '' : $old->$k;
86 $x = DB_DataObject::factory('core_event_audit');
88 'event_id' => $this->id,
90 'old_audit_id' => $old ? $x->findLast($this, $k) : 0,