/** * 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); }
/** * 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'); } }
/** * 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 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('Ø ' . __('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; }
/** * 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']));
/** * 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); }