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 $col = $this->person_table == "Person" ? 'person_id' : $person_table . '_id';
56 $this->person_id = is_object($set) ? $set->id : $set;
59 static $cache =array();
60 $person_table = empty($this->person_table) ? 'Person' : $this->person_table;
61 $col = $person_table == "Person" ? 'person_id' : $person_table . '_id';
63 if (isset($cache[$person_table .':'. $this->{$col}])) {
64 return $cache[$person_table .':'. $this->{$col}];
67 $c = DB_DataObject::Factory($person_table);
68 $c->get($this->{$col});
69 $cache[$person_table .':'. $this->{$col}] = $c;
73 function object($set = false)
76 $this->ontable = $set->tableName();
77 $this->onid = $set->id;
80 $c = DB_DataObject::factory($this->ontable);
82 if ($this->onid == 0) {
83 return $c; // empty dataobject.
88 if ($c->get($this->onid)) {
95 function lookup($obj, $person, $evtype='')
97 $x = DB_DataObject::Factory($this->tableName());
100 if (!empty($evtype)) {
101 $x->evtype = $evtype;
103 if ($x->count() != 1) {
112 function beforeDelete($dependants_array, $roo) {
113 if ($this->delivered()) {
114 $roo->jerr("you can not delete a record of a successfull delivery");
117 function beforeInsert($request,$roo)
119 if (empty($request['act_when']) && !empty($request['act_start'])) {
120 $this->act_start($request['act_start']);
124 function beforeUpdate($old, $request,$roo)
126 if (empty($request['act_when']) && !empty($request['act_start'])) {
127 $this->act_start($request['act_start']);
132 function act_start($set = false)
134 if ($set === false) {
135 return $this->act_start;
137 $this->act_when = $set;
138 $this->act_start = $set;
145 $c = DB_DataObject::factory('Events');
147 if ($c->get($this->event_id)) {
154 function triggerEvent()
157 $c = DB_DataObject::factory('Events');
159 if ($c->get($this->trigger_event_id)) {
168 return !empty($this->msgid);
171 function whereAddDeliveryStatus($delivered = false)
173 $tn = $this->tableName();
175 $this->whereAdd("$tn.msgid IS NOT NULL AND $tn.msgid != ''");
177 $this->whereAdd("$tn.msgid IS NULL OR $tn.msgid = ''");
181 function status() // used by commandline reporting at present..
183 switch($this->event_id) {
185 return 'DELIVERED'; //not valid..
190 if (strtotime($this->act_when) > time()) {
191 $p = "RETRY: {$this->act_when} ";
193 return $p. $this->event()->remarks;
198 * current state of process
209 if ($this->msgid != '') {
213 // msgid is empty now..
214 // if act_when is greater than now, then it's still pending.
215 if (strtotime($this->act_when) > time()) {
219 // event id can be filled in with a failed attempt.
221 if ($this->event_id > 0) {
225 // event id is empty, and act_when is in the past... not sent yet..
233 function applyFilters($q, $au, $roo)
235 if (isset($q['ontable']) && !in_array($q['ontable'], array('Person', 'Events', 'core_watch'))) {
236 // this will only work on tables not joined to ours.
238 //DB_DAtaObject::DebugLevel(1);
239 // then we can build a join..
240 $d = DB_DataObject::Factory($q['ontable']);
241 $ji = $d->autoJoin();
242 //echo '<PRE>';print_R($ji);
244 foreach($ji['join_names'] as $cname=>$fname) {
245 $this->selectAdd($fname . ' as ontable_id_' . $cname );
248 //$this->selectAdd($d->_query['data_select']); -- this will cause the same dataIndex...
250 LEFT JOIN {$d->tableName()} ON {$this->tableName()}.onid = {$d->tableName()}.id
253 $this->selectAs($d, 'core_notify_%s');
255 if (!empty($q['query']['person_id_name']) ) {
256 $this->whereAdd( "join_person_id_id.name LIKE '{$this->escape($q['query']['person_id_name'])}%'");
259 if (!empty($q['query']['status'])) {
260 switch ($q['query']['status']) {
263 $this->whereAdd("msgid != ''");
267 $this->whereAdd("msgid = '' AND event_id > 0 AND act_when < NOW()");
271 $this->whereAdd('event_id = 0 OR (event_id > 0 AND act_when > NOW() )');
275 $this->whereAdd('is_open > 0');
284 if(!empty($q['_evtype_align'])){
291 etype = 'Core.NotifyType'
293 name = core_notify.evtype
300 if(!empty($q['from'])){
302 act_when >= '{$q['from']}'
306 if(!empty($q['to'])){
308 act_when <= '{$q['to']}'