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                 $isSummary = true;
47         }
48         $e->whereAdd("changedate >= '$start 00:00:00' AND changedate < '$start 00:00:00' + INTERVAL 1 MONTH");
49         
50         $e->whereAdd("
51             ( ontable='mtrack_ticket' AND
52                 onid IN (SELECT id FROM mtrack_ticket where project_id = $pid)
53             )
54             OR
55             ( ontable='mtrack_repos' AND
56                 onid IN (SELECT id FROM mtrack_repos where project_id = $pid)
57             )
58         ");
59         $ar = $e->fetchAll();
60         $this->events = array();
61         //$this->hist= array();
62         $last_day  =false;
63         foreach($ar as $i=>$h) {
64             $h->cls = $i % 2 ? 'odd' : '';
65         
66             $ts = strtotime($h->changedate);
67             $day = date('D, M d Y', $ts);
68             $time = date('g:ia', $ts);
69             //print_r($ent);
70             if ($day !== $last_day) {
71                 $this->events[] = (object) array(
72                     'isday' => 1,
73                     'day' => $day
74                 );
75             }
76             $h->time = $time;
77                 
78             $last_day = $day;
79             $M = array();
80            
81              
82             $h->object = $h->objectCached();
83     
84             $this->events[] = empty($_REQUEST['json']) ?  $h : $h->toArray();
85             
86           
87             
88         }
89         if (!empty($_REQUEST['json'])) {
90              $this->jdata($this->events);
91          }
92          
93          
94     
95     }
96      
97
98 }
99