Esempio n. 1
0
 /**
  * Constructor
  * @param int $id
  */
 public function __construct($id = false)
 {
     if ($id === false) {
         $id = Configuration::General()->mainSport();
     }
     $this->id = $id;
     $this->data = SportFactory::DataFor($id);
 }
Esempio n. 2
0
 /**
  * Initialize internal sports-array from database
  */
 private static function initAllSports()
 {
     self::$AllSports = array();
     $sports = self::cacheAllSports();
     foreach ($sports as $sport) {
         self::$AllSports[(string) $sport['id']] = $sport;
     }
     Configuration::ActivityForm()->orderSports()->sort(self::$AllSports);
 }
 /**
  * Init some class variables
  */
 private function initVariables()
 {
     $this->Sport = SportFactory::DataFor($this->sportid);
     $this->DatasetConfig = new \Runalyze\Dataset\Configuration(DB::getInstance(), SessionAccountHandler::getId());
     require_once 'class.SummaryTable.php';
     require_once 'class.SummaryTable10Weeks.php';
     require_once 'class.SummaryTableAllWeeks.php';
     require_once 'class.SummaryTableAllYears.php';
     require_once 'class.SummaryTableMonths.php';
 }
 /**
  * Init some class variables
  */
 private function initVariables()
 {
     $this->Sport = SportFactory::DataFor($this->sportid);
     $this->Dataset = new Dataset(SessionAccountHandler::getId());
     require_once 'class.SummaryTable.php';
     require_once 'class.SummaryTable10Weeks.php';
     require_once 'class.SummaryTableAllWeeks.php';
     require_once 'class.SummaryTableAllYears.php';
     require_once 'class.SummaryTableMonths.php';
 }
Esempio n. 5
0
 /**
  * Set default values
  */
 protected function setDefaultValues()
 {
     if (!isset($_POST['sportid'])) {
         $_POST['sportid'] = array_keys(SportFactory::AllSports());
     }
     if (!isset($_POST['date-from'])) {
         $_POST['date-from'] = date('d.m.Y', START_TIME);
     }
     if (!isset($_POST['date-to'])) {
         $_POST['date-to'] = date('d.m.Y');
     }
 }
Esempio n. 6
0
 /**
  * Get the sport-specific icon
  * @param int $id
  * @param string $title
  */
 public static function getSportIcon($id, $title = '', $tooltip = '')
 {
     $data = SportFactory::DataFor($id);
     if ($data === false) {
         return '';
     }
     if ($title == '') {
         $title = $data['name'];
     }
     if ($tooltip == '') {
         $tooltip = $title;
     }
     return Ajax::tooltip('<i class="' . $data['img'] . '"></i>', $tooltip);
 }
Esempio n. 7
0
 protected function setUp()
 {
     \Cache::clean();
     $this->PDO = \DB::getInstance();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'sport` (`name`,`kcal`,`outside`,`accountid`,`power`) VALUES("",600,1,0,1)');
     $this->OutdoorID = $this->PDO->lastInsertId();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'sport` (`name`,`kcal`,`outside`,`accountid`,`power`) VALUES("",400,0,0,0)');
     $this->IndoorID = $this->PDO->lastInsertId();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'shoe` (`name`,`km`,`time`,`accountid`) VALUES("",10,3000,0)');
     $this->ShoeID1 = $this->PDO->lastInsertId();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'shoe` (`name`,`km`,`time`,`accountid`) VALUES("",0,0,0)');
     $this->ShoeID2 = $this->PDO->lastInsertId();
     \SportFactory::reInitAllSports();
     \ShoeFactory::reInitAllShoes();
 }
