public function testSimpleInsert() { $Equipment = new Object(array(Object::NAME => 'Equipment name', Object::TYPEID => $this->Typeid, Object::NOTES => 'Here are some notes', Object::DATE_START => '2015-01-01', Object::DATE_END => null)); $Inserter = new Inserter($this->PDO, $Equipment); $Inserter->setAccountID(1); $Inserter->insert(); $data = $this->PDO->query('SELECT * FROM `' . PREFIX . 'equipment` WHERE `accountid`=1')->fetch(PDO::FETCH_ASSOC); $New = new Object($data); $this->assertEquals('Equipment name', $New->name()); $this->assertEquals('Here are some notes', $New->notes()); $this->assertTrue($New->hasStartDate()); $this->assertEquals('2015-01-01', $New->startDate()); $this->assertTrue($New->isInUse()); $this->assertEquals(null, $New->endDate()); }
public function testSimpleUpdate() { $Inserter = new Inserter($this->PDO); $Inserter->setAccountID(1); $Inserter->insert(new Object(array(Object::NAME => 'Equipment name', Object::TYPEID => $this->Typeid, Object::NOTES => 'Here are some notes', Object::DATE_START => '2015-01-01', Object::DATE_END => '2015-02-02'))); $Type = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'equipment` WHERE `id`=' . $Inserter->insertedID())->fetch(PDO::FETCH_ASSOC)); $Type->set(Object::NOTES, ''); $Changed = clone $Type; $Changed->set(Object::DATE_END, null); $Updater = new Updater($this->PDO, $Changed, $Type); $Updater->setAccountID(1); $Updater->update(); $Result = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'equipment` WHERE `id`=' . $Inserter->insertedID())->fetch(PDO::FETCH_ASSOC)); $this->assertEquals('Equipment name', $Result->name()); $this->assertEquals('Here are some notes', $Result->notes()); $this->assertTrue($Result->hasStartDate()); $this->assertEquals('2015-01-01', $Result->startDate()); $this->assertTrue($Result->isInUse()); $this->assertEquals(null, $Result->endDate()); }
/** * Keys to insert * @return array */ protected function keys() { return array_merge(array(self::ACCOUNTID), Object::allDatabaseProperties()); }
/** * Display table */ public function displayTable() { if (is_null($this->Equipment)) { $this->initTableData(); } echo '<table id="list-of-all-equipment" class="fullwidth zebra-style"> <thead> <tr> <th class="{sorter: \'x\'} small">' . __('x-times') . '</th> <th>' . __('Name') . '</th> <th class="{sorter: \'germandate\'} small">' . __('since') . '</th> <th class="{sorter: \'distance\'}">Ø ' . Runalyze\Configuration::General()->distanceUnitSystem()->distanceUnit() . '</th> <th>Ø ' . __('Pace') . '</th> <th class="{sorter: \'distance\'} small"><small>' . __('max.') . '</small> ' . Runalyze\Configuration::General()->distanceUnitSystem()->distanceUnit() . '</th> <th class="small"><small>' . __('min.') . '</small> ' . __('Pace') . '</th> <th class="{sorter: \'resulttime\'}">' . __('Time') . '</th> <th class="{sorter: \'distance\'}">' . __('Distance') . '</th> <th>' . __('Notes') . '</th> </tr> </thead> <tbody>'; if (!empty($this->Equipment)) { foreach ($this->Equipment as $data) { $Object = new Model\Equipment\Object($data); $in_use = $Object->isInUse() ? '' : ' unimportant'; $Pace = new Pace($Object->duration(), $Object->distance()); $MaxPace = new Pace($data['pace_in_s'], 1); echo '<tr class="' . $in_use . ' r" style="position: relative"> <td class="small">' . $data['num'] . 'x</td> <td class="b l">' . SearchLink::to('equipmentid', $Object->id(), $Object->name()) . '</td> <td class="small">' . $this->formatData($Object->startDate()) . '</td> <td>' . ($data['num'] != 0 ? Distance::format($Object->distance() / $data['num']) : '-') . '</td> <td>' . ($Object->duration() > 0 ? $Pace->asMinPerKm() . '/km' : '-') . '</td> <td class="small">' . Distance::format($data['dist']) . '</td> <td class="small">' . $MaxPace->asMinPerKm() . '/km' . '</td> <td>' . Duration::format($Object->duration()) . '</td> <td>' . Distance::format($Object->totalDistance()) . '</td> <td class="small">' . $Object->notes() . '</td> </tr>'; } } else { echo '<tr><td colspan="9">' . __('You don\'t have any shoes') . '</td></tr>'; } echo '</tbody>'; echo '</table>'; Ajax::createTablesorterFor("#list-of-all-equipment", true); }