private function insertNewTag() { $InsertTag = new Model\Tag\Inserter($this->PDO, $this->TagObject); $InsertTag->setAccountID(\SessionAccountHandler::getId()); $InsertTag->insert(); return $InsertTag->insertedID(); }
/** * Get fieldset block * @return string */ private function getFieldsetBlock() { $String = ''; foreach ($this->TrainingObjects as $i => $TrainingObject) { $activityIDs[] = $TrainingObject->getActivityId(); } $duplicates = (new DuplicateFinder(DB::getInstance(), SessionAccountHandler::getId()))->checkForDuplicates($activityIDs); $countDuplicates = count(array_filter($duplicates)); $String .= HTML::info(sprintf(__('Found %s activities.'), count($this->TrainingObjects))); if ($countDuplicates > 0) { $String .= HTML::warning(_n('Found <strong>one</strong> duplicate activity.', 'Found duplicate activities.', $countDuplicates)); } $String .= '<table class="fullwidth multi-import-table zebra-style c" id="multi-import-table">'; $String .= '<thead><tr><th>' . __('Import') . '</th><th>' . __('Date') . '</th><th>' . __('Duration') . '</th><th>' . __('Distance') . '</th><th colspan="4"></th></tr></thead>'; $String .= '<tbody>'; foreach ($this->TrainingObjects as $i => $TrainingObject) { $String .= '<tr>' . $this->getTableRowFor($TrainingObject, $i, $duplicates[$TrainingObject->getActivityId()]) . '</tr>'; } $String .= '</tbody>'; $String .= '</table>'; $String .= Ajax::wrapJSforDocumentReady(' $("#multi-import-table td").click(function(e){ if ($(e.target).closest(\'input[type="checkbox"]\').length == 0) $(this).parent().find(\'input:checkbox\').attr(\'checked\', !$(this).parent().find(\'input:checkbox\').attr(\'checked\')); }); '); return $String; }
/** * Display the content * @see PluginPanel::displayContent() */ protected function displayContent() { echo $this->getStyle(); echo '<div id="schuhe">'; // TODO: Use data from shoe factory $inuse = true; $schuhe = DB::getInstance()->query('SELECT * FROM `' . PREFIX . 'shoe` WHERE accountid = ' . SessionAccountHandler::getId() . ' ORDER BY `inuse` DESC, `km` DESC')->fetchAll(); foreach ($schuhe as $schuh) { $Shoe = new Shoe($schuh); if ($inuse && $Shoe->isInUse() == 0) { echo '<div id="hiddenschuhe" style="display:none;">'; $inuse = false; } echo '<p style="position:relative;"> <span class="right">' . $Shoe->getKmString() . '</span> <strong>' . ShoeFactory::getSearchLink($schuh['id']) . '</strong> ' . $this->getShoeUsageImage($Shoe->getKm()) . ' </p>'; } if (empty($schuhe)) { echo HTML::em(__('You don\'t have any shoes')); } if (!$inuse) { echo '</div>'; } echo '</div>'; if (!$inuse) { echo Ajax::toggle('<a class="right" href="#schuhe" name="schuhe">' . __('Show unused shoes') . '</a>', 'hiddenschuhe'); } echo HTML::clearBreak(); }
/** * Construct importer * @param string $fileName relative to FRONTEND_PATH */ public function __construct($fileName) { $this->Reader = new BigFileReaderGZip($fileName); $this->DB = DB::getInstance(); $this->AccountID = USER_MUST_LOGIN ? SessionAccountHandler::getId() : 0; $this->Results = new RunalyzeJsonImporterResults(); }
/** * Constructor * @param string $Type */ public function __construct($Type) { $ExporterClass = 'Exporter' . $Type; if (class_exists($ExporterClass)) { $this->Exporter = new $ExporterClass(new Context(Request::sendId(), SessionAccountHandler::getId())); } }
/** * Fetch row by id * @param string $table without PREFIX * @param int $ID * @return array */ public function fetchByID($table, $ID) { $table = str_replace(PREFIX, '', $table); if ($table == 'account' || $table == 'plugin_conf') { return $this->query('SELECT * FROM `' . PREFIX . $table . '` WHERE `id`=' . (int) $ID . ' LIMIT 1')->fetch(); } return $this->query('SELECT * FROM `' . PREFIX . $table . '` WHERE `id`=' . (int) $ID . ' AND `accountid`="' . SessionAccountHandler::getId() . '" LIMIT 1')->fetch(); }
/** * Init training */ private function initTraining() { // TODO: Cache? $this->ActivityContext = new Activity\Context(SharedLinker::getTrainingId(), SessionAccountHandler::getId()); if ($this->ActivityContext->activity()->id() <= 0) { $this->ActivityContext = null; } }
/** * @return int|null */ protected function equipmentTypeIdForNewStuff() { if (null === $this->NewEquipmentTypeId) { $this->NewEquipmentTypeId = DB::getInstance()->insert('equipment_type', ['name', 'accountid'], ['RunningAHEAD', SessionAccountHandler::getId()]); DB::getInstance()->exec('INSERT INTO `' . PREFIX . 'equipment_sport` (`sportid`, `equipment_typeid`) SELECT `id`, "' . $this->NewEquipmentTypeId . '" FROM `runalyze_sport` WHERE `accountid`=' . SessionAccountHandler::getId()); } return $this->NewEquipmentTypeId; }
/** * Construct summary table * @param \Runalyze\Dataset\Configuration $datasetConfig * @param int $sportid * @param int $year */ public function __construct(Dataset\Configuration $datasetConfig, $sportid, $year) { $this->AccountID = SessionAccountHandler::getId(); $this->DatasetQuery = new Dataset\Query($datasetConfig, DB::getInstance(), $this->AccountID); $this->DatasetTable = new Runalyze\View\Dataset\Table($datasetConfig); $this->Sportid = $sportid; $this->Year = $year; }
/** * Handle request */ private function handleRequest() { if (strlen(Request::param('public')) > 0) { $Updater = new Activity\Updater(DB::getInstance()); $Updater->setAccountID(SessionAccountHandler::getId()); $Updater->update(new Activity\Object(array('id' => $this->TrainingID, Activity\Object::IS_PUBLIC => Request::param('public') == 'true' ? 1 : 0)), array(Activity\Object::IS_PUBLIC)); } }
/** * Cache Clothes */ private static function cacheAllClothes() { $clothes = Cache::get(self::CACHE_KEY); if (is_null($clothes)) { $clothes = DB::getInstance()->query('SELECT * FROM `' . PREFIX . 'clothes` WHERE accountid = ' . SessionAccountHandler::getId())->fetchAll(); Cache::set(self::CACHE_KEY, $clothes, '3600'); } return $clothes; }
/** * Cache all from Table plugin for a user */ private static function fetchAllPlugins() { $data = Cache::get(self::CACHE_KEY); if ($data == NULL) { $data = self::fetchAllPluginsFrom(DB::getInstance(), SessionAccountHandler::getId()); Cache::set(self::CACHE_KEY, $data, '3600'); } return $data; }
/** * Uninstall * @return bool */ public function uninstall() { $Factory = new PluginFactory(); $Plugin = $Factory->newInstance($this->Key); DB::getInstance()->deleteByID('plugin', $Plugin->id()); DB::getInstance()->query('DELETE FROM `' . PREFIX . 'plugin_conf` WHERE `pluginid`=' . $Plugin->id() . ' AND accountid = ' . SessionAccountHandler::getId()); PluginFactory::clearCache(); return true; }
/** * Construct importer * @param string $fileName relative to FRONTEND_PATH * @param int $accountID optional, session account id is used otherwise */ public function __construct($fileName, $accountID = false) { $this->Reader = new GZipReader(FRONTEND_PATH . $fileName); $this->DB = DB::getInstance(); $this->AccountID = SessionAccountHandler::getId(); $this->Results = new RunalyzeJsonImporterResults(); if ($accountID !== false) { $this->AccountID = $accountID; } }
/** * Load account ID * @return int */ private static function loadAccountID() { if (defined('RUNALYZE_TEST')) { return null; } if (\AccountHandler::$IS_ON_REGISTER_PROCESS) { return \AccountHandler::$NEW_REGISTERED_ID; } return \SessionAccountHandler::getId(); }
/** * Handle request */ protected function handleRequest() { if (Request::param('use-calculated-value') == 'true') { $oldObject = clone $this->Context->activity(); $this->Context->activity()->set(Model\Activity\Object::ELEVATION, $this->Context->route()->elevation()); $Updater = new Model\Activity\Updater(DB::getInstance(), $this->Context->activity(), $oldObject); $Updater->setAccountID(SessionAccountHandler::getId()); $Updater->update(); } }
/** * Insert Show * @param SimpleXMLElement $Equipment */ private function insertShoe(SimpleXMLElement &$Equipment) { if ((string) $Equipment->Name == '') { return; } $ExistingShoe = DB::getInstance()->query('SELECT id FROM `' . PREFIX . 'shoe` WHERE name=' . DB::getInstance()->escape($Equipment->Name) . ' AND accountid = ' . SessionAccountHandler::getId() . ' LIMIT 1')->fetch(); if (isset($ExistingShoe['id'])) { self::$NewEquipment[(string) $Equipment->attributes()->id] = $ExistingShoe['id']; } else { self::$NewEquipment[(string) $Equipment->attributes()->id] = DB::getInstance()->insert('shoe', array('name', 'since', 'additionalKm', 'inuse'), array((string) $Equipment->Name, isset($Equipment->PurchaseInfo) && isset($Equipment->PurchaseInfo['date']) ? (string) $Equipment->PurchaseInfo['date'] : '', isset($Equipment->Distance) && isset($Equipment->Distance['initialDistance']) ? $this->distanceFromUnit($Equipment->Distance['initialDistance'], $Equipment->Distance['unit']) : 0, isset($Equipment->Name['retired']) && (string) $Equipment->Name['retired'] == 'true' ? 0 : 1)); } }
/** * Get string to display this dataset value * @param \Runalyze\Dataset\Context $context * @return string */ public function stringFor(Context $context) { $string = ''; if ($context->hasData(self::CONCAT_TAGIDS_KEY) && $context->data(self::CONCAT_TAGIDS_KEY) != '') { $ids = explode(',', $context->data(self::CONCAT_TAGIDS_KEY)); $Factory = new \Runalyze\Model\Factory(\SessionAccountHandler::getId()); foreach ($ids as $id) { $string .= '#' . $Factory->tag($id)->tag() . ' '; } } return $string; }
/** * Initialize this plugin * @see PluginPanel::initPlugin() */ protected function initPlugin() { $this->fileNameStart = SessionAccountHandler::getId() . '-runalyze-backup'; if (isset($_GET['json'])) { if (move_uploaded_file($_FILES['qqfile']['tmp_name'], realpath('') . '/../data/DbBackup/import/' . $_FILES['qqfile']['name'])) { Error::getInstance()->footer_sent = true; echo '{"success":true}'; } else { echo '{"error":"Moving file did not work. Set chmod 777 for /data/DbBackup/import/"}'; } exit; } }
/** * Init all types * * IDs will be set as string as indices for correct order */ private static function initAllTypes() { self::$AllTypes = array(); $types = Cache::get('types'); if (is_null($types)) { $types = DB::getInstance()->query('SELECT * FROM `' . PREFIX . 'type` WHERE `accountid` = ' . SessionAccountHandler::getId())->fetchAll(); Cache::set('types', $types, '3600'); } foreach ($types as $data) { self::$AllTypes[(string) $data['id']] = $data; } Configuration::ActivityForm()->orderTypes()->sort(self::$AllTypes); }
/** * Get string to display this dataset value * @param \Runalyze\Dataset\Context $context * @return string */ public function stringFor(Context $context) { if ($context->hasData(parent::CONCAT_EQUIPMENT_KEY) && $context->data(parent::CONCAT_EQUIPMENT_KEY) != '') { $ids = explode(',', $context->data(parent::CONCAT_EQUIPMENT_KEY)); $Factory = new \Runalyze\Model\Factory(\SessionAccountHandler::getId()); $names = array(); foreach (array_unique($ids) as $id) { $names[] = $Factory->equipment($id)->name(); } $Icon = new \Runalyze\View\Icon('fa-cubes'); $Icon->setTooltip(implode(', ', $names)); return $Icon->code(); } return ''; }
protected function setUp() { $this->PDO = \DB::getInstance(); $this->PDO->exec('DELETE FROM `runalyze_training`'); $this->PDO->exec('DELETE FROM `runalyze_account` WHERE `username` = "LinkerOther"'); $this->ThisAccountID = \SessionAccountHandler::getId(); $this->PDO->exec('INSERT INTO `runalyze_account` (`username`, `name`, `mail`) VALUES ("LinkerOther", "LinkerOther", "*****@*****.**")'); $this->OtherAccountID = $this->PDO->lastInsertId(); $activities = [[0, $this->OtherAccountID], [1, $this->ThisAccountID], [2, $this->OtherAccountID], [3, $this->ThisAccountID], [3, $this->ThisAccountID], [4, $this->OtherAccountID], [5, $this->ThisAccountID], [6, $this->OtherAccountID]]; foreach ($activities as $data) { $this->PDO->exec('INSERT INTO `runalyze_training` (`time`, `accountid`) VALUES (' . $data[0] . ', ' . $data[1] . ')'); if ($data[1] == $this->ThisAccountID) { $this->ThisIDs[] = $this->PDO->lastInsertId(); } } }
/** * Get string to display this dataset value * @param \Runalyze\Dataset\Context $context * @return string */ public function stringFor(Context $context) { if ($context->hasData(parent::CONCAT_EQUIPMENT_KEY) && $context->data(parent::CONCAT_EQUIPMENT_KEY) != '') { $ids = explode(',', $context->data(parent::CONCAT_EQUIPMENT_KEY)); $Factory = new \Runalyze\Model\Factory(\SessionAccountHandler::getId()); $mainTypeID = $context->sport()->mainEquipmentTypeID(); $names = array(); foreach (array_unique($ids) as $id) { $Equipment = $Factory->equipment($id); if ($Equipment->typeid() == $mainTypeID) { $names[] = $Factory->equipment($id)->name(); } } return implode(', ', $names); } return ''; }
/** * Initialize $this->ABCData */ private function initData() { $result = DB::getInstance()->query(' SELECT SUM(`abc`) as `abc`, SUM(1) as `num`, YEAR(FROM_UNIXTIME(`time`)) as `year`, MONTH(FROM_UNIXTIME(`time`)) as `month` FROM `' . PREFIX . 'training` WHERE `sportid`=' . Configuration::General()->runningSport() . ' AND `accountid`=' . SessionAccountHandler::getId() . ' GROUP BY `year` DESC, `month` ASC')->fetchAll(); foreach ($result as $dat) { if ($dat['abc'] > 0) { $this->ABCData[$dat['year']][$dat['month']] = array('abc' => $dat['abc'], 'num' => $dat['num']); } } }
/** * Init internal array with all trainings */ private function initTrainings() { $this->Query = DB::getInstance()->query(' SELECT `id`, `time`, `sportid`, `distance`, `s`, `is_track`, `comment`, `pulse_avg`, `pulse_max`, `vdot`, `vdot_by_time` FROM `' . PREFIX . 'training` WHERE `pulse_avg`!=0 AND `typeid`=' . Configuration::General()->competitionType() . ' AND `accountid` = ' . SessionAccountHandler::getId() . ' ORDER BY `time` DESC'); }
public function testSimpleRecalculations() { $id = (int) \SessionAccountHandler::getId(); $this->PDO->exec('INSERT INTO `' . PREFIX . 'route` VALUES(' . $id . ', 1, 0, 0, 0, "100|200|150", "")'); $this->PDO->exec('INSERT INTO `' . PREFIX . 'route` VALUES(' . $id . ', 2, 100, 100, 50, "100|200|150", "")'); $this->PDO->exec('INSERT INTO `' . PREFIX . 'route` VALUES(' . $id . ', 3, 0, 0, 0, "", "150|200|100")'); $this->PDO->exec('INSERT INTO `' . PREFIX . 'route` VALUES(' . $id . ', 4, 100, 0, 0, "", "")'); $Job = new ElevationsRecalculator($this->PDO); $Job->run(); $Fetch = $this->PDO->prepare('SELECT `elevation`, `elevation_up`, `elevation_down` FROM `' . PREFIX . 'route` WHERE `id`=:id'); $Fetch->setFetchMode(PDO::FETCH_NUM); $this->assertEquals(2, $Job->numberOfRoutes()); $Fetch->execute(array(':id' => 1)); $this->assertEquals(array(100, 100, 50), $Fetch->fetch()); $Fetch->execute(array(':id' => 2)); $this->assertEquals(array(100, 100, 50), $Fetch->fetch()); $Fetch->execute(array(':id' => 3)); $this->assertEquals(array(100, 50, 100), $Fetch->fetch()); $Fetch->execute(array(':id' => 4)); $this->assertEquals(array(100, 0, 0), $Fetch->fetch()); $this->assertEquals(array(1 => array(100, 100, 50), 2 => array(100, 100, 50), 3 => array(100, 50, 100)), $Job->results()); }
/** * Load last object */ private function loadLastObject() { if ($this->DatabaseScheme->hasTimestamp()) { $this->data = DB::getInstance()->query('SELECT * FROM `' . $this->tableName() . '` WHERE accountid = ' . SessionAccountHandler::getId() . ' ORDER BY `time` DESC LIMIT 1')->fetch(); } else { $this->data = DB::getInstance()->query('SELECT * FROM `' . $this->tableName() . '` WHERE accountid = ' . SessionAccountHandler::getId() . ' ORDER BY `id` DESC LIMIT 1')->fetch(); } if (empty($this->data)) { $this->constructAsDefaultObject(); } }
/** * Was there a run today? * @return bool */ private function wasRunningToday() { return 0 < DB::getInstance()->query(' SELECT `sportid` FROM `' . PREFIX . 'training` WHERE `time` BETWEEN UNIX_TIMESTAMP(\'' . date('Y-m-d') . '\') AND UNIX_TIMESTAMP(\'' . date('Y-m-d', time() + DAY_IN_S) . '\')-1 AND `sportid`=' . Configuration::General()->runningSport() . ' AND `accountid`=' . SessionAccountHandler::getId() . ' LIMIT 1 ')->rowCount(); }
/** * Display */ public function display() { foreach ($this->Properties as $name => $content) { echo '<meta property="' . $name . '" content="' . $content . '">' . NL; } if (!empty($this->Properties) && $this->Context->hasRoute() && $this->Context->route()->hasPositionData()) { echo '<link rel="opengraph" href="' . System::getFullDomain() . 'call/call.MetaCourse.php?id=' . $this->Context->activity()->id() . '&account=' . SessionAccountHandler::getId() . '">'; } }
/** * Parse all post values */ public function parsePostData() { $Types = DB::getInstance()->query('SELECT `id` FROM `' . PREFIX . 'type` WHERE `accountid` = ' . SessionAccountHandler::getId())->fetchAll(); $Types[] = array('id' => -1); foreach ($Types as $Type) { $id = $Type['id']; $columns = array('name', 'abbr', 'sportid', 'short', 'hr_avg', 'quality_session'); $values = array($_POST['type']['name'][$id], $_POST['type']['abbr'][$id], $_POST['type']['sportid'][$id], $_POST['type']['short'][$id], $_POST['type']['hr_avg'][$id], isset($_POST['type']['quality_session'][$id])); if (isset($_POST['type']['delete'][$id])) { DB::getInstance()->deleteByID('type', (int) $id); } elseif ($id != -1) { DB::getInstance()->update('type', $id, $columns, $values); } elseif (strlen($_POST['type']['name'][$id]) > 2) { DB::getInstance()->insert('type', $columns, $values); } } if (isset($_POST['type']['name'][$_POST['racetype']]) && !isset($_POST['type']['delete'][$_POST['racetype']]) && $_POST['type']['sportid'][$_POST['racetype']] == Configuration::General()->runningSport() && $_POST['racetype'] != Configuration::General()->competitionType()) { // TODO: this needs a recalculation of vdot factor Configuration::General()->updateCompetitionType($_POST['racetype']); Ajax::setReloadFlag(Ajax::$RELOAD_PLUGINS); } TypeFactory::reInitAllTypes(); Ajax::setReloadFlag(Ajax::$RELOAD_DATABROWSER); }