3 * Table Definition for core_watch
5 * works with 'core_notify'
8 * $watch->notify($ontable, $onid)
10 * in which case it should create a core_notify event.
13 * Should 'event' trigger this..
14 * -> eg. somebody makes a 'EDIT' on 'person'
15 * -> a watch exists for
17 * onid = -1 <<-- every entry..
18 * person_id -> who is goes to.
19 * event = CRUD (eg. shortcut for edit/create/delete)
20 * medium = "REVIEW" << eg. review needed..
26 require_once 'DB/DataObject.php';
28 class Pman_Core_DataObjects_Core_watch extends DB_DataObject
31 /* the code below is auto generated do not remove the above tag */
33 public $__table = 'core_watch'; // table name
34 public $id; // int(11) not_null primary_key auto_increment
35 public $ontable; // string(128) not_null
36 public $onid; // int(11) not_null
37 public $person_id; // int(11) not_null
38 public $event; // string(128) not_null
39 public $medium; // string(128) not_null
40 public $active; // int(11) not_null
43 /* the code above is auto generated do not remove the tag below */
45 /** make sure there is a watch for this user.. */
53 function ensureNotify( $ontable, $onid, $person_id, $whereAdd)
55 //DB_DAtaObject::debugLevel(1);
56 $w = DB_DataObject::factory('core_watch');
57 $w->person_id = $person_id;
58 if (empty($w->person_id)) {
63 $w->whereAdd($whereAdd);
69 $nw->ontable = $ontable;
72 $nw->medium = 'email';
78 function notify($ontable , $onid, $whereAdd)
80 $w = DB_DataObject::factory('core_watch');
81 $w->whereAdd($whereAdd);
83 $w->selectAdd('distinct(person_id) as person_id');
84 $people = $w->fetchAll('person_id');
86 $nn = DB_DataObject::Factory('core_notify');
87 $nn->ontable = $ontable;
89 foreach($people as $p) {
90 if (!$p) { // no people??? bugs in watch table
96 $nf->whereAdd('sent < act_when');
98 // we have a item in the queue for that waiting to be sent..
101 $n->act_start( date("Y-m-d H:i:s") );
109 function notifyEvent($event)
111 // see if there are any watches on events..
113 $w = DB_DataObject::factory('core_watch');
114 $w->ontable = $event->on_table;
115 $w->whereAdd('onid = 0 OR onid='. ((int) $event->on_id));
116 $w->event = $event->action;
119 $watches = $w->fetchAll();
121 $nn = DB_DataObject::Factory('core_notify');
122 $nn->ontable = $event->on_table;
123 $nn->onid = $event->on_id;
125 foreach($watches as $watch) {
126 if (!$watch->person_id) { // no people??? bugs in watch table
132 $n->watch_id = $watch->id;
135 $nf->whereAdd('sent < act_when');
137 // we have a item in the queue for that waiting to be sent..
141 $n->act_start( date("Y-m-d H:i:s") );