4 * Table is designed to be used with a mailer to notify or issue
5 * emails (or maybe others later??)
8 CREATE TABLE core_notify (
9 `id` int(11) NOT NULL AUTO_INCREMENT,
10 `recur_id` INT(11) NOT NULL;
11 `act_when` DATETIME NOT NULL,
12 `onid` int(11) NOT NULL DEFAULT 0,
13 `ontable` varchar(128) NOT NULL DEFAULT '',
14 `person_id` int(11) NOT NULL DEFAULT 0,
15 `msgid` varchar(128) NOT NULL DEFAULT '',
16 `sent` DATETIME NOT NULL,
17 `event_id` int(11) NOT NULL DEFAULT 0,
19 INDEX `lookup`(`act_when`, `msgid`)
23 require_once 'DB/DataObject.php';
25 class Pman_Core_DataObjects_Core_notify extends DB_DataObject
28 /* the code below is auto generated do not remove the above tag */
30 public $__table = 'core_notify'; // table name
31 public $id; // int(11) not_null primary_key auto_increment
32 public $recur_id; // int(11) not_null
33 public $act_when; // datetime(19) not_null multiple_key binary
34 public $onid; // int(11) not_null
35 public $ontable; // string(128) not_null
36 public $person_id; // int(11) not_null
37 public $msgid; // string(128) not_null
38 public $sent; // datetime(19) not_null binary
39 public $event_id; // int(11)
40 public $watch_id; // int(11)
41 public $trigger_person_id; // int(11)
42 public $trigger_event_id; // int(11)
43 public $evtype; // event type (or method to call)fall
48 /* the code above is auto generated do not remove the tag below */
51 function person($set = false)
54 $this->person_table = is_object($set) ? $set->tableName() : '';
55 $this->person_id = is_object($set) ? $set->id : $set;
58 static $cache =array();
59 $person_table = empty($this->person_table) ? 'Person' : $this->person_table;
60 $col = $person_table == "Person" ? 'person_id' : $person_table . '_id';
62 if (isset($cache[$person_table .':'. $this->{$col}])) {
63 return $cache[$person_table .':'. $this->{$col}];
66 $c = DB_DataObject::Factory($person_table);
67 $c->get($this->{$col});
68 $cache[$person_table .':'. $this->{$col}] = $c;
72 function object($set = false)
75 $this->ontable = $set->tableName();
76 $this->onid = $set->id;
79 $c = DB_DataObject::factory($this->ontable);
81 if ($this->onid == 0) {
82 return $c; // empty dataobject.
87 if ($c->get($this->onid)) {
94 function lookup($obj, $person, $evtype='')
96 $x = DB_DataObject::Factory($this->tableName());
99 if (!empty($evtype)) {
100 $x->evtype = $evtype;
102 if ($x->count() != 1) {
111 function beforeDelete($dependants_array, $roo) {
112 if ($this->delivered()) {
113 $roo->jerr("you can not delete a record of a successfull delivery");
116 function beforeInsert($request,$roo)
118 if (empty($request['act_when']) && !empty($request['act_start'])) {
119 $this->act_start($request['act_start']);
123 function beforeUpdate($old, $request,$roo)
125 if (empty($request['act_when']) && !empty($request['act_start'])) {
126 $this->act_start($request['act_start']);
131 function act_start($set = false)
133 if ($set === false) {
134 return $this->act_start;
136 $this->act_when = $set;
137 $this->act_start = $set;
144 $c = DB_DataObject::factory('Events');
146 if ($c->get($this->event_id)) {
153 function triggerEvent()
156 $c = DB_DataObject::factory('Events');
158 if ($c->get($this->trigger_event_id)) {
167 return !empty($this->msgid);
170 function whereAddDeliveryStatus($delivered = false)
172 $tn = $this->tableName();
174 $this->whereAdd("$tn.msgid IS NOT NULL AND $tn.msgid != ''");
176 $this->whereAdd("$tn.msgid IS NULL OR $tn.msgid = ''");
180 function status() // used by commandline reporting at present..
182 switch($this->event_id) {
184 return 'DELIVERED'; //not valid..
189 if (strtotime($this->act_when) > time()) {
190 $p = "RETRY: {$this->act_when} ";
192 return $p. $this->event()->remarks;
197 function applyFilters($q, $au, $roo)
199 if (isset($q['ontable']) && !in_array($q['ontable'], array('Person', 'Events', 'core_watch'))) {
200 // this will only work on tables not joined to ours.
202 //DB_DAtaObject::DebugLevel(1);
203 // then we can build a join..
204 $d = DB_DataObject::Factory($q['ontable']);
205 $ji = $d->autoJoin();
206 //echo '<PRE>';print_R($ji);
208 foreach($ji['join_names'] as $cname=>$fname) {
209 $this->selectAdd($fname . ' as ontable_id_' . $cname );
212 //$this->selectAdd($d->_query['data_select']); -- this will cause the same dataIndex...
214 LEFT JOIN {$d->tableName()} ON {$this->tableName()}.onid = {$d->tableName()}.id
217 $this->selectAs($d, 'core_notify_%s');
219 if (!empty($q['query']['person_id_name']) ) {
220 $this->whereAdd( "join_person_id_id.name LIKE '{$this->escape($q['query']['person_id_name'])}%'");
223 if (!empty($q['query']['status'])) {
224 switch ($q['query']['status']) {
227 $this->whereAdd("msgid != ''");
231 $this->whereAdd("msgid = '' AND event_id > 0 AND act_when < NOW()");
235 $this->whereAdd('event_id = 0 OR (event_id > 0 AND act_when > NOW() )');
239 $this->whereAdd('is_open > 0');
248 if(!empty($q['_evtype_align'])){
255 etype = 'Core.NotifyType'
257 name = core_notify.evtype
264 if(!empty($q['from'])){
266 act_when >= '{$q['from']}'
270 if(!empty($q['to'])){
272 act_when <= '{$q['to']}'