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