Ejemplo n.º 1
0
 /**
  * Check preparation
  * @throws Exception
  */
 private function checkPreparation()
 {
     if ($this->Timerange == 0 || $this->TimeStart == 0 && $this->TimeEnd == 0) {
         throw new Exception('Timerange, -start and -end have to be properly defined.');
     }
     if ($this->CompareKilometers) {
         $this->Dataset->activateKilometerComparison();
     }
 }
 /**
  * Display table with last week-statistics 
  * @param bool $showAllWeeks
  */
 private function displayWeekTable($showAllWeeks = false)
 {
     if (($this->showsAllYears() || $this->showsSpecificYear() && $this->year != date('Y')) && !$showAllWeeks) {
         return;
     }
     $Dataset = new Dataset();
     if ($this->Configuration()->value('compare_weeks')) {
         $Dataset->activateKilometerComparison();
     }
     $title = $showAllWeeks ? __('All training weeks') : __('Last 10 training weeks');
     echo '<table class="r fullwidth zebra-style">';
     echo '<thead><tr><th colspan="' . ($Dataset->cols() + 1) . '">' . $title . '</th></tr></thead>';
     echo '<tbody>';
     if (!$showAllWeeks) {
         $starttime = time();
         $maxW = 9;
     } else {
         $starttime = $this->year == date("Y") ? time() : mktime(1, 0, 0, 12, 31, $this->year);
         $maxW = ($starttime - mktime(1, 0, 0, 12, 31, $this->year - 1)) / (7 * DAY_IN_S);
     }
     $CompleteData = array();
     $CurrentWeekEnd = Time::Weekend($starttime);
     $CompleteResult = $Dataset->getGroupOfTrainingsForTimerange($this->sportid, 7 * DAY_IN_S, $CurrentWeekEnd - ($maxW + 2) * 7 * DAY_IN_S, $CurrentWeekEnd);
     foreach ($CompleteResult as $Data) {
         $CompleteData[$Data['timerange']] = $Data;
     }
     for ($w = 0; $w <= $maxW; $w++) {
         $time = $starttime - $w * 7 * DAY_IN_S;
         $start = Time::Weekstart($time);
         $end = Time::Weekend($time);
         $week = Icon::$CALENDAR . ' ' . __('Week') . ' ' . date('W', $time);
         //echo '<tr><td class="b l"">'.DataBrowserLinker::link($week, $start, $end).'</td>';
         echo '<tr><td class="l"><span class="b">' . DataBrowserLinker::link($week, $start, $end, '') . '</span>&nbsp;&nbsp;&nbsp;<span class="small">' . date('d.m', $start) . " - " . date('d.m', $end) . '</span></td>';
         if (isset($CompleteData[$w]) && !empty($CompleteData[$w])) {
             $Dataset->setGroupOfTrainings($CompleteData[$w]);
             if (isset($CompleteData[$w + 1])) {
                 $Dataset->setKilometerToCompareTo($CompleteData[$w + 1]['distance']);
             }
             $Dataset->displayTableColumns();
         } else {
             echo HTML::emptyTD($Dataset->cols(), '<em>' . __('No activities') . '</em>', 'c small');
         }
         echo '</tr>';
     }
     echo '</tbody>';
     echo '</table>';
 }