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