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
40     
41     /* the code above is auto generated do not remove the tag below */
42     ###END_AUTOCODE
43     
44     function person($set = false)
45     {
46         if ($set !== false) {
47             $this->person_id = is_object($set) ? $set->id : $set;
48             return;
49         }
50         $c = DB_DataObject::Factory('Person');
51         $c->get($this->person_id);
52         return $c;
53         
54     }
55     function object($set = false)
56     {
57         if ($set !== false) {
58             $this->ontable = $set->tableName();
59             $this->onid = $set->id;
60             return $set;
61         }
62         $c = DB_DataObject::factory($this->ontable);
63         if ($this->onid == 0) {
64             return $c; // empty dataobject.
65         }
66         
67         $c->autoJoin();
68         if ($c->get($this->onid)) {
69             return $c;
70         }
71         return false;
72         
73     }
74     
75     
76     function act_start($set = false)
77     {
78         if ($set === false) {
79             return $this->act_start;
80         }
81         $this->act_when = $set;
82         $this->act_start = $set;
83         return $set;
84     }
85     
86     function event()
87     {
88
89         $c = DB_DataObject::factory('Events');
90         
91         if ($c->get($this->event_id)) {
92             return $c;
93         }
94         return false;
95         
96     }
97     function delivered()
98     {
99         return !empty($msgid);
100     }
101     
102     function status() // used by commandline reporting at present..
103     {
104         switch($this->event_id) {
105             case -1:
106                 return 'DELIVERED';
107             case 0:
108                 return 'PENDING';
109             default:
110                 $p ='';
111                 if (strtotime($this->act_when) > time()) {
112                     $p = "RETRY: {$this->act_when} ";
113                 }
114                 return  $p. $this->event()->remarks;
115         }
116         
117     }
118 }