DataObjects/Core_watch.php
[Pman.Core] / DataObjects / Core_watch.php
1 <?php
2 /**
3  * Table Definition for core_watch
4  *
5  * works with 'core_notify'
6  *
7  * any object can call
8  *   $watch->notify($ontable, $onid)
9  *
10  *   in which case it should create a notify event.
11  *
12  *
13  * 
14  */
15 require_once 'DB/DataObject.php';
16
17 class Pman_Core_DataObjects_Core_watch extends DB_DataObject 
18 {
19     ###START_AUTOCODE
20     /* the code below is auto generated do not remove the above tag */
21
22     public $__table = 'core_watch';                      // table name
23     public $ontable;                         // string(128)  not_null primary_key
24     public $onid;                            // int(11)  not_null primary_key
25     public $person_id;                         // int(11)  not_null primary_key
26     public $event;                           // string(128)  not_null primary_key
27     public $medium;                          // string(128)  not_null primary_key
28     public $active;                          // int(11)  not_null
29
30     
31     /* the code above is auto generated do not remove the tag below */
32     ###END_AUTOCODE
33     
34     /***
35      * The purpose of this is to gather all the events that have
36      * occured in the system (where watches exist)
37      * Do we want to send the user 1 email ?? or multiple...
38      * --> I guess multiple emails..
39      *
40      * so we need to return
41      *
42      *  array(
43           $USER_ID => array(
44                 $OBJECT:$ID, $OBJECT:$ID, $OBJECT:$ID, .....
45           )
46      * )
47      *
48      * The mailer can then go through and call each object ??
49      *
50      *
51      * -- Things we can watch..
52      *
53      * mtrack_change <- this is a neat log of all events.
54      *  which logs these things
55      *     Individual Ticket changes (already)
56      *     a Project -> which means ticket changes... which again can be discovered via mtrack_changes..
57      *     a Repo for Commits (-- which will be handled by mtrack_changes)
58      *     Wiki changes.. later...
59      *     
60      *
61      *
62      */
63     
64     function watched($medium, $watcher = null)
65     {
66         $w = DB_DataObject::factory('core_watch');
67         if ($watcher) {
68             $w->person_id = $watcher;
69         }
70         $w->active = 1;
71         $w->medium = $medium;
72         $ar = $w->fetchAll();
73         $ret = array();
74         foreach($ar as $o) {
75             if (!isset($ret[$o->person_id])) {
76                 $ret[$o->person_id] = array();
77             }
78             $ret[$o->person_id][] = $o->ontable .':'. $o->onid;
79         }
80         
81         return $ret;
82     }
83 }