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
39     
40     /* the code above is auto generated do not remove the tag below */
41     ###END_AUTOCODE
42     
43     function person()
44     {
45         $c = DB_DataObject::Factory('Person');
46         $c->get($this->person_id);
47         return $c;
48         
49     }
50     function object()
51     {
52         $c = DB_DataObject::factory($this->ontable);
53         $c->autoJoin();
54         if ($c->get($this->onid)) {
55             return $c;
56         }
57         return false;
58         
59     }
60     function event()
61     {
62
63         $c = DB_DataObject::factory('Events');
64         
65         if ($c->get($this->event_id)) {
66             return $c;
67         }
68         return false;
69         
70     }
71     function delivered()
72     {
73         return !empty($msgid);
74     }
75     
76     function status()
77     {
78         switch($this->event_id) {
79             case -1:
80                 return 'DELIVERED';
81             case 0:
82                 return 'PENDING';
83             default:
84                 return  $this->event()->remarks;
85         }
86         
87     }
88 }