MTrackWeb/Log.php
[web.mtrack] / MTrackWeb / Log.php
1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3
4 require_once 'MTrackWeb.php';
5
6 class MTrackWeb_Log extends MTrackWeb
7 {
8     var $template = 'log.html';
9     function getAuth()
10     {
11         
12         parent::getAuth();
13        
14         return true;
15     }
16     
17     function get($pi)
18     {
19        // echo "STARGING";
20         if (!isset($_REQUEST['ajax_body'])) {
21             return;
22         }
23         $this->masterTemplate = 'log.html';
24          
25        
26         $this->pi = empty($pi) ? '' : ($pi . $this->bootLoader->ext);
27        
28         $this->repo = DB_DataObject::factory('mtrack_repos');
29         $this->filename = $this->repo->loadFromPath($this->pi);
30         
31        
32         if (!$this->repo->id) {
33             return HTML_FlexyFramework::run('Browse');  
34         };
35           
36         if (!$this->projectPerm($this->repo->project_id, 'MTrack.Repos', 'S')) {
37             return HTML_FlexyFramework::run('Noperm');  // noperm = loggedin -> need more perms / not.. try loggin in..
38         }
39         
40          
41         
42         $this->branches = $this->repo->getBranches();
43
44         
45         
46         $this->title = "Log $this->filename";
47         
48         $this->branches = $this->repo->getBranches();
49         
50         
51         $this->crumbs = array();
52         $location = '';
53         $crumbs = explode('/', $this->filename);
54         array_unshift($crumbs,'');
55         foreach($crumbs as $path) 
56         {
57             
58             $c = new StdClass;
59             $c->name = strlen($path) ? $path : '[root]';
60             $c->root = strlen($path) ? 0 : 1;
61             $location .=  strlen($location) ? '/' : '';
62             $location .=  strlen($path)  ?  urlencode($path)  : '';
63             $c->location = $location;
64             $this->crumbs[] = $c;
65         } 
66           
67         $branches = $this->repo->getBranches();
68         $tags = $this->repo->getTags();
69         if (count($branches) + count($tags)) {
70             $this->showJump = 1;
71             $jumps = array("" => "- Select Branch / Tag - ");
72             if (is_array($branches)) {
73                 foreach ($branches as $name => $notcare) {
74                     $jumps["branch:$name"] = "Branch: $name";
75                 }
76             }
77             if (is_array($tags)) {
78                 foreach ($tags as $name => $notcare) {
79                     $jumps["tag:$name"] = "Tag: $name";
80                 }
81             }
82             
83             $this->elements['jump'] = new HTML_Template_Flexy_Element('select');
84             $this->elements['jump']->setOptions($jumps);  
85             $this->elements['jump']->setValue(empty($_GET['jump']) ? '' : $_GET['jump']);
86         }
87         $object = null;
88         $ident = null;
89         if (!empty($_GET['jump'])) {
90             list($object, $ident) = explode(':', $_GET['jump'], 2);
91         }
92             
93             
94         $last_day = null;
95         $even = 1;
96         $hist = $this->repo->history($this->filename, 100, $object, $ident);
97          
98         if (empty($hist)) {
99             return;
100         }
101         
102         // code here...
103         // repo has a 'release' branch, this should be used to track what needs 
104         // merging from 'HEAD' to update it
105         // (basically how far behind is the release from head..)
106                 
107  //         $need_review = ' style="background-color:#fdd;"';
108  //         $good_to_go = ' style="background-color:#585;"';
109  //         $live = ' style="background-color:#336;"';
110   
111         //$is_live = false;
112         $this->hist= array();
113         foreach($hist as $i=>$h) {
114             $h->cls = $i % 2 ? 'odd' : '';
115         
116             $ts = strtotime($h->ctime);
117             $day = date('D, M d Y', $ts);
118             $time = date('g:ia', $ts);
119             //print_r($ent);
120             if ($day !== $last_day) {
121                 $this->hist[] = (object) array(
122                     'isday' => 1,
123                     'day' => $day
124                 );
125             }
126             $h->time = $time;
127                 
128             $last_day = $day;
129             $M = array();
130             if (preg_match('/#([0-9]+)\s+/', $h->changelog, $M)) {
131                 
132                 $h->ticket = MTrackIssue::loadByNSIdent($M[1]) ;
133                 // ticket->status == closed == ok to commit to another branch...
134                // echo '<PRE>'; print_r($h->ticket);
135             }
136             
137              
138        
139     
140             $this->hist[] = $h;
141         }
142     }
143         
144 }
145