MTrackWeb/Timeline.php
[web.mtrack] / MTrackWeb / Timeline.php
1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3
4
5
6
7 require_once 'MTrack/Attachment.php';
8 require_once 'MTrackWeb.php';
9
10 class MTrackWeb_Timeline extends MTrackWeb
11 {
12         
13     
14     var $title = 'Timeline';
15     
16      var $start_time = '-2 weeks';
17     var $limit = 250;
18     // fixme = this should be alot more efficient...
19     
20      
21     
22     
23     function get($only_users)
24     {
25         
26         
27         if (!isset($_REQUEST['ajax_body'])) {
28             return;
29         }
30         
31         
32         $this->masterTemplate = 'timeline.html';
33         // perms... 
34         $pid = $this->currentProject();
35          //DB_DataObject::debugLevel(1);
36         $isSummary = false;
37         
38         
39         $e = DB_DataObject::factory('mtrack_change');
40         $e->orderBy('changedate DESC');
41         
42         $start = empty($_REQUEST['from_date']) ? date('Y-m-01') : 
43             date('Y-m-01', strtotime($_REQUEST['from_date']));
44             
45         if (!empty($_REQUEST['viewtype']) && $_REQUEST['viewtype'] = 'summary') {
46              //DB_DataObject::debugLevel(1);
47             $isSummary = true;
48             $e->whereAdd("changedate >= '$start 00:00:00' AND changedate < '$start 00:00:00' + INTERVAL 1 MONTH");
49             $e->selectAdd();
50             $e->joinAdd(DB_DataObject::factory('Person'), 'LEFT');
51             $e->selectAdd("
52                      DATE_FORMAT(changedate, '%Y-%m-%d')  as changeday,
53                      CONCAT(DATE_FORMAT(changedate, '%Y-%m-%d-') ,Person.id)  as id,
54                      Person.name as name,
55                      COUNT(id) as nchanges
56                     ");
57             $e->groupBy("changeday,id,name");
58             $e->orderBy('changeday desc, name asc');
59             $ret = array();
60             $e->find();
61             while($e->fetch()) {
62                 $ret[] = $e->toArray();
63             }
64             $this->jdata($ret);
65             
66             
67         } else {
68             $e->whereAdd("changedate >= '$start 00:00:00' AND changedate < '$start 00:00:00' + INTERVAL 3 DAY");
69         }
70         
71         
72         $e->whereAdd("
73             ( ontable='mtrack_ticket' AND
74                 onid IN (SELECT id FROM mtrack_ticket where project_id = $pid)
75             )
76             OR
77             ( ontable='mtrack_repos' AND
78                 onid IN (SELECT id FROM mtrack_repos where project_id = $pid)
79             )
80         ");
81         
82         
83         
84         
85         
86         $ar = $e->fetchAll();
87         $this->events = array();
88         //$this->hist= array();
89         $last_day  =false;
90         foreach($ar as $i=>$h) {
91             $h->cls = $i % 2 ? 'odd' : '';
92         
93             $ts = strtotime($h->changedate);
94             $day = date('D, M d Y', $ts);
95             $time = date('g:ia', $ts);
96             //print_r($ent);
97             
98             $add = $h->toArray();
99             
100             if ($day !== $last_day) {
101                 $add['first_of_day'] = 1;
102             }
103             $last_day = $day;
104             $p = $h->person();
105             $add['person_id_name'] = $p->name;
106             $add['person_id_email'] = $p->email;
107             $add['audit'] = $h->cachedAuditToString();
108             $add['audit_ar'] = $h->cachedAuditToJSONArray();
109             // add the underlying object..
110             $add = array_merge($add, $h->objectCached()->toArray('object_%s'));
111             
112             
113             
114             
115             
116             
117     
118             $this->events[] = $add;
119              
120         }
121        
122         $this->jdata($this->events);
123     
124          
125          
126     
127     }
128      
129
130 }
131