Esempio n. 8
0
 protected function setUp()
 {
     \Cache::clean();
     $this->PDO = \DB::getInstance();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'sport` (`name`,`kcal`,`outside`,`accountid`,`power`,`HFavg`) VALUES("",600,1,0,1,160)');
     $this->OutdoorID = $this->PDO->lastInsertId();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'sport` (`name`,`kcal`,`outside`,`accountid`,`power`,`HFavg`) VALUES("",400,0,0,0,100)');
     $this->IndoorID = $this->PDO->lastInsertId();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'equipment_type` (`name`,`accountid`) VALUES("Type",0)');
     $this->EquipmentType = $this->PDO->lastInsertId();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'equipment_sport` (`sportid`,`equipment_typeid`) VALUES(' . $this->OutdoorID . ',' . $this->EquipmentType . ')');
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'equipment` (`name`,`typeid`,`notes`,`accountid`) VALUES("A",' . $this->EquipmentType . ',"",0)');
     $this->EquipmentA = $this->PDO->lastInsertId();
     $this->PDO->exec('INSERT INTO `' . PREFIX . 'equipment` (`name`,`typeid`,`notes`,`accountid`) VALUES("B",' . $this->EquipmentType . ',"",0)');
     $this->EquipmentB = $this->PDO->lastInsertId();
     $Factory = new Model\Factory(0);
     $Factory->clearCache('sport');
     \SportFactory::reInitAllSports();
 }
 /**
  * Construct new input field for: sportid
  * @param string $name
  * @param string $label
  * @param string $value optional, default: loading from $_POST
  */
 public function __construct($name, $label, $value = '')
 {
     parent::__construct($name, $label, $value);
     foreach (SportFactory::AllSports() as $id => $sport) {
         $attributes = array();
         $attributes['data-kcal'] = $sport['kcal'];
         if ($sport['id'] == Configuration::General()->runningSport()) {
             $attributes['data-running'] = 'true';
         }
         if ($sport['outside'] == 1) {
             $attributes['data-outside'] = 'true';
         }
         if ($sport['distances'] == 1) {
             $attributes['data-distances'] = 'true';
         }
         if ($sport['power'] == 1) {
             $attributes['data-power'] = 'true';
         }
         $this->addOption($id, $sport['name'], $attributes);
     }
 }
    /**
     * Get fieldset for paces
     * @return \FormularFieldset
     */
    public function getFieldsetPaces()
    {
        $Table = '<table class="fullwidth zebra-style">
				<thead>
					<tr>
						<th>' . __('Name') . '</th>
						<th class="small">' . __('Pace') . '</th>
						<th class="small">' . __('Description') . '</th>
					</tr>
				</thead>
				<tbody>';
        $VDOT = new VDOT(Configuration::Data()->vdot());
        $PaceObject = new Runalyze\Activity\Pace(0, 1, SportFactory::getSpeedUnitFor(Configuration::General()->runningSport()));
        foreach ($this->getArrayForPaces() as $Pace) {
            $Table .= '<tr>
						<td class="b">' . $Pace['short'] . '</td>
						<td class=""><em>' . $PaceObject->setTime($VDOT->paceAt($Pace['limit-high'] / 100))->value() . '</em> - <em>' . $PaceObject->setTime($VDOT->paceAt($Pace['limit-low'] / 100))->value() . '</em>' . $PaceObject->appendix() . '</td>
						<td class="">' . $Pace['description'] . '</td>
					</tr>';
        }
        $Table .= '
				</tbody>
			</table>';
        $Fieldset = new FormularFieldset(__('Training paces'));
        $Fieldset->addBlock($Table);
        $Fieldset->addInfo(__('These paces are based on Jack Daniels\' recommendation.'));
        return $Fieldset;
    }
