00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit();}
00002 # streber - a php based project management system
00003 # Copyright (c) 2005 Thomas Mann - thomas@pixtur.de
00004 # Distributed under the terms and conditions of the GPL as stated in docs/license.txt
00005
00016 class ListBlock_efforts extends ListBlock
00017 {
00018 public $bg_style = "bg_time";
00019 public $filters = array();
00020
00021 public function __construct($args=NULL)
00022 {
00023 parent::__construct($args);
00024
00025 global $PH;
00026 $this->id='efforts';
00027 $this->bg_style='bg_time';
00028 $this->no_items_html= __('no efforts booked yet');
00029 $this->title= __("Efforts");
00030
00031
00032 $this->add_col( new ListBlockColSelect());
00033 $this->add_col(new ListBlockColMethod(array(
00034 'key'=>'p.name',
00035 'name'=>__('Project'),
00036 'func'=>'getProjectLink'
00037 )));
00038 $this->add_col(new ListBlockColMethod(array(
00039 'key'=>'person',
00040 'name'=>__('person'),
00041 'func'=>'getPersonLink'
00042 )));
00043 $this->add_col( new ListBlockCol_EffortTask);
00044 $this->add_col( new ListBlockCol_EffortStatus);
00045 $this->add_col( new ListBlockCol_EffortName);
00046 $this->add_col( new ListBlockCol_EffortDate);
00047 $this->add_col( new ListBlockCol_EffortDateEnd);
00048 $this->add_col( new ListBlockCol_EffortAmount);
00049 $this->add_col( new ListBlockCol_DayGraph);
00050
00051 #---- functions ----
00052 $this->add_function(new ListFunction(array(
00053 'target'=>$PH->getPage('effortEdit')->id,
00054 'name' =>__('Edit effort'),
00055 'id' =>'effortEdit',
00056 'icon' =>'edit',
00057 'context_menu'=>'submit',
00058 )));
00059 $this->add_function(new ListFunction(array(
00060 'target'=>$PH->getPage('effortNew')->id,
00061 'name' =>__('New effort'),
00062 'id' =>'effortNew',
00063 'icon' =>'new',
00064 'context_menu'=>'submit',
00065 )));
00066 $this->add_function(new ListFunction(array(
00067 'target'=>$PH->getPage('effortsDelete')->id,
00068 'name' =>__('Delete'),
00069 'id' =>'effortsDelete',
00070 'icon' =>'delete',
00071 'context_menu'=>'submit',
00072 )));
00073
00074 $this->add_function(new ListFunction(array(
00075 'target'=>$PH->getPage('effortViewMultiple')->id,
00076 'name' =>__('View selected Efforts'),
00077 'id' =>'effortViewMultiple',
00078 'context_menu'=>'submit',
00079 )));
00080 $this->add_function(new ListFunction(array(
00081 'target'=>$PH->getPage('itemsAsBookmark')->id,
00082 'name' =>__('Mark as bookmark'),
00083 'id' =>'itemsAsBookmark',
00084 'context_menu'=>'submit',
00085 )));
00086
00087
00088 ### block style functions ###
00089 $this->add_blockFunction(new BlockFunction(array(
00090 'target'=>'changeBlockStyle',
00091 'key'=>'list',
00092 'default'=>true,
00093 'name'=>'List',
00094 'params'=>array(
00095 'style'=>'list',
00096 'block_id'=>$this->id,
00097 'page_id'=>$PH->cur_page->id,
00098 ),
00099
00100 )));
00101 $this->groupings= new BlockFunction_grouping(array(
00102 'target'=>'changeBlockStyle',
00103 'key'=>'grouped',
00104 'name'=>'Grouped',
00105 'params'=>array(
00106 'style'=>'grouped',
00107 'block_id'=>$this->id,
00108 'page_id'=>$PH->cur_page->id,
00109 ),
00110 ));
00111 $this->add_blockFunction($this->groupings);
00112
00113 ### list groupings ###
00114 $this->groupings->groupings= array(
00115 new ListGroupingEffortStatus(),
00116 new ListGroupingCreatedBy(),
00117 new ListGroupingTask(),
00118 );
00119
00120 }
00121
00122 public function print_automatic()
00123 {
00124 global $PH;
00125
00126 if(!$this->active_block_function=$this->getBlockStyleFromCookie()) {
00127 $this->active_block_function = 'list';
00128 }
00129
00130 $this->query_options['alive_only'] = false;
00131
00132 $this->group_by= get("blockstyle_{$PH->cur_page->id}_{$this->id}_grouping");
00133
00134 $s_cookie= "sort_{$PH->cur_page->id}_{$this->id}_{$this->active_block_function}";
00135 if($sort= get($s_cookie)) {
00136 $this->query_options['order_by']= $sort;
00137 }
00138 else {
00139 $this->query_options['order_by']= 'time_end DESC';
00140 }
00141
00142 ### add filter options ###
00143 foreach($this->filters as $f) {
00144 foreach($f->getQuerryAttributes() as $k=>$v) {
00145 $this->query_options[$k]= $v;
00146 }
00147 }
00148
00149 ### grouped view ###
00150 if($this->active_block_function == 'grouped') {
00151
00157 if(isset($this->columns[ $this->group_by ])) {
00158 unset($this->columns[$this->group_by]);
00159 }
00160
00161 ### prepend key to sorting ###
00162 if(isset($this->query_options['order_by'])) {
00163 $this->query_options['order_by'] = $this->groupings->getActiveFromCookie() . ",".$this->query_options['order_by'];
00164
00165 }
00166 else {
00167 $this->query_options['order_by'] = $this->groupings->getActiveFromCookie();
00168 }
00169 }
00170 ### list view ###
00171 else {
00172 $pass= true;
00173 }
00174
00175 $efforts = Effort::getAll($this->query_options);
00176
00177 $this->render_list(&$efforts);
00178 }
00179
00183 public function render_list(&$efforts=NULL)
00184 {
00185 switch($this->page->format){
00186 case FORMAT_CSV:
00187 $this->renderListCSV($efforts);
00188 break;
00189 default:
00190 $this->renderListHtml($efforts);
00191 break;
00192 }
00193
00194 }
00195
00196 function renderListHtml(&$efforts=NULL)
00197 {
00198 $this->render_header();
00199 if(!$efforts && $this->no_items_html) {
00200 $this->render_tfoot_empty();
00201 }
00202 else {
00203
00204 $this->render_thead();
00205
00206 $sum=0.0;
00207 $day_last=0;
00208
00209 ### grouping ###
00210 if($this->groupings && $this->active_block_function == 'grouped' && $this->groupings->active_grouping_obj) {
00211 $last_group= NULL;
00212 $gr= $this->groupings->active_grouping_key;
00213 foreach($efforts as $e) {
00214 if($last_group != $e->$gr) {
00215 echo '<tr class=group><td colspan='. count($this->columns) .'>'. $this->groupings->active_grouping_obj->render($e).'</td></tr>';
00216 $last_group = $e->$gr;
00217 }
00218 $sum +=(strToClientTime( $e->time_end) - strToClientTime( $e->time_start) )/60/60 * 1.0;
00219
00223 $day= gmdate('z',strToClientTime( $e->time_end ) )*1;
00224 if($day != $day_last) {
00225 $day_last= $day;
00226 $this->render_trow(&$e,'isNewDay');
00227 }
00228 else {
00229 $this->render_trow(&$e);
00230 }
00231 }
00232 }
00233 else {
00234 foreach($efforts as $e) {
00235 $sum +=(strToClientTime( $e->time_end) - strToClientTime( $e->time_start) )/60/60 * 1.0;
00236
00240 $day= gmdate('z',strToClientTime( $e->time_end ) )*1;
00241 if($day != $day_last) {
00242 $day_last= $day;
00243 $this->render_trow(&$e,'isNewDay');
00244 }
00245 else {
00246 $this->render_trow(&$e);
00247 }
00248 }
00249 }
00250
00251 $sum=round($sum,1);
00252 $this->summary= sprintf(__("%s effort(s) with %s hours"), count($efforts), $sum);
00253 $this->render_tfoot();
00254 }
00255 }
00256 }
00257
00258 class ListBlockCol_EffortName extends ListBlockCol
00259 {
00260 public $key='name';
00261
00262 public function __construct($args=NULL) {
00263 parent::__construct($args);
00264 $this->name= __('Effort');
00265 $this->width= '50%';
00266 $this->tooltip= __("Effort name. More Details as tooltips");
00267 $this->format= '{?name}';
00268 }
00269 function render_tr(&$obj, $style="")
00270 {
00271 global $PH;
00272 $str="";
00273
00274 if(isset($obj->name)) {
00275 if($effort= Effort::getById($obj->id)) {
00276 $str= $PH->getLink('effortView', $effort->name, array('effort'=>$effort->id));
00277 }
00278 }
00279
00280 print "<td><b>$str</b></td>";
00281 }
00282 }
00283
00284 class ListBlockCol_EffortTask extends ListBlockCol
00285 {
00286 public $key='task';
00287
00288 public function __construct($args=NULL) {
00289 parent::__construct($args);
00290 $this->name= __('Task','column header');
00291 }
00292 function render_tr(&$obj, $style="")
00293 {
00294 global $PH;
00295 $str="";
00296
00297 if(isset($obj->task)) {
00298 if($task= Task::getById($obj->task)) {
00299 $str= $PH->getLink('taskView',$task->getShort(),array('tsk'=>$task->id));
00300 }
00301 }
00302 print "<td><nobr>$str</nobr></td>";
00303
00304 }
00305 }
00306
00307 class ListBlockCol_EffortStatus extends ListBlockCol
00308 {
00309 public $key = 'status';
00310
00311 public function __construct($args=NULL) {
00312 parent::__construct($args);
00313 $this->name = __('Status','column header');
00314 }
00315 function render_tr(&$obj, $style="")
00316 {
00317 global $PH;
00318 global $g_effort_status_names;
00319 $str = "";
00320
00321 if(isset($obj->status)) {
00322 $str = $g_effort_status_names[$obj->status];
00323 }
00324 print "<td><nobr>$str</nobr></td>";
00325
00326 }
00327 }
00328
00329 class ListBlockCol_EffortDate extends ListBlockCol
00330 {
00331 public $key='time_start';
00332
00333
00334 public function __construct($args=NULL)
00335 {
00336 parent::__construct($args);
00337 $this->name= __('Start','column header');
00338 }
00339
00340
00341 function render_tr(&$obj, $style="")
00342 {
00343 if(!isset($obj) || !$obj instanceof Effort) {
00344 trigger_error("ListBlock->render_tr() called without valid object", E_USER_WARNING);
00345 return;
00346 }
00347
00348 #$value= date(__("D, d.m.Y"), strToGMTime($obj->time_start) );
00349 $value= renderDateHtml($obj->time_start);
00350
00351 if($obj->as_duration) {
00352 $value.=" ".renderTime($obj->time_start) ;
00353 }
00354 print "<td><nobr>$value</nobr></td>"; #@@@ note: nobr is a hack for firefox 1.0
00355 }
00356 }
00357
00358 class ListBlockCol_EffortDateEnd extends ListBlockCol{
00359 public $key='time_end';
00360
00361 public function __construct($args=NULL)
00362 {
00363 parent::__construct($args);
00364 $this->name= __('End','column header');
00365 }
00366
00367 function render_tr(&$obj, $style="")
00368 {
00369 if(!isset($obj) || !$obj instanceof Effort) {
00370 trigger_error("ListBlock->render_tr() called without valid object", E_USER_WARNING);
00371 return;
00372 }
00373 if($obj->as_duration) {
00374 $value="";
00375 }
00376 else {
00377 $value= renderTime($obj->time_end);
00378 }
00379 print "<td>$value</td>";
00380 }
00381 }
00382
00383 class ListBlockCol_EffortAmount extends ListBlockCol
00384 {
00385
00386 public function __construct($args=NULL) {
00387 parent::__construct($args);
00388 $this->name=__('len','column header of length of effort');
00389 }
00390 function render_tr(&$obj, $style="") {
00391 if(!isset($obj) || !$obj instanceof Effort) {
00392 trigger_error("ListBlock->render_tr() called without valid object", E_USER_WARNING);
00393 return;
00394 }
00395 $value=round((strToGMTime($obj->time_end) - strToGMTime($obj->time_start))/60/60,1)."h";
00396 print "<td>$value</td>";
00397 }
00398 }
00399
00400 class ListBlockCol_DayGraph extends ListBlockCol
00401 {
00402
00403 public function __construct($args=NULL) {
00404 parent::__construct($args);
00405 $this->name= __('Daygraph','columnheader');
00406 }
00407 function render_tr(&$obj, $style="") {
00408 if(!isset($obj) || !$obj instanceof Effort) {
00409 trigger_error("ListBlock->render_tr() called without valid object", E_USER_WARNING);
00410 return;
00411 }
00412 if($obj->as_duration) {
00413 echo "<td>-</td>";
00414 }
00415 else {
00416 $tmp=mysqlDatetime2utc($obj->time_start);
00417 $day_time_start= confGet('DAYGRAPH_START_HOUR')*60*60;
00418 $day_time_end= confGet('DAYGRAPH_END_HOUR')*60*60;
00419
00420 $stretch= confGet('DAYGRAPH_WIDTH')/ ($day_time_end - $day_time_start);
00421
00422 $time_start= round((($tmp['hour']*60*60+$tmp['min']*60+ $tmp['sec']) - $day_time_start)* $stretch,0);
00423 if($time_start<0) {
00424 $time_start=0;
00425 }
00426
00427
00428 $tmp=mysqlDatetime2utc($obj->time_end);
00429 $time_end= round((($tmp['hour']*60*60+$tmp['min']*60+ $tmp['sec']) - $day_time_start)*$stretch,0);
00430 if($time_end< $time_start) {
00431 $time_end=0;
00432 }
00433 $time_len= $time_end - $time_start;
00434
00435 echo "<td>";
00436 echo "<nobr>";
00437 echo "<img src='".getThemeFile("img/pixel.gif") . "' style='width:{$time_start}px;height:3px;'>";
00438 echo "<img src='".getThemeFile("img/pixel.gif") . "' style='width:{$time_len}px;height:12px;background-color:#f00;'>";
00439 echo "</nobr>";
00440 echo "</td>";
00441 }
00442 }
00443 }
00444
00445
00446 ?>