コード例 #1
0
ファイル: InserterTest.php プロジェクト: 9x/Runalyze
 public function testSimpleInsert()
 {
     $Type = new Object(array(Object::NAME => 'Equipment type name', Object::INPUT => 0, Object::MAX_KM => 100, Object::MAX_TIME => 0));
     $Inserter = new Inserter($this->PDO, $Type);
     $Inserter->setAccountID(1);
     $Inserter->insert();
     $data = $this->PDO->query('SELECT * FROM `' . PREFIX . 'equipment_type` WHERE `accountid`=1')->fetch(PDO::FETCH_ASSOC);
     $New = new Object($data);
     $this->assertEquals('Equipment type name', $New->name());
     $this->assertFalse($New->allowsMultipleValues());
     $this->assertTrue($New->hasMaxDistance());
     $this->assertEquals(100, $New->maxDistance());
     $this->assertFalse($New->hasMaxDuration());
     $this->assertEquals(0, $New->maxDuration());
 }
コード例 #2
0
ファイル: UpdaterTest.php プロジェクト: 9x/Runalyze
 public function testSimpleUpdate()
 {
     $Inserter = new Inserter($this->PDO);
     $Inserter->setAccountID(1);
     $Inserter->insert(new Object(array(Object::NAME => 'Equipment type name', Object::INPUT => 1, Object::MAX_KM => 100, Object::MAX_TIME => 0)));
     $Type = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'equipment_type` WHERE `id`=' . $Inserter->insertedID())->fetch(PDO::FETCH_ASSOC));
     $Type->set(Object::INPUT, 0);
     $Changed = clone $Type;
     $Changed->set(Object::MAX_TIME, 500);
     $Updater = new Updater($this->PDO, $Changed, $Type);
     $Updater->setAccountID(1);
     $Updater->update();
     $Result = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'equipment_type` WHERE `id`=' . $Inserter->insertedID())->fetch(PDO::FETCH_ASSOC));
     $this->assertEquals('Equipment type name', $Result->name());
     $this->assertTrue($Result->allowsMultipleValues());
     $this->assertTrue($Result->hasMaxDistance());
     $this->assertTrue($Result->hasMaxDuration());
     $this->assertEquals(100, $Result->maxDistance());
     $this->assertEquals(500, $Result->maxDuration());
 }
コード例 #3
0
    /**
     * @param \Runalyze\Model\EquipmentType\Object $EquipmentType
     * @param boolean $inuse
     */
    protected function showListFor(Model\EquipmentType\Object $EquipmentType, &$inuse)
    {
        $max = 0;
        $showDistance = $EquipmentType->hasMaxDistance();
        $hasMaxDuration = $showDistance || $EquipmentType->hasMaxDuration();
        $allEquipment = DB::getInstance()->query('SELECT * FROM `' . PREFIX . 'equipment` WHERE `typeid`="' . $EquipmentType->id() . '" AND `accountid`="' . SessionAccountHandler::getId() . '" ORDER BY ISNULL(`date_end`) DESC, `distance` DESC')->fetchAll();
        foreach ($allEquipment as $data) {
            $Object = new Model\Equipment\Object($data);
            $Distance = new Distance($Object->totalDistance());
            $Duration = new Duration($Object->duration());
            if ($inuse && !$Object->isInUse()) {
                echo '<div id="hiddenequipment" style="display:none;">';
                $inuse = false;
            }
            if ($max == 0) {
                $max = $Object->duration();
            }
            echo '<p style="position:relative;">
				<span class="right">' . ($showDistance ? $Distance->string() : $Duration->string()) . '</span>
				<strong>' . SearchLink::to('equipmentid', $Object->id(), $Object->name()) . '</strong>
				' . $this->getUsageImage($showDistance ? $Object->totalDistance() / $EquipmentType->maxDistance() : $Object->duration() / ($hasMaxDuration ? $EquipmentType->maxDuration() : $max)) . '
			</p>';
        }
        if (empty($allEquipment)) {
            echo HTML::em(__('You don\'t have any equipment'));
        }
        if (!$inuse) {
            echo '</div>';
        }
    }
コード例 #4
0
ファイル: Updater.php プロジェクト: 9x/Runalyze
 /**
  * Keys to insert
  * @return array
  */
 protected function keys()
 {
     return array_merge(array(self::ACCOUNTID), Object::allDatabaseProperties());
 }