DataObjects/ProjectDirectory.php
[Pman.Core] / DataObjects / Events.php
1 <?php
2 /**
3  * Table Definition for Events
4  */
5 require_once 'DB/DataObject.php';
6
7 class Pman_Core_DataObjects_Events extends DB_DataObject 
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
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
22
23     
24     /* the code above is auto generated do not remove the tag below */
25     ###END_AUTOCODE
26     /**
27      * check who is trying to access this. false == access denied..
28      */
29     function checkPerm($lvl, $au) 
30     {
31         return $lvl == 'S' && $au->hasPerm("Admin.Admin_Tab", $lvl);
32     } 
33     /**
34      * init:
35      * Initialize an event - ready to insert..
36      * 
37      * @param {String} action  - group/name of event
38      * @param {DataObject|false} obj - dataobject action occured on.
39      * @param {String} any remarks 
40      */
41     
42     function init($act, $obj, $remarks)
43     {
44         $pg = HTML_FlexyFramework::get()->page;
45         $au = $pg->getAuthUser();
46          
47         $this->person_name = $au ? $au->name : '';
48         $this->person_id = $au ? $au->id : '';
49         $this->ipaddr = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : 'cli';
50         $this->action = $act;
51         $this->on_table = $obj ? $obj->tableName() : '';
52         $pk = $obj ? $obj->keys()  : false;
53         $this->on_id  = $obj && $pk ? $obj->{$pk[0]}: 0;
54         $rem  = array();
55         // should this really go in remarks? - 
56         if ($obj && method_exists($obj,'toEventString')) {
57             $rem[] = $obj->toEventString() ;
58         }
59         $rem[] = $remarks;
60         $this->remarks = implode(' : ', $rem);
61     }
62 }