public function testSimpleUpdate() { $Inserter = new Inserter($this->PDO); $Inserter->setAccountID(1); $Inserter->insert(new Object(array(Object::NAME => 'Sport name', Object::CALORIES_PER_HOUR => 700))); $Sport = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'sport` WHERE `id`=' . $Inserter->insertedID())->fetch(PDO::FETCH_ASSOC)); $Sport->set(Object::CALORIES_PER_HOUR, 0); $Changed = clone $Sport; $Changed->set(Object::NAME, 'New sport name'); $Updater = new Updater($this->PDO, $Changed, $Sport); $Updater->setAccountID(1); $Updater->update(); $Result = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'sport` WHERE `id`=' . $Inserter->insertedID())->fetch(PDO::FETCH_ASSOC)); $this->assertEquals('New sport name', $Result->name()); $this->assertEquals(700, $Result->caloriesPerHour()); }
public function testSimpleInsert() { $Object = new Object(array(Object::NAME => 'Sport name', Object::SHORT => 0, Object::CALORIES_PER_HOUR => 700, Object::HR_AVG => 140, Object::HAS_DISTANCES => 1, Object::PACE_UNIT => 'foo', Object::HAS_TYPES => 1, Object::HAS_POWER => 0, Object::IS_OUTSIDE => 1)); $Inserter = new Inserter($this->PDO, $Object); $Inserter->setAccountID(1); $Inserter->insert(); $data = $this->PDO->query('SELECT * FROM `' . PREFIX . 'sport` WHERE `accountid`=1')->fetch(PDO::FETCH_ASSOC); $Sport = new Object($data); $this->assertEquals('Sport name', $Sport->name()); $this->assertEquals(700, $Sport->caloriesPerHour()); $this->assertEquals(140, $Sport->avgHR()); $this->assertEquals('foo', $Sport->paceUnit()); $this->assertTrue($Sport->hasDistances()); $this->assertTrue($Sport->hasTypes()); $this->assertTrue($Sport->isOutside()); $this->assertFalse($Sport->usesShortDisplay()); $this->assertFalse($Sport->hasPower()); }
/** * Keys to insert * @return array */ protected function keys() { return array_merge(array(self::ACCOUNTID), Object::allProperties()); }
/** * @return string */ public function sportIcon() { $Icon = $this->Sport->icon(); $Icon->setTooltip($this->Sport->name()); return $Icon->code(); }
/** * 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 ''; }
/** * 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 $sportData) { $Request->bindValue('sportid', $sportData['id']); $Request->execute(); $data = $Request->fetchAll(); if (!empty($data)) { $Sport = new Sport\Object($sportData); $output = true; echo '<tr class="r">'; echo '<td class="b l">' . $Sport->icon()->code() . ' ' . $Sport->name() . '</td>'; $j = 0; foreach ($data as $j => $dat) { if ($rekord['speed']) { $Pace = new Pace($dat['s'], $dat['distance']); $Pace->setUnit($Sport->paceUnit()); $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>'; } }
/** * 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) { // TODO: 's_sum_with_distance' //return $this->TrainingObject->DataView()->getSpeedStringForTime( $this->TrainingObject->getTimeInSecondsSumWithDistance() ); return $this->Dataview->pace()->valueWithAppendix(); } return ''; case 'elevation': return $this->Dataview->elevation(); 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()->inCM() > 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 $this->Activity->weather()->temperature()->asString(); } 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 'clothes': return $this->cut($this->Dataview->clothes()); 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 'shoeid': if ($this->Activity->shoeID() > 0) { return ShoeFactory::NameOf($this->Activity->shoeID()); } return ''; 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 ''; } return ''; }