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() : '';
56 $person_table = empty($this->person_table) ? 'Person' : $this->person_table;
57 $col = $person_table == "Person" ? 'person_id' : $person_table . '_id';
59 $this->{$col} = is_object($set) ? $set->id : $set;
62 static $cache =array();
63 $person_table = empty($this->person_table) ? 'Person' : $this->person_table;
64 $col = $person_table == "Person" ? 'person_id' : $person_table . '_id';
66 if (isset($cache[$person_table .':'. $this->{$col}])) {
67 return $cache[$person_table .':'. $this->{$col}];
70 $c = DB_DataObject::Factory($person_table);
71 $c->get($this->{$col});
72 $cache[$person_table .':'. $this->{$col}] = $c;
76 function object($set = false)
79 $this->ontable = $set->tableName();
80 $this->onid = $set->id;
83 $c = DB_DataObject::factory($this->ontable);
85 if ($this->onid == 0) {
86 return $c; // empty dataobject.
91 if ($c->get($this->onid)) {
98 function lookup($obj, $person, $evtype='')
100 $x = DB_DataObject::Factory($this->tableName());
103 if (!empty($evtype)) {
104 $x->evtype = $evtype;
106 if ($x->count() != 1) {
115 function beforeDelete($dependants_array, $roo) {
116 if ($this->delivered()) {
117 $roo->jerr("you can not delete a record of a successfull delivery");
120 function beforeInsert($request,$roo)
122 if (empty($request['act_when']) && !empty($request['act_start'])) {
123 $this->act_start($request['act_start']);
127 function beforeUpdate($old, $request,$roo)
129 if (empty($request['act_when']) && !empty($request['act_start'])) {
130 $this->act_start($request['act_start']);
135 function act_start($set = false)
137 if ($set === false) {
138 return $this->act_start;
140 $this->act_when = $set;
141 $this->act_start = $set;
148 $c = DB_DataObject::factory('Events');
150 if ($c->get($this->event_id)) {
157 function triggerEvent()
160 $c = DB_DataObject::factory('Events');
162 if ($c->get($this->trigger_event_id)) {
171 return !empty($this->msgid);
174 function whereAddDeliveryStatus($delivered = false)
176 $tn = $this->tableName();
178 $this->whereAdd("$tn.msgid IS NOT NULL AND $tn.msgid != ''");
180 $this->whereAdd("$tn.msgid IS NULL OR $tn.msgid = ''");
184 function status() // used by commandline reporting at present..
186 switch($this->event_id) {
188 return 'DELIVERED'; //not valid..
193 if (strtotime($this->act_when) > time()) {
194 $p = "RETRY: {$this->act_when} ";
196 return $p. $this->event()->remarks;
201 * current state of process
212 if ($this->msgid != '') {
216 // msgid is empty now..
217 // if act_when is greater than now, then it's still pending.
218 if (strtotime($this->act_when) > time()) {
222 // event id can be filled in with a failed attempt.
224 if ($this->event_id > 0) {
228 // event id is empty, and act_when is in the past... not sent yet..
236 function applyFilters($q, $au, $roo)
238 if (isset($q['ontable']) && !in_array($q['ontable'], array('Person', 'Events', 'core_watch'))) {
239 // this will only work on tables not joined to ours.
241 //DB_DAtaObject::DebugLevel(1);
242 // then we can build a join..
243 $d = DB_DataObject::Factory($q['ontable']);
244 $ji = $d->autoJoin();
245 //echo '<PRE>';print_R($ji);
247 foreach($ji['join_names'] as $cname=>$fname) {
248 $this->selectAdd($fname . ' as ontable_id_' . $cname );
251 //$this->selectAdd($d->_query['data_select']); -- this will cause the same dataIndex...
253 LEFT JOIN {$d->tableName()} ON {$this->tableName()}.onid = {$d->tableName()}.id
256 $this->selectAs($d, 'core_notify_%s');
258 if (!empty($q['query']['person_id_name']) ) {
259 $this->whereAdd( "join_person_id_id.name LIKE '{$this->escape($q['query']['person_id_name'])}%'");
262 if (!empty($q['query']['status'])) {
263 switch ($q['query']['status']) {
266 $this->whereAdd("msgid != ''");
270 $this->whereAdd("msgid = '' AND event_id > 0 AND act_when < NOW()");
274 $this->whereAdd('event_id = 0 OR (event_id > 0 AND act_when > NOW() )');
278 $this->whereAdd('is_open > 0');
287 if(!empty($q['_evtype_align'])){
294 etype = 'Core.NotifyType'
296 name = core_notify.evtype
303 if(!empty($q['from'])){
305 act_when >= '{$q['from']}'
309 if(!empty($q['to'])){
311 act_when <= '{$q['to']}'