Beispiel #1
0
 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());
 }
Beispiel #2
0
 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());
 }
 /**
  * Parse post data for equipment
  */
 protected function parsePostDataForSingleEquipment()
 {
     $DB = DB::getInstance();
     $accountId = SessionAccountHandler::getId();
     $Equipments = $this->Model->allEquipments();
     $Equipments[] = new Equipment\Entity();
     foreach ($Equipments as $Equipment) {
         $isNew = !$Equipment->hasID();
         $id = $isNew ? -1 : $Equipment->id();
         $AdditionalDistance = new Distance();
         $AdditionalDistance->setInPreferredUnit($_POST['equipment']['additional_km'][$id]);
         $NewEquipment = clone $Equipment;
         $NewEquipment->set(Equipment\Entity::NAME, $_POST['equipment']['name'][$id]);
         $NewEquipment->set(Equipment\Entity::TYPEID, (int) $_POST['equipment']['typeid'][$id]);
         $NewEquipment->set(Equipment\Entity::ADDITIONAL_KM, $AdditionalDistance->kilometer());
         $NewEquipment->set(Equipment\Entity::DATE_START, $this->stringToDatetime($_POST['equipment']['date_start'][$id]));
         $NewEquipment->set(Equipment\Entity::DATE_END, $this->stringToDatetime($_POST['equipment']['date_end'][$id]));
         $NewEquipment->set(Equipment\Entity::NOTES, $_POST['equipment']['notes'][$id]);
         if ($isNew) {
             if ($NewEquipment->name() != '') {
                 $Inserter = new Equipment\Inserter($DB, $NewEquipment);
                 $Inserter->setAccountID($accountId);
                 $Inserter->insert();
             }
         } elseif (isset($_POST['equipment']['delete'][$id])) {
             $DB->deleteByID('equipment', (int) $id);
         } else {
             $Updater = new Equipment\Updater($DB, $NewEquipment, $Equipment);
             $Updater->setAccountID($accountId);
             $Updater->update();
         }
     }
     $this->Model->clearCache('equipment');
 }