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
46 /* the code above is auto generated do not remove the tag below */
49 function person($set = false)
52 $this->person_id = is_object($set) ? $set->id : $set;
55 $c = DB_DataObject::Factory('Person');
56 $c->get($this->person_id);
60 function object($set = false)
63 $this->ontable = $set->tableName();
64 $this->onid = $set->id;
67 $c = DB_DataObject::factory($this->ontable);
69 if ($this->onid == 0) {
70 return $c; // empty dataobject.
75 if ($c->get($this->onid)) {
81 function beforeDelete($dependants_array, $roo) {
82 if ($this->delivered()) {
83 $roo->jerr("you can not delete a record of a successfull delivery");
86 function beforeInsert($request,$roo)
88 if (empty($request['act_when']) && !empty($request['act_start'])) {
89 $this->act_start($request['act_start']);
93 function beforeUpdate($old, $request,$roo)
95 if (empty($request['act_when']) && !empty($request['act_start'])) {
96 $this->act_start($request['act_start']);
101 function act_start($set = false)
103 if ($set === false) {
104 return $this->act_start;
106 $this->act_when = $set;
107 $this->act_start = $set;
114 $c = DB_DataObject::factory('Events');
116 if ($c->get($this->event_id)) {
123 function triggerEvent()
126 $c = DB_DataObject::factory('Events');
128 if ($c->get($this->trigger_event_id)) {
137 return !empty($this->msgid);
140 function whereAddDeliveryStatus($delivered = false)
142 $tn = $this->tableName();
144 $this->whereAdd("$tn.msgid IS NOT NULL AND $tn.msgid != ''");
146 $this->whereAdd("$tn.msgid IS NULL OR $tn.msgid = ''");
150 function status() // used by commandline reporting at present..
152 switch($this->event_id) {
154 return 'DELIVERED'; //not valid..
159 if (strtotime($this->act_when) > time()) {
160 $p = "RETRY: {$this->act_when} ";
162 return $p. $this->event()->remarks;
167 function applyFilters($q, $au, $roo)
169 if (isset($q['ontable']) && !in_array($q['ontable'], array('Person', 'Events', 'core_watch'))) {
170 // this will only work on tables not joined to ours.
172 //DB_DAtaObject::DebugLevel(1);
173 // then we can build a join..
174 $d = DB_DataObject::Factory($q['ontable']);
175 $ji = $d->autoJoin();
176 //echo '<PRE>';print_R($ji);
178 foreach($ji['join_names'] as $cname=>$fname) {
179 $this->selectAdd($fname . ' as ontable_id_' . $cname );
182 //$this->selectAdd($d->_query['data_select']); -- this will cause the same dataIndex...
184 LEFT JOIN {$d->tableName()} ON {$this->tableName()}.onid = {$d->tableName()}.id
187 $this->selectAs($d, 'core_notify_%s');
189 if (!empty($q['query']['person_id_name']) ) {
190 $this->whereAdd( "join_person_id_id.name LIKE '{$this->escape($q['query']['person_id_name'])}%'");
193 if (!empty($q['query']['status'])) {
194 switch ($q['query']['status']) {
197 $this->whereAdd("msgid != ''");
201 $this->whereAdd("msgid = '' AND event_id > 0 AND act_when < NOW()");
205 $this->whereAdd('event_id = 0 OR (event_id > 0 AND act_when > NOW() )');
209 $this->whereAdd('is_open > 0');
218 if(!empty($q['_evtype_align'])){
225 etype = 'Core.NotifyType'
227 name = core_notify.evtype
234 if(!empty($q['from'])){
236 act_when >= '{$q['from']}'
240 if(!empty($q['to'])){
242 act_when <= '{$q['to']}'