Merge branch 'master' of http://git.roojs.com:8081/web.mtrack
[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
46         $e->whereAdd("
47             ( ontable='mtrack_ticket' AND
48                 onid IN (SELECT id FROM mtrack_ticket where project_id = $pid)
49             )
50             OR
51             ( ontable='mtrack_repos' AND
52                 onid IN (SELECT id FROM mtrack_repos where project_id = $pid)
53             )
54         ");
55             
56         if (!empty($_REQUEST['viewtype']) && $_REQUEST['viewtype'] == 'summary') {
57             //DB_DataObject::debugLevel(1);
58             $isSummary = true;
59             $e->whereAdd("changedate >= '$start 00:00:00' AND changedate < '$start 00:00:00' + INTERVAL 1 MONTH");
60             $e->selectAdd();
61             $e->joinAdd(DB_DataObject::factory('Person'), 'LEFT');
62             $e->selectAdd("
63                      DATE_FORMAT(changedate, '%Y-%m-%d')  as changeday,
64                      CONCAT(DATE_FORMAT(changedate, '%Y-%m-%d-') ,Person.id)  as id,
65                      Person.name as name,
66                      COUNT(mtrack_change.id) as nchanges
67                     ");
68             $e->groupBy("changeday,id,name");
69             $e->orderBy('changeday desc, name asc');
70             $ret = array();
71             $e->find();
72             while($e->fetch()) {
73                 $ret[] = $e->toArray();
74             }
75             $this->jdata($ret);
76             
77             
78         } else {
79             $e->whereAdd("changedate >= '$start 00:00:00' AND changedate < '$start 00:00:00' + INTERVAL 3 DAY");
80         }
81         
82         
83        
84         
85         
86         
87         
88         
89         $ar = $e->fetchAll();
90         $this->events = array();
91         //$this->hist= array();
92         $last_day  =false;
93         foreach($ar as $i=>$h) {
94             $h->cls = $i % 2 ? 'odd' : '';
95         
96             $ts = strtotime($h->changedate);
97             $day = date('D, M d Y', $ts);
98             $time = date('g:ia', $ts);
99             //print_r($ent);
100             
101             $add = $h->toArray();
102             
103             if ($day !== $last_day) {
104                 $add['first_of_day'] = 1;
105             }
106             $last_day = $day;
107             $p = $h->person();
108             $add['person_id_name'] = $p->name;
109             $add['person_id_email'] = $p->email;
110             $add['audit'] = $h->cachedAuditToString();
111             $add['audit_ar'] = $h->cachedAuditToJSONArray();
112             // add the underlying object..
113             $add = array_merge($add, $h->objectCached()->toArray('object_%s'));
114             
115             
116             
117             
118             
119             
120     
121             $this->events[] = $add;
122              
123         }
124        
125         $this->jdata($this->events);
126     
127          
128          
129     
130     }
131      
132
133 }
134