DataObjects/Core_notify.php
[Pman.Core] / DataObjects / Core_notify.php
1 <?php
2 /**
3  *
4  * Table is designed to be used with a mailer to notify or issue
5  * emails (or maybe others later??)
6  *
7  *
8 CREATE TABLE  core_notify  (
9   `id` int(11)  NOT NULL AUTO_INCREMENT,
10   `act_when` DATETIME NOT NULL,
11   `onid` int(11)  NOT NULL DEFAULT 0,
12   `ontable` varchar(128)  NOT NULL DEFAULT '',
13   `person_id` int(11)  NOT NULL DEFAULT 0,
14   `msgid` varchar(128)  NOT NULL  DEFAULT '',
15   `sent` DATETIME  NOT NULL,
16   `event_id` int(11)  NOT NULL DEFAULT 0,
17   PRIMARY KEY (`id`),
18   INDEX `lookup`(`act_when`, `msgid`)
19 );
20 **/
21
22 require_once 'DB/DataObject.php';
23
24 class Pman_Core_DataObjects_Core_notify extends DB_DataObject 
25 {
26     ###START_AUTOCODE
27     /* the code below is auto generated do not remove the above tag */
28
29     public $__table = 'core_notify';                     // table name
30     public $id;                              // int(11)  not_null primary_key auto_increment
31     public $act_when;                        // datetime(19)  not_null multiple_key binary
32     public $onid;                            // int(11)  not_null
33     public $ontable;                         // string(128)  not_null
34     public $person_id;                       // int(11)  not_null
35     public $msgid;                           // string(128)  not_null
36     public $sent;                            // datetime(19)  not_null binary
37     public $event_id;                        // int(11)  
38     public $watch_id;                        // int(11)  
39     public $trigger_id;                        // int(11)  
40     
41     
42     /* the code above is auto generated do not remove the tag below */
43     ###END_AUTOCODE
44     
45     function person($set = false)
46     {
47         if ($set !== false) {
48             $this->person_id = is_object($set) ? $set->id : $set;
49             return;
50         }
51         $c = DB_DataObject::Factory('Person');
52         $c->get($this->person_id);
53         return $c;
54         
55     }
56     function object($set = false)
57     {
58         if ($set !== false) {
59             $this->ontable = $set->tableName();
60             $this->onid = $set->id;
61             return $set;
62         }
63         $c = DB_DataObject::factory($this->ontable);
64         if ($this->onid == 0) {
65             return $c; // empty dataobject.
66         }
67         
68         $c->autoJoin();
69         if ($c->get($this->onid)) {
70             return $c;
71         }
72         return false;
73         
74     }
75     
76     
77     function act_start($set = false)
78     {
79         if ($set === false) {
80             return $this->act_start;
81         }
82         $this->act_when = $set;
83         $this->act_start = $set;
84         return $set;
85     }
86     
87     function event()
88     {
89
90         $c = DB_DataObject::factory('Events');
91         
92         if ($c->get($this->event_id)) {
93             return $c;
94         }
95         return false;
96         
97     }
98     function delivered()
99     {
100         return !empty($msgid);
101     }
102     
103     function status() // used by commandline reporting at present..
104     {
105         switch($this->event_id) {
106             case -1:
107                 return 'DELIVERED';
108             case 0:
109                 return 'PENDING';
110             default:
111                 $p ='';
112                 if (strtotime($this->act_when) > time()) {
113                     $p = "RETRY: {$this->act_when} ";
114                 }
115                 return  $p. $this->event()->remarks;
116         }
117         
118     }
119 }