Esempio n. 11
0
 /**
  * Get links for all sports
  * @return array
  */
 private function getSportLinksAsList()
 {
     $Links = '';
     if ($this->ShowAllSportsLink) {
         $Links .= '<li' . (-1 == $this->sportid ? ' class="active"' : '') . '>' . $this->getInnerLink(__('All'), -1, $this->year, $this->dat) . '</li>';
     }
     $Sports = SportFactory::NamesAsArray();
     foreach ($Sports as $id => $name) {
         $Links .= '<li' . ($id == $this->sportid ? ' class="active"' : '') . '>' . $this->getInnerLink($name, $id, $this->year, $this->dat) . '</li>';
     }
     return $Links;
 }
    /**
     * Get array for "Tempobereiche"
     */
    private function getPaceArray()
    {
        $speed_min = $this->Configuration()->value('lowest_pacegroup');
        $speed_max = $this->Configuration()->value('highest_pacegroup');
        $speed_step = $this->Configuration()->value('pacegroup_step');
        $ceil_corr = $speed_min % $speed_step;
        if ($this->sportid != Configuration::General()->runningSport()) {
            $MinMax = DB::getInstance()->query('
				SELECT
					MIN(`s`/`distance`) as `min`,
					MAX(`s`/`distance`) as `max`
				FROM `' . PREFIX . 'training`
				WHERE `sportid`=' . $this->sportid . ' AND ' . PREFIX . 'training.accountid="' . SessionAccountHandler::getId() . '" ' . $this->where_time . ' AND `distance`>0
			')->fetch();
            if (!empty($MinMax)) {
                $speed_min = round((double) $MinMax['max']);
                $speed_max = round((double) $MinMax['min']);
                $speed_step = $speed_min == $speed_max ? 1 : round(($speed_min - $speed_max) / 10);
                $ceil_corr = $speed_min == $speed_max ? 1 : $speed_min % $speed_step;
            }
        }
        $result = DB::getInstance()->query('
			SELECT ' . $this->getTimerIndexForQuery() . ' AS `timer`,
				COUNT(*) AS `num`,
				SUM(`distance`) AS `distance`,
				SUM(`s`) AS `s`,
				FLOOR( (`s`/`distance` - ' . $ceil_corr . ')/' . $speed_step . ')*' . $speed_step . ' + ' . $ceil_corr . ' AS `group`
			FROM `' . PREFIX . 'training`
			WHERE `sportid`=' . $this->sportid . ' AND ' . PREFIX . 'training.accountid="' . SessionAccountHandler::getId() . '" ' . $this->where_time . ' AND `distance`>0
			GROUP BY `group`, ' . $this->group_time . '
			ORDER BY `group` DESC, ' . $this->getTimerForOrderingInQuery() . ' ASC
		')->fetchAll();
        $speed_data = $this->emptyData;
        foreach ($result as $dat) {
            if ($this->sportid == Configuration::General()->runningSport()) {
                if ($dat['group'] > $speed_min) {
                    $dat['group'] = $speed_min;
                } else {
                    if ($dat['group'] < $speed_max) {
                        $dat['group'] = $speed_max;
                    }
                }
            }
            $this->setGroupData($speed_data, $dat);
            $this->setSumData($speed_data, $dat);
        }
        $speed_foreach = array();
        if (!empty($result)) {
            $Pace = new Pace(0, 1, SportFactory::getSpeedUnitFor($this->sportid));
            for ($speed = $speed_min; $speed > $speed_max - $speed_step; $speed -= $speed_step) {
                if ($speed <= $speed_max) {
                    $name = '<small>' . __('faster than') . '</small>&nbsp;' . $Pace->setTime($speed + $speed_step)->valueWithAppendix();
                } else {
                    if ($speed == $speed_min) {
                        $name = '<small>' . __('up to') . '</small>&nbsp;' . $Pace->setTime($speed)->valueWithAppendix();
                    } else {
                        $name = $Pace->setTime($speed + $speed_step)->value() . ' <small>' . __('to') . '</small>&nbsp;' . $Pace->setTime($speed)->valueWithAppendix();
                    }
                }
                $speed_foreach[] = array('name' => $name, 'id' => max($speed, $speed_max));
            }
        }
        return array('name' => __('Pace Zones') . '*', 'array' => $speed_data, 'foreach' => $speed_foreach);
    }
Esempio n. 13
0
 /**
  * Get menu links for sports
  * @return array
  */
 private function getMenuLinksForSports()
 {
     $Links = array($this->link(__('All sports'), $this->Year, 0, 'sport', Request::param('group') == 'sport'));
     $SportGroup = Request::param('group') == 'sport' ? 'types' : Request::param('group');
     $Sports = SportFactory::NamesAsArray();
     foreach ($Sports as $id => $name) {
         $Links[] = $this->link($name, $this->Year, $id, $SportGroup, $this->Sport->id() == $id);
     }
     return $Links;
 }
Esempio n. 14
0
/**
 * Draw total time of training for each day of a week for the user
 * Include:   inc/draw/Plot.Weekday.php
 * @package Runalyze\Plugins\Stats
 */
$titleCenter = __('Activity [in h] by weekday');
$yAxis = array();
$xAxis = array();
for ($w = 1; $w <= 7; $w++) {
    $xAxis[] = array($w - 1, Time::Weekday($w, true));
}
if ($this->sportid > 0) {
    $Sports = array(SportFactory::DataFor((int) $this->sportid));
} else {
    $Sports = SportFactory::AllSports();
}
$Query = DB::getInstance()->prepare('SELECT
		SUM(`s`) as `value`,
		(DAYOFWEEK(FROM_UNIXTIME(`time`))-1) as `day`
	FROM `' . PREFIX . 'training`
	WHERE
		`sportid`=:id
		' . $this->getYearDependenceForQuery() . '
	GROUP BY `day`
	ORDER BY ((`day`+6)%7) ASC');
// TODO: Should be possible with one query?
foreach ($Sports as $sport) {
    $id = $sport['name'];
    $yAxis[$id] = array(0, 0, 0, 0, 0, 0, 0);
    $Query->execute(array(':id' => $sport['id']));
Esempio n. 15
0
 /**
  * Parse all post values
  */
 public function parsePostData()
 {
     $Sports = SportFactory::AllSports();
     $Sports[] = array('id' => -1);
     foreach ($Sports as $Data) {
         $id = $Data['id'];
         $columns = array('name', 'img', 'short', 'kcal', 'HFavg', 'distances', 'speed', 'power', 'outside', 'main_equipmenttypeid');
         $values = array($_POST['sport']['name'][$id], $_POST['sport']['img'][$id], $_POST['sport']['short'][$id], $_POST['sport']['kcal'][$id], $_POST['sport']['HFavg'][$id], isset($_POST['sport']['distances'][$id]), $_POST['sport']['speed'][$id], isset($_POST['sport']['power'][$id]), isset($_POST['sport']['outside'][$id]), $_POST['sport']['main_equipmenttypeid'][$id]);
         if (isset($_POST['sport']['delete'][$id]) && $id != Runalyze\Configuration::General()->runningSport()) {
             DB::getInstance()->deleteByID('sport', (int) $id);
         } elseif ($Data['id'] != -1) {
             DB::getInstance()->update('sport', $id, $columns, $values);
         } elseif (strlen($_POST['sport']['name'][$id]) > 2) {
             Db::getInstance()->insert('sport', $columns, $values);
         }
     }
     SportFactory::reInitAllSports();
     Ajax::setReloadFlag(Ajax::$RELOAD_DATABROWSER);
 }
    /**
     * Display the table with general records
     */
    private function displayRekorde()
    {
        foreach ($this->rekorde as $rekord) {
            echo '<table class="fullwidth zebra-style">';
            echo '<thead><tr><th colspan="11" class="l">' . $rekord['name'] . '</th></tr></thead>';
            echo '<tbody>';
            $output = false;
            $sports = DB::getInstance()->query($rekord['sportquery'])->fetchAll();
            $Request = DB::getInstance()->prepare($rekord['datquery']);
            foreach ($sports as $sport) {
                $Request->bindValue('sportid', $sport['id']);
                $Request->execute();
                $data = $Request->fetchAll();
                if (!empty($data)) {
                    $output = true;
                    echo '<tr class="r">';
                    echo '<td class="b l">' . Icon::getSportIconForGif($sport['img'], $sport['name']) . ' ' . $sport['name'] . '</td>';
                    $j = 0;
                    foreach ($data as $j => $dat) {
                        if ($rekord['speed']) {
                            $Pace = new Pace($dat['s'], $dat['distance'], SportFactory::getSpeedUnitFor($sport['id']));
                            $code = $Pace->valueWithAppendix();
                        } else {
                            $code = $dat['distance'] != 0 ? Distance::format($dat['distance']) : Duration::format($dat['s']);
                        }
                        echo '<td class="small"><span title="' . date("d.m.Y", $dat['time']) . '">
								' . Ajax::trainingLink($dat['id'], $code) . '
							</span></td>';
                    }
                    for (; $j < 9; $j++) {
                        echo HTML::emptyTD();
                    }
                    echo '</tr>';
                }
            }
            if (!$output) {
                echo '<tr><td colspan="11"><em>' . __('No data available') . '</em></td></tr>';
            }
            echo '</tbody>';
            echo '</table>';
        }
    }
    /**
     * Show prognosis for a given distance
     * @param double $distance
     */
    protected function showPrognosis($distance)
    {
        $PB = new PersonalBest($distance);
        $PB->lookupWithDetails();
        $PBTime = $PB->exists() ? Duration::format($PB->seconds()) : '-';
        $PBString = $PB->exists() ? Ajax::trainingLink($PB->activityId(), $PBTime, true) : $PBTime;
        $Prognosis = new Duration($this->Prognosis->inSeconds($distance));
        $Distance = new Distance($distance);
        $Pace = new Pace($Prognosis->seconds(), $distance, SportFactory::getSpeedUnitFor(Configuration::General()->runningSport()));
        echo '<p>
				<span class="right">
					' . sprintf(__('<small>from</small> %s <small>to</small> <strong>%s</strong>'), $PBString, $Prognosis->string(Duration::FORMAT_AUTO, 0)) . '
					<small>(' . $Pace->valueWithAppendix() . ')</small>
				</span>
				<strong>' . $Distance->stringAuto(true, 1) . '</strong>
			</p>';
    }
 /**
  * Init calculations
  */
 protected function runCalculations()
 {
     if (!$this->PrognosisObject->isValid()) {
         return;
     }
     foreach ($this->Distances as $km) {
         $Prognosis = $this->PrognosisObject->inSeconds($km);
         $PB = new PersonalBest($km, DB::getInstance(), false);
         $PB->lookupWithDetails();
         $VDOTprognosis = new VDOT();
         $VDOTprognosis->fromPace($km, $Prognosis);
         $VDOTpb = new VDOT();
         $VDOTpb->fromPace($km, $PB->seconds());
         $PacePrognosis = new Pace($Prognosis, $km, SportFactory::getSpeedUnitFor(Configuration::General()->runningSport()));
         $PacePB = new Pace($PB->seconds(), $km, SportFactory::getSpeedUnitFor(Configuration::General()->runningSport()));
         $DateWithLink = Ajax::trainingLink($PB->activityId(), date('d.m.Y', $PB->timestamp()), true);
         $this->Prognoses[] = array('distance' => (new Distance($km))->stringAuto(), 'prognosis' => Duration::format($Prognosis), 'prognosis-pace' => $PacePrognosis->valueWithAppendix(), 'prognosis-vdot' => $VDOTprognosis->uncorrectedValue(), 'diff' => !$PB->exists() ? '-' : ($PB->seconds() > $Prognosis ? '+ ' : '- ') . Duration::format(abs(round($PB->seconds() - $Prognosis))), 'diff-class' => $PB->seconds() > $Prognosis ? 'plus' : 'minus', 'pb' => $PB->seconds() > 0 ? Duration::format($PB->seconds()) : '-', 'pb-pace' => $PB->seconds() > 0 ? $PacePB->valueWithAppendix() : '-', 'pb-vdot' => $PB->seconds() > 0 ? $VDOTpb->uncorrectedValue() : '-', 'pb-date' => $PB->seconds() > 0 ? $DateWithLink : '-');
     }
 }
Esempio n. 19
0
 /**
  * Get content for a given dataset
  * @param string $name
  * @return string
  */
 public function getDataset($name)
 {
     switch ($name) {
         case 'sportid':
             if (!is_null($this->Sport)) {
                 return $this->Sport->icon()->code();
             }
             return '';
         case 'typeid':
             if (!is_null($this->Type)) {
                 if ($this->Type->isQualitySession()) {
                     return '<strong>' . $this->Type->abbreviation() . '</strong>';
                 }
                 return $this->Type->abbreviation();
             }
             return '';
         case 'time':
             return $this->Dataview->daytime();
         case 'distance':
             return $this->Dataview->distance() . $this->distanceComparison();
         case 's':
             return $this->Dataview->duration()->string();
         case 'pace':
             if ($this->Activity->distance() > 0) {
                 if (isset($this->ActivityData['s_sum_with_distance'])) {
                     if ($this->ActivityData['s_sum_with_distance'] > 0) {
                         $Pace = new Pace($this->ActivityData['s_sum_with_distance'], $this->Activity->distance(), SportFactory::getSpeedUnitFor($this->Activity->sportid()));
                         return $Pace->valueWithAppendix();
                     }
                     return '';
                 }
                 return $this->Dataview->pace()->valueWithAppendix();
             }
             return '';
         case 'elevation':
             if ($this->Activity->elevation() > 0) {
                 return $this->Dataview->elevation()->string();
             }
             return '';
         case 'kcal':
             return $this->Dataview->calories();
         case 'pulse_avg':
             if ($this->Activity->hrAvg() > 0) {
                 return $this->Dataview->hrAvg()->string();
             }
             return '';
         case 'pulse_max':
             if ($this->Activity->hrMax() > 0) {
                 return $this->Dataview->hrMax()->string();
             }
             return '';
         case 'trimp':
             return $this->Dataview->trimp();
         case 'cadence':
             if ($this->Dataview->cadence()->value() > 0) {
                 return $this->Dataview->cadence()->asString();
             }
             return '';
         case 'stride_length':
             if ($this->Dataview->strideLength()->value() > 0) {
                 return $this->Dataview->strideLength()->string();
             }
             return '';
         case 'groundcontact':
             return $this->Dataview->groundcontact();
         case 'vertical_oscillation':
             return $this->Dataview->verticalOscillation();
         case 'power':
             return $this->Dataview->power();
         case 'temperature':
             if (!$this->Activity->weather()->temperature()->isUnknown() && (is_null($this->Sport) || $this->Sport->isOutside())) {
                 return Temperature::format($this->Activity->weather()->temperature()->value(), true, false);
             }
             return '';
         case 'weatherid':
             if (!$this->Activity->weather()->isEmpty() && (is_null($this->Sport) || $this->Sport->isOutside())) {
                 return $this->Activity->weather()->condition()->icon()->code();
             }
             return '';
         case 'routeid':
             if ($this->Activity->get(Activity\Object::ROUTEID) > 0) {
                 return $this->cut($this->Factory->route($this->Activity->get(Activity\Object::ROUTEID))->name());
             }
             return '';
         case 'splits':
             if (!$this->Activity->splits()->isEmpty()) {
                 if ($this->Activity->splits()->hasActiveAndInactiveLaps() || round($this->Activity->splits()->totalDistance()) != round($this->Activity->distance()) || !is_null($this->Type) && $this->Type->id() == Configuration::General()->competitionType()) {
                     // TODO: Icon with tooltip?
                     $Icon = new Icon(Icon::CLOCK);
                     return $Icon->code();
                 }
             }
             return '';
         case 'comment':
             return $this->cut($this->Activity->comment());
         case 'partner':
             return $this->cut($this->Activity->partner()->asString());
         case 'abc':
             return $this->Dataview->abcIcon();
         case 'vdoticon':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport()) {
                 return $this->Dataview->vdotIcon();
             }
             return '';
         case 'vdot':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport() && $this->Activity->vdotByHeartRate() > 0) {
                 if (!$this->Activity->usesVDOT()) {
                     return '<span class="unimportant">' . $this->Dataview->vdot()->value() . '</span>';
                 }
                 return $this->Dataview->vdot()->value();
             }
             return '';
         case 'jd_intensity':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport()) {
                 return $this->Dataview->jdIntensityWithStresscolor();
             }
             return '';
         case 'fit_vdot_estimate':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport()) {
                 return $this->Dataview->fitVdotEstimate();
             }
             return '';
         case 'fit_recovery_time':
             return $this->Dataview->fitRecoveryTime();
         case 'fit_hrv_analysis':
             return $this->Dataview->fitHRVscore();
     }
     return '';
 }
Esempio n. 20
0
    /**
     * Get code
     * @return string 
     */
    private function getCode()
    {
        $Code = '
			<table class="fullwidth zebra-style c">
				<thead>
					<tr class="b">
						<th>' . __('Name') . '</th>
						<th>' . __('Abbreviation') . '</th>
						<th>' . Ajax::tooltip(__('Sport'), __('A type can only belong to one sport.')) . '</th>
						<th>' . Ajax::tooltip('&Oslash;&nbsp;' . __('HR'), __('Average heart rate (used for calculation of TRIMP)')) . '</th>
						<th>' . Ajax::tooltip(__('Quality?'), __('Quality sessions will be emphasized in your calendar.')) . '</th>
						<th>' . Ajax::tooltip(__('Race'), __('You need to set one type for running as race type.')) . '</th>
						<th>' . Ajax::tooltip(__('Calendar view'), __('Mode for displaying activities in calendar')) . '</th>
						<th>' . Ajax::tooltip(Icon::$CROSS_SMALL, __('A type can only be deleted if no references exist.')) . '</th>
					</tr>
				</thead>
				<tbody>';
        $Types = DB::getInstance()->query('
			SELECT ty.id, ty.name, ty.abbr, ty.sportid, ty.short, ty.hr_avg, ty.quality_session, ty.accountid, (
				SELECT COUNT(*) 
				FROM `' . PREFIX . 'training` tr
				WHERE tr.typeid = ty.id AND
					`accountid`="' . SessionAccountHandler::getId() . '"
			) AS tcount
			FROM `' . PREFIX . 'type` ty
			WHERE `accountid`="' . SessionAccountHandler::getId() . '"
			ORDER BY `sportid` ASC, `tcount` DESC
		')->fetchAll();
        //TODO Change all locations where Typeid is used
        $Types[] = array('id' => -1, 'sportid' => -1, 'name' => '', 'abbr' => '', 'short' => 0, 'hr_avg' => 120, 'quality_session' => 0);
        $raceID = Configuration::General()->competitionType();
        $sportid = false;
        foreach ($Types as $Data) {
            $id = $Data['id'];
            if ($id == -1) {
                $delete = '';
            } elseif ($Data['tcount'] == 0) {
                $delete = '<input type="checkbox" name="type[delete][' . $id . ']">';
            } else {
                $delete = SearchLink::to('typeid', $id, '<small>(' . $Data['tcount'] . ')</small>');
            }
            $Sports = SportFactory::AllSports();
            $ShortOptions = array(0 => __('complete row'), 1 => __('only icon'));
            $Code .= '
				<tr class="' . ($sportid !== false && $sportid != $Data['sportid'] ? 'top-separated-light' : '') . ($id == -1 ? ' unimportant' : '') . '">
					<td><input type="text" size="20" name="type[name][' . $id . ']" value="' . $Data['name'] . '"></td>
					<td><input type="text" size="3" name="type[abbr][' . $id . ']" value="' . $Data['abbr'] . '"></td>
					<td><select name="type[sportid][' . $id . ']">';
            foreach ($Sports as $SData) {
                $Code .= '<option value="' . $SData['id'] . '"' . HTML::Selected($SData['id'] == $Data['sportid']) . '>' . $SData['name'] . '</option>';
            }
            $Code .= '</select></td>
					<td>
						<span class="input-with-unit">
							<input type="text" name="type[hr_avg][' . $id . ']" value="' . $Data['hr_avg'] . '" id="type_hr_avg_' . $id . '" class="small-size">
							<label for="type_hr_avg_' . $id . '" class="input-unit">bpm</label>
						</span>
					</td>
					<td><input type="checkbox" name="type[quality_session][' . $id . ']"' . ($Data['quality_session'] ? ' checked' : '') . '></td>
					<td>' . ($id == -1 ? '' : '<input type="radio" name="racetype" value="' . $id . '"' . ($id == $raceID ? ' checked' : '') . '>') . '</td>
					<td>' . HTML::selectBox('type[short][' . $id . ']', $ShortOptions, $Data['short']) . '</td>
					<td>' . $delete . '</td>
				</tr>';
            $sportid = $Data['sportid'];
        }
        $Code .= '
				</tbody>
			</table>';
        return $Code;
    }
    /**
     * Display the images
     */
    private function displayTable()
    {
        if ($this->sportid > 0) {
            $sports_not_short = $this->sportid . ',';
        } else {
            $sports_not_short = '';
            $sports = DB::getInstance()->query('SELECT `id` FROM `' . PREFIX . 'sport` WHERE `short`=0 AND `accountid` = ' . SessionAccountHandler::getId())->fetchAll();
            foreach ($sports as $sport) {
                $sports_not_short .= $sport['id'] . ',';
            }
        }
        $nights = DB::getInstance()->query('SELECT * FROM (
			SELECT
				id,
				time,
				s,
				sportid,
				distance,
				is_track,
				HOUR(FROM_UNIXTIME(`time`)) as `H`,
				MINUTE(FROM_UNIXTIME(`time`)) as `MIN`
			FROM `' . PREFIX . 'training`
			WHERE
				`sportid` IN(' . substr($sports_not_short, 0, -1) . ') AND
                                `accountid` = ' . SessionAccountHandler::getId() . ' AND
				(HOUR(FROM_UNIXTIME(`time`))!=0 OR MINUTE(FROM_UNIXTIME(`time`))!=0) 
				' . $this->getYearDependenceForQuery() . '
			ORDER BY
				ABS(12-(`H`+10)%24-`MIN`/60) ASC,
				`MIN` DESC LIMIT 20
			) t
		ORDER BY
			(`H`+12)%24 ASC,
			`MIN` ASC')->fetchAll();
        if (empty($nights)) {
            $this->dataIsMissing = true;
            return;
        }
        echo '<table class="fullwidth zebra-style">';
        echo '<thead><tr class="b c"><th colspan="8">' . __('Nightly activities') . '</th></tr></thead>';
        echo '<tbody>';
        foreach ($nights as $i => $data) {
            $Activity = new Activity\Entity($data);
            $Linker = new Linker($Activity);
            $View = new Dataview($Activity);
            if ($i % 2 == 0) {
                echo '<tr">';
            }
            echo '<td class="b">' . $View->daytime() . '</td>
				<td>' . $Linker->linkWithSportIcon() . '</td>
				<td>' . $View->distanceOrDuration() . ' ' . SportFactory::name($Activity->sportid()) . '</td>
				<td>' . $Linker->weekLink() . '</td>';
            if ($i % 2 == 1) {
                echo '</tr>';
            }
        }
        echo '</tbody></table>';
        // TODO: Find a better description.
        echo '<p class="text">';
        echo __('2 a.m. is considered as <em>most extreme</em> time for a training. ');
        echo __('The 20 trainings being nearest to that time are listed.');
        echo '</p>';
    }
 /**
  * Initialize line-data-array for 'Tempo'
  * @param array $dat
  */
 private function initTempoData($dat)
 {
     $Pace = new Pace($dat['s_sum_with_distance'], $dat['distance'], SportFactory::getSpeedUnitFor($this->sportid));
     $text = $dat['s_sum_with_distance'] == 0 ? NBSP : $Pace->valueWithAppendix();
     $this->TempoData[] = array('i' => $dat['i'], 'text' => $text);
 }
Esempio n. 23
0
 /**
  * Sport
  * @param int $sportid
  * @return \Runalyze\Model\Sport\Object
  */
 public function sport($sportid)
 {
     return new Sport\Object(\SportFactory::DataFor($sportid));
 }
Esempio n. 24
0
 /**
  * Get sport as string
  * @return string
  */
 protected function getSportString()
 {
     return $this->sportid == -1 ? __('All') : SportFactory::name($this->sportid);
 }
Esempio n. 25
0
 /**
  * Try to get current sport id
  * @return int 
  */
 protected function findSportId()
 {
     if (!empty($this->XML->sportType)) {
         $Name = (string) $this->XML->sportType;
         $Id = SportFactory::idByName($Name);
         if ($Id > 0) {
             return $Id;
         } else {
             switch ($Name) {
                 case 'Run':
                     $Name = 'Laufen';
                     break;
                 case 'Bike':
                 case 'Mountain Bike':
                     $Name = 'Radfahren';
                     break;
                 case 'Swim':
                     $Name = 'Schwimmen';
                     break;
                 default:
                     $Name = 'Sonstiges';
             }
             $Id = SportFactory::idByName($Name);
             if ($Id > 0) {
                 return $Id;
             }
         }
     }
     return Configuration::General()->runningSport();
 }
 /**
  * Submenu for sport
  * @param int $sportid
  * @param int $year
  * @return string
  */
 private static function submenuForSport($sportid, $year)
 {
     $Code = '<li' . (-1 == $sportid ? ' class="active"' : '') . '>' . self::linkToRoutenet(__('All'), -1, $year) . '</li>';
     $Sports = SportFactory::NamesAsArray();
     foreach ($Sports as $id => $name) {
         $Code .= '<li' . ($id == $sportid ? ' class="active"' : '') . '>' . self::linkToRoutenet($name, $id, $year) . '</li>';
     }
     return $Code;
 }