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 * Generate a notify event based on watches (matching whereAdd)
80 * Usage: $core_watch->notify('mtrack_repos', 1, false, date()
82 * This can match any 'event' type - eg. it can be blank etc...
83 * Generally used by non-event driven notifications, like our
84 * Daily commit message.
86 * @param string $ontable - the database table that has been updated/changed etc.
87 * @param int $onid - the id of the row changed
88 * @param string $whereAdd (optiona) - a DB whereAdd() condition to filter the search for watches
89 * @param datetime $when (default now) - date/time to create the notification for (Eg. end of day..)
92 function notify($ontable , $onid, $whereAdd = false, $when=false)
94 $w = DB_DataObject::factory('core_watch');
95 if ($whereAdd !== false) {
96 $w->whereAdd($whereAdd );
100 $w->whereAdd('onid = 0 OR onid='. ((int) $onid));
103 $w->ontable = $ontable;
105 //$w->selectAdd('distinct(person_id) as person_id');
107 foreach($w->fetchAll() as $w) {
108 if (!$w->person_id) { // no people??? bugs in watch table
114 $nn = DB_DataObject::Factory('core_notify');
115 $nn->ontable = $ontable;
117 $nn->evtype = $w->medium;
118 $nn->person_id = $w->person_id;
121 $nf->whereAdd("sent < '2000-01-01'");
123 // we have a item in the queue for that waiting to be sent..
126 $nn->act_start( date("Y-m-d H:i:s", $when !== false ? strtotime($when) : time()) );
134 * This get's called by roo->jok()
137 * it's basic usage is to fill in core_notify after an event has happend.
139 * We can also use it to notify other modules if something has happend.
140 * = eg. mtrack_ticket * watch will notify mtrack_jira::
143 * public $ontable; // string(128) not_null
144 public $onid; // int(11) not_null
145 public $person_id; // int(11) not_null
146 public $event; // string(128) not_null
147 public $medium; // string(128) not_null
148 public $active; // int(11) not_null
152 function notifyEvent($event)
154 //DB_DataObject::DebugLevel(1);
155 // see if there are any watches on events..
156 // notify everyone flagged except the person doing it...
157 // this is very basic logic... -
158 // if more intelligence is needed...
159 // then it 'rules' will have to be added by the watched object....
160 // anyway leave that for another day..
161 if (empty($event->action)) {
164 $w = DB_DataObject::factory('core_watch');
165 $w->ontable = $event->on_table;
166 $w->whereAdd('onid = 0 OR onid='. ((int) $event->on_id));
168 $w->event = $event->action;
172 $w->whereAdd('person_id != '. (int) $event->person_id);
174 $watches = $w->fetchAll();
176 //print_R($watches);exit;
178 $nn = DB_DataObject::Factory('core_notify');
179 $nn->ontable = $event->on_table;
180 $nn->onid = $event->on_id;
182 foreach($watches as $watch) {
183 if (!$watch->person_id) { // no people??? bugs in watch table
184 $dom = explode(':',$watch->medium);
185 if (count($dom) != 2) {
188 $do = DB_DataObject::factory($dom[0]);
189 if (!method_exists($do,$dom[1])) {
192 $do->{$dom[1]}($event);
198 $n->trigger_person_id = $event->person_id;
199 $n->trigger_event_id = $event->id;
200 $n->person_id = $watch->person_id;
201 $n->watch_id = $watch->id;
203 // does this watch already have a flag...
205 $nf->whereAdd("sent ><'2000-01-01'");
206 //$nf->whereAdd('sent < act_when');
208 // we have a item in the queue for that waiting to be sent..
212 $n->act_start( date("Y-m-d H:i:s") );