示例#1
0
    /**
     * Init to show year
     */
    private function loadData()
    {
        $whereSport = Request::param('group') == 'sport' ? '' : '`sportid`=' . $this->Sport->id() . ' AND';
        $this->usesDistance = $this->Sport->usesDistance();
        if (Request::param('group') != 'sport' && $this->Analysis == self::ANALYSIS_DEFAULT && $this->usesDistance) {
            $num = DB::getInstance()->query('
				SELECT COUNT(*) FROM `' . PREFIX . 'training`
				WHERE
					' . $whereSport . '
					`distance` = 0 AND `s` > 0 AND
				' . $this->whereDate() . '
			')->fetchColumn();
            if ($num > 0) {
                $this->usesDistance = false;
            }
        }
        $this->RawData = DB::getInstance()->query('
			SELECT
				`sportid`,
				`typeid`,
				(`typeid` = ' . Configuration::General()->competitionType() . ') as `wk`,
				' . $this->dataSum() . ' as `sum`,
				' . $this->timer() . ' as `timer`
			FROM `' . PREFIX . 'training`
			WHERE
				' . $whereSport . '
				' . $this->whereDate() . '
			GROUP BY ' . $this->groupBy() . ', ' . $this->timer())->fetchAll();
    }
 /**
  * Display the analysis
  */
 private function displayAnalysis()
 {
     if (empty($this->AnalysisData)) {
         echo HTML::info(__('There is no data for this sport.'));
     }
     foreach ($this->AnalysisData as $i => $Data) {
         if (!is_array($Data)) {
             continue;
         }
         $this->printTableStart($Data['name']);
         if (empty($Data['foreach'])) {
             echo '<tr class="c">' . HTML::emptyTD($this->colspan, '<em>' . __('No data available.') . '</em>') . '</tr>';
         } else {
             foreach ($Data['foreach'] as $i => $Each) {
                 echo '<tr><td class="c b">' . $Each['name'] . '</td>';
                 for ($t = $this->timer_start; $t <= $this->timer_end; $t++) {
                     if (isset($Data['array'][$Each['id']][$t])) {
                         $num = $Data['array'][$Each['id']][$t]['num'];
                         $dist = $Data['array'][$Each['id']][$t]['distance'];
                         $time = $Data['array'][$Each['id']][$t]['s'];
                         if ($this->dat == 'km') {
                             $percent = $Data['array']['timer_sum_km'][$t] > 0 ? round(100 * $dist / $Data['array']['timer_sum_km'][$t], 1) : 0;
                         } else {
                             $percent = $Data['array']['timer_sum_s'][$t] > 0 ? round(100 * $time / $Data['array']['timer_sum_s'][$t], 1) : 0;
                         }
                         $this->displayTDfor($num, $time, $dist, $percent);
                     } else {
                         echo HTML::emptyTD();
                     }
                 }
                 if (isset($Data['array']['id_sum_s'][$Each['id']])) {
                     $num = $Data['array']['id_sum_num'][$Each['id']];
                     $time = $Data['array']['id_sum_s'][$Each['id']];
                     $dist = $Data['array']['id_sum_km'][$Each['id']];
                     if ($this->dat == 'km') {
                         $percent = $Data['array']['all_sum_km'] > 0 ? round(100 * $dist / $Data['array']['all_sum_km'], 1) : 0;
                     } else {
                         $percent = $Data['array']['all_sum_s'] > 0 ? round(100 * $time / $Data['array']['all_sum_s'], 1) : 0;
                     }
                     $this->displayTDfor($num, $time, $dist, $percent);
                 } else {
                     echo HTML::emptyTD();
                 }
                 echo '</tr>';
             }
             if ($i == count($Data['foreach']) - 1) {
                 echo '<tr class="top-spacer no-zebra"><td class="c b">' . __('Total') . '</td>';
                 for ($t = $this->timer_start; $t <= $this->timer_end; $t++) {
                     if (isset($Data['array']['timer_sum_km'][$t])) {
                         if ($this->Sport->usesDistance() && $this->dat != 's') {
                             echo '<td>' . Distance::format($Data['array']['timer_sum_km'][$t], false, 0) . '</td>';
                         } else {
                             echo '<td>' . Duration::format($Data['array']['timer_sum_s'][$t]) . '</td>';
                         }
                     } else {
                         echo HTML::emptyTD();
                     }
                 }
                 if ($this->Sport->usesDistance() && $this->dat != 's') {
                     echo '<td>' . Distance::format($Data['array']['all_sum_km'], false, 0) . '</td></tr>';
                 } else {
                     echo '<td>' . Duration::format($Data['array']['all_sum_s']) . '</td></tr>';
                 }
             }
         }
         $this->printTableEnd();
     }
 }