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)
53 $def_pt = 'core_person';
56 $this->person_table = is_object($set) ? $set->tableName() : '';
60 $person_table = empty($this->person_table) ? $def_pt : strtolower($this->person_table);
61 $col = $person_table == $def_pt ? 'person_id' : $person_table . '_id';
63 $this->{$col} = is_object($set) ? $set->id : $set;
66 static $cache =array();
67 $person_table = empty($this->person_table) ? $def_pt : strtolower($this->person_table);
68 $col = $person_table == $def_pt ? 'person_id' : $person_table . '_id';
70 if (isset($cache[$person_table .':'. $this->{$col}])) {
71 return $cache[$person_table .':'. $this->{$col}];
74 $c = DB_DataObject::Factory($person_table == 'person' ? 'core_person' : $person_table);
75 $c->get($this->{$col});
76 $cache[$person_table .':'. $this->{$col}] = $c;
80 function object($set = false)
83 $this->ontable = $set->tableName();
84 $this->onid = $set->id;
87 $c = DB_DataObject::factory($this->ontable);
89 if ($this->onid == 0) {
90 return $c; // empty dataobject.
95 if ($c->get($this->onid)) {
102 function lookup($obj, $person, $evtype='')
104 $x = DB_DataObject::Factory($this->tableName());
107 if (!empty($evtype)) {
108 $x->evtype = $evtype;
110 if ($x->count() != 1) {
119 function beforeDelete($dependants_array, $roo) {
120 if ($this->delivered()) {
121 $roo->jerr("you can not delete a record of a successfull delivery");
124 function beforeInsert($request,$roo)
126 if (empty($request['act_when']) && !empty($request['act_start'])) {
127 $this->act_start($request['act_start']);
131 function beforeUpdate($old, $request,$roo)
133 if (empty($request['act_when']) && !empty($request['act_start'])) {
134 $this->act_start($request['act_start']);
139 function act_start($set = false)
141 if ($set === false) {
142 return $this->act_start;
144 $this->act_when = $set;
145 $this->act_start = $set;
152 $c = DB_DataObject::factory('Events');
154 if ($c->get($this->event_id)) {
161 function triggerEvent()
164 $c = DB_DataObject::factory('Events');
166 if ($c->get($this->trigger_event_id)) {
175 return !empty($this->msgid);
178 function whereAddDeliveryStatus($delivered = false)
180 $tn = $this->tableName();
182 $this->whereAdd("$tn.msgid IS NOT NULL AND $tn.msgid != ''");
184 $this->whereAdd("$tn.msgid IS NULL OR $tn.msgid = ''");
188 function status() // used by commandline reporting at present..
190 switch($this->event_id) {
192 return 'DELIVERED'; //not valid..
197 if (strtotime($this->act_when) > time()) {
198 $p = "RETRY: {$this->act_when} ";
200 return $p. $this->event()->remarks;
205 * current state of process
216 if ($this->msgid != '') {
220 // msgid is empty now..
221 // if act_when is greater than now, then it's still pending.
222 if (strtotime($this->act_when) > time()) {
226 // event id can be filled in with a failed attempt.
228 if ($this->event_id > 0) {
232 // event id is empty, and act_when is in the past... not sent yet..
240 function applyFilters($q, $au, $roo)
242 if (isset($q['ontable']) && !in_array($q['ontable'], array('Person', 'Events', 'core_watch'))) {
243 // this will only work on tables not joined to ours.
245 //DB_DAtaObject::DebugLevel(1);
246 // then we can build a join..
247 $d = DB_DataObject::Factory($q['ontable']);
248 $ji = $d->autoJoin();
249 //echo '<PRE>';print_R($ji);
251 foreach($ji['join_names'] as $cname=>$fname) {
252 $this->selectAdd($fname . ' as ontable_id_' . $cname );
255 //$this->selectAdd($d->_query['data_select']); -- this will cause the same dataIndex...
257 LEFT JOIN {$d->tableName()} ON {$this->tableName()}.onid = {$d->tableName()}.id
260 $this->selectAs($d, 'core_notify_%s');
262 if (!empty($q['query']['person_id_name']) ) {
263 $this->whereAdd( "join_person_id_id.name LIKE '{$this->escape($q['query']['person_id_name'])}%'");
266 if (!empty($q['query']['status'])) {
267 switch ($q['query']['status']) {
270 $this->whereAdd("msgid != ''");
274 $this->whereAdd("msgid = '' AND event_id > 0 AND act_when < NOW()");
278 $this->whereAdd('event_id = 0 OR (event_id > 0 AND act_when > NOW() )');
282 $this->whereAdd('is_open > 0');
291 if(!empty($q['_evtype_align'])){
298 etype = 'Core.NotifyType'
300 name = core_notify.evtype
307 if(!empty($q['from'])){
309 act_when >= '{$q['from']}'
313 if(!empty($q['to'])){
315 act_when <= '{$q['to']}'
321 function sendManual()
323 require_once 'Pman/Core/NotifySend.php';
325 $send = new Pman_Core_NotifySend();
326 $send->error_handler = 'exception';
329 $send->get($this->id, array());
330 } catch (Exception $e) {