Пример #1
0
    /**
     * Update statistics
     * @return mixed false on failure, number of affected rows otherwise
     */
    public function run()
    {
        $whereAccount = null !== $this->accountID ? 'WHERE `eqp`.`accountid` = ' . $this->accountID : '';
        $result = $this->PDO->exec('UPDATE `' . PREFIX . 'equipment`
			CROSS JOIN(
				SELECT
					`eqp`.`id` AS `eqpid`,
					SUM(`tr`.`distance`) AS `km`,
					SUM(`tr`.`s`) AS `s` 
				FROM `' . PREFIX . 'equipment` AS `eqp` 
				LEFT JOIN `' . PREFIX . 'activity_equipment` AS `aeqp` ON `eqp`.`id` = `aeqp`.`equipmentid` 
				LEFT JOIN `' . PREFIX . 'training` AS `tr` ON `aeqp`.`activityid` = `tr`.`id`
				' . $whereAccount . '
				GROUP BY `eqp`.`id`
			) AS `new`
			SET
				`distance` = IFNULL(`new`.`km`, 0),
				`time` = IFNULL(`new`.`s`, 0)
			WHERE `id` = `new`.`eqpid`');
        if ($result !== false) {
            $Factory = new \Runalyze\Model\Factory($this->accountID);
            $Factory->clearCache('equipment');
        }
        return $result;
    }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * 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 '';
 }
Пример #4
0
 /**
  * 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 '';
 }
Пример #5
0
 /**
  * @param int $sportid
  * @return array
  */
 protected function getEquipmentTypeOptions($sportid)
 {
     $Options = array(0 => __('none'));
     $Factory = new \Runalyze\Model\Factory(\SessionAccountHandler::getId());
     foreach ($Factory->equipmentTypeForSport($sportid) as $Type) {
         $Options[$Type->id()] = $Type->name();
     }
     return $Options;
 }
 /**
  * Initialize internal data
  */
 private function initData()
 {
     $this->sportid = Configuration::General()->mainSport();
     $Factory = new \Runalyze\Model\Factory(SessionAccountHandler::getId());
     $this->EquipmentTypes = $Factory->allEquipmentTypes();
     if (isset($_GET['dat'])) {
         $this->Equipment = $Factory->equipmentForEquipmentType($_GET['dat']);
     }
     if ($this->showsAllYears()) {
         $this->i = 0;
         $this->jahr = __('In total');
         $this->jstart = mktime(0, 0, 0, 1, 1, START_YEAR);
         $this->jende = time();
     } else {
         $this->i = $this->year;
         $this->jahr = $this->year;
         $this->jstart = mktime(0, 0, 0, 1, 1, $this->i);
         $this->jende = mktime(23, 59, 59, 1, 0, $this->i + 1);
     }
 }
Пример #7
0
 /**
  * Add equipment
  */
 protected function addEquipment()
 {
     $Types = array();
     $Factory = new \Runalyze\Model\Factory(SessionAccountHandler::getId());
     $Equipment = $Factory->equipmentForActivity($this->Context->activity()->id());
     foreach ($Equipment as $Object) {
         $Link = SearchLink::to('equipmentid', $Object->id(), $Object->name());
         if (isset($Types[$Object->typeid()])) {
             $Types[$Object->typeid()][] = $Link;
         } else {
             $Types[$Object->typeid()] = array($Link);
         }
     }
     foreach ($Types as $typeid => $links) {
         $Type = $Factory->equipmentType($typeid);
         $Value = new BoxedValue(implode(', ', $links), '', $Type->name());
         $Value->defineAsFloatingBlock('w100 flexible-height');
         $this->BoxedValues[] = $Value;
     }
 }
 /**
  * Add tags
  */
 protected function addTags()
 {
     $Links = array();
     $Factory = new \Runalyze\Model\Factory(SessionAccountHandler::getId());
     $SelectedTags = $Factory->tagForActivity($this->Context->activity()->id());
     foreach ($SelectedTags as $Object) {
         $Links[] = SearchLink::to('tagid', $Object->id(), '#' . $Object->tag());
     }
     if (!empty($Links)) {
         $Value = new BoxedValue(implode(', ', $Links), '', __('Tags'));
         $Value->defineAsFloatingBlock('w100 flexible-height');
         $this->BoxedValues[] = $Value;
     }
 }
Пример #9
0
 /**
  * Get link with icon as text
  * @param string $tooltipCssClass optional, e.g. 'atRight'
  * @return string HTML-link to this training
  */
 public function linkWithSportIcon($tooltipCssClass = '')
 {
     $Time = new Duration($this->Activity->duration());
     $Factory = new \Runalyze\Model\Factory(\SessionAccountHandler::getId());
     $Sport = $Factory->sport($this->Activity->sportid());
     $code = $Sport->icon()->code();
     $Tooltip = new \Runalyze\View\Tooltip($Sport->name() . ': ' . $Time->string());
     $Tooltip->setPosition($tooltipCssClass);
     $Tooltip->wrapAround($code);
     return $this->link($code);
 }