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 class_exists('DB_DataObject') ? '' : 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() : '';
58 $person_table = empty($this->person_table) ? $def_pt : strtolower($this->person_table);
59 $col = $person_table == $def_pt ? 'person_id' : $person_table . '_id';
61 $this->{$col} = is_object($set) ? $set->id : $set;
64 static $cache =array();
65 $person_table = empty($this->person_table) ? $def_pt : strtolower($this->person_table);
66 $col = $person_table == $def_pt ? 'person_id' : $person_table . '_id';
68 if (isset($cache[$person_table .':'. $this->{$col}])) {
69 return $cache[$person_table .':'. $this->{$col}];
72 $c = DB_DataObject::Factory($person_table == 'person' ? 'core_person' : $person_table);
73 $c->get($this->{$col});
74 $cache[$person_table .':'. $this->{$col}] = $c;
78 function object($set = false)
81 $this->ontable = $set->tableName();
82 $this->onid = $set->id;
85 $c = DB_DataObject::factory($this->ontable);
87 if ($this->onid == 0) {
88 return $c; // empty dataobject.
93 if ($c->get($this->onid)) {
100 function lookup($obj, $person, $evtype='')
102 $x = DB_DataObject::Factory($this->tableName());
105 if (!empty($evtype)) {
106 $x->evtype = $evtype;
108 if ($x->count() != 1) {
117 function beforeDelete($dependants_array, $roo) {
118 if ($this->delivered()) {
119 $roo->jerr("you can not delete a record of a successfull delivery");
122 function beforeInsert($request,$roo)
124 if (empty($request['act_when']) && !empty($request['act_start'])) {
125 $this->act_start($request['act_start']);
129 function beforeUpdate($old, $request,$roo)
131 if (empty($request['act_when']) && !empty($request['act_start'])) {
132 $this->act_start($request['act_start']);
137 function act_start($set = false)
139 if ($set === false) {
140 return $this->act_start;
142 $this->act_when = $set;
143 $this->act_start = $set;
150 $c = DB_DataObject::factory('Events');
152 if ($c->get($this->event_id)) {
159 function triggerEvent()
162 $c = DB_DataObject::factory('Events');
164 if ($c->get($this->trigger_event_id)) {
173 return !empty($this->msgid);
176 function whereAddDeliveryStatus($delivered = false)
178 $tn = $this->tableName();
180 $this->whereAdd("$tn.msgid IS NOT NULL AND $tn.msgid != ''");
182 $this->whereAdd("$tn.msgid IS NULL OR $tn.msgid = ''");
186 function status() // used by commandline reporting at present..
188 switch($this->event_id) {
190 return 'DELIVERED'; //not valid..
195 if (strtotime($this->act_when) > time()) {
196 $p = "RETRY: {$this->act_when} ";
198 return $p. $this->event()->remarks;
203 * current state of process
214 if ($this->msgid != '') {
218 // msgid is empty now..
219 // if act_when is greater than now, then it's still pending.
220 if (strtotime($this->act_when) > time()) {
224 // event id can be filled in with a failed attempt.
226 if ($this->event_id > 0) {
230 // event id is empty, and act_when is in the past... not sent yet..
238 function applyFilters($q, $au, $roo)
240 if (isset($q['ontable']) && !in_array($q['ontable'], array('Person', 'Events', 'core_watch'))) {
241 // this will only work on tables not joined to ours.
243 //DB_DAtaObject::DebugLevel(1);
244 // then we can build a join..
245 $d = DB_DataObject::Factory($q['ontable']);
246 $ji = $d->autoJoin();
247 //echo '<PRE>';print_R($ji);
249 foreach($ji['join_names'] as $cname=>$fname) {
250 $this->selectAdd($fname . ' as ontable_id_' . $cname );
253 //$this->selectAdd($d->_query['data_select']); -- this will cause the same dataIndex...
255 LEFT JOIN {$d->tableName()} ON {$this->tableName()}.onid = {$d->tableName()}.id
258 $this->selectAs($d, 'core_notify_%s');
260 if (!empty($q['query']['person_id_name']) ) {
261 $this->whereAdd( "join_person_id_id.name LIKE '{$this->escape($q['query']['person_id_name'])}%'");
264 if (!empty($q['query']['status'])) {
265 switch ($q['query']['status']) {
268 $this->whereAdd("msgid != ''");
272 $this->whereAdd("msgid = '' AND event_id > 0 AND act_when < NOW()");
276 $this->whereAdd('event_id = 0 OR (event_id > 0 AND act_when > NOW() )');
280 $this->whereAdd('is_open > 0');
289 if(!empty($q['_evtype_align'])){
296 etype = 'Core.NotifyType'
298 name = core_notify.evtype
305 if(!empty($q['from'])){
307 act_when >= '{$q['from']}'
311 if(!empty($q['to'])){
313 act_when <= '{$q['to']}'
319 function sendManual()
321 require_once 'Pman/Core/NotifySend.php';
323 $send = new Pman_Core_NotifySend();
324 $send->error_handler = 'exception';
327 $send->get($this->id, array());
328 } catch (Exception $e) {