Exemple #1
0
 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());
 }
 /**
  * Parse post data for equipment types
  */
 protected function parsePostDataForEquipmentTypes()
 {
     $DB = DB::getInstance();
     $accountId = SessionAccountHandler::getId();
     $Types = $this->Model->allEquipmentTypes();
     $Types[] = new EquipmentType\Entity();
     foreach ($Types as $Type) {
         $isNew = !$Type->hasID();
         $id = $isNew ? -1 : $Type->id();
         $MaxTime = new Duration($_POST['equipmenttype']['max_time'][$id]);
         $MaxDistance = new Distance();
         $MaxDistance->setInPreferredUnit($_POST['equipmenttype']['max_km'][$id]);
         $NewType = clone $Type;
         $NewType->set(EquipmentType\Entity::NAME, $_POST['equipmenttype']['name'][$id]);
         $NewType->set(EquipmentType\Entity::INPUT, (int) $_POST['equipmenttype']['input'][$id]);
         $NewType->set(EquipmentType\Entity::MAX_KM, $MaxDistance->kilometer());
         $NewType->set(EquipmentType\Entity::MAX_TIME, $MaxTime->seconds());
         if ($isNew) {
             if ($NewType->name() != '') {
                 $Inserter = new EquipmentType\Inserter($DB, $NewType);
                 $Inserter->setAccountID($accountId);
                 $Inserter->insert();
                 $RelationUpdater = new EquipmentType\RelationUpdater($DB, $Inserter->insertedID());
                 $RelationUpdater->update($_POST['equipmenttype']['sportid'][$id]);
             }
         } elseif (isset($_POST['equipmenttype']['delete'][$id])) {
             $DB->deleteByID('equipment_type', (int) $id);
         } else {
             $Updater = new EquipmentType\Updater($DB, $NewType, $Type);
             $Updater->setAccountID($accountId);
             $Updater->update();
             $RelationUpdater = new EquipmentType\RelationUpdater($DB, $Type->id());
             $RelationUpdater->update($_POST['equipmenttype']['sportid'][$id], explode(',', $_POST['equipmenttype']['sportid_old'][$id]));
         }
     }
     $this->Model->clearCache('equipment_type');
 }