/**
  * check if values $_REQUEST[''] exist then - get thing by id(existing thing)
  * if values not exist then create a new thing and assigns to the friend whose id is set
  * @return array
  */
 protected function run()
 {
     if (array_key_exists('id', $_REQUEST) and $_REQUEST['id'] > 0) {
         $thing = Things::getThingByID($_REQUEST['id']);
     } else {
         $thing = new Thing();
         $thing->setFriendID($_REQUEST['friendid']);
     }
     /**
      * if $_POST_[""] is not empty then set the values into the template
      * else set error massage if one of the $_POST[""] is empty
      */
     if (!empty($_POST["description"]) and !empty($_POST["statebeforelent"])) {
         $thing->setDescription($_POST["description"]);
         $thing->setStateBeforeLent($_POST["statebeforelent"]);
         $thing->setDateOfLent(date('Y-m-d'));
         /**
          * records can be saved after editing or creating
          * exit the program after a successful storage
          * error massage when one of the $_POST fields is empty
          */
         if ($thing->save()) {
             header('location:index.php?module=lentthingslist&friendid=' . $thing->getFriendId());
             exit;
         } else {
             $var = array('fehler' => "Etwas stimmt mit der Eingabe nicht!");
         }
     } elseif (!empty($_POST["description"]) or !empty($_POST["statebeforelent"])) {
         $var = array('fehler' => "Es sind nicht alle Datenfelder ausgefüllt");
     }
     $var['thing'] = $thing;
     return $var;
 }
Ejemplo n.º 2
0
 protected function syncChildren($thingName, $member, $parent)
 {
     if (!isset($parent[$member])) {
         throw new DumbassDeveloperException($member . " is not a child member of given parent");
     }
     $channel = Channel::Shopify;
     $children = $parent[$member];
     $parentThing = Thing::loadByAltId($parent["id"]);
     foreach ($children as $child) {
         $id = $child['id'];
         $thingChild = null;
         try {
             $thingChild = Thing::loadByAltId($id);
         } catch (InstanceNotFoundException $ex) {
             //create a thing for the top level product
             $thingChild = new Thing();
             $thingChild->setAltid($id);
             $thingChild->setName($thingName);
             $thingChild->setChannel($channel);
             $thingChild->setThing($parentThing);
             //set the parent of the child thing
             $thingChild->save();
         }
         //all data associated to the child
         $thingData_raw = $thingChild->getData();
         //indexed numerically
         //make array indexed by key
         $thingDatas = array();
         //indexed by key
         foreach ($thingData_raw as $thingData) {
             $thingDatas[$thingData->getKey()] = $thingData;
         }
         foreach ($child as $key => $value) {
             //create a new data if not exist in thingData
             if (!isset($thingDatas[$key])) {
                 $data = new Data();
                 $data->setKey($key);
                 $data->setValue($value);
                 $data->setThing($thingChild);
                 $data->save();
             } else {
                 $dbData = $thingDatas[$key];
                 if ($dbData->getValue() != $value) {
                     $dbData->setValue($value);
                     $dbData->save();
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 public function testGetById()
 {
     $thing = new Thing();
     $thing->name = "sean";
     $thing->save();
     $qo = Thing::Q()->getById($thing->id);
     $t = $qo->exec();
     $this->assertTrue(is_a($t, 'Thing'));
     $this->assertEquals($thing->id, $t->id);
 }