Пример #1
0
 /**
  * REMOVE ENTITY
  *
  * @param \Berie\ORM\Entity $entity
  *
  * @return \Berie\ORM\Entity
  */
 public function remove(\Berie\ORM\Manager\Entity $entity)
 {
     $table = $entity->getPref()['params']['table'];
     $manager = new Manager($this->connect, $table);
     $manager->removeEntity($entity);
     return $entity;
 }
Пример #2
0
 function removeEntity(\Berie\ORM\Manager\Entity $entity)
 {
     $id = $entity->getPreference('id');
     $table = $entity->getPreference('table');
     $data = $entity->getData();
     if (!empty($id)) {
         (new \Berie\ORM\Builder($this->database))->delete()->from($table)->where('id', $id)->getQuery();
     }
     return;
 }
Пример #3
0
 public function managerPreSave(\Berie\ORM\Manager\Entity $entity)
 {
     $data = $entity->getData();
     $dataType = $entity->getPref()["dataType"];
     foreach ($data as $key => $value) {
         switch ($dataType[$key]["type"]["glob"]) {
             case "STRING":
                 if (is_array($value)) {
                     if ($dataType[$key]["type"]["sub"] === "TINYTEXT" || $dataType[$key]["type"]["sub"] === "TEXT" || $dataType[$key]["type"]["sub"] === "MEDIUMTEXT" || $dataType[$key]["type"]["sub"] === "LONGTEXT") {
                         $data[$key] = @serialize($value);
                     } else {
                         // exception serialize array
                     }
                 }
                 break;
             case "DATETIME":
                 if (is_object($value) && get_class($value) === "DateTime") {
                     if ($dataType[$key]["type"]["sub"] === "DATE") {
                         $data[$key] = $value->format("Y-m-d");
                     } elseif ($dataType[$key]["type"]["sub"] === "DATETIME") {
                         $data[$key] = $value->format("Y-m-d H:i:s");
                     } elseif ($dataType[$key]["type"]["sub"] === "TIMESTAMP") {
                         $data[$key] = $value->format("U");
                     } elseif ($dataType[$key]["type"]["sub"] === "TIME") {
                         $data[$key] = $value->format("H:i:s");
                     } elseif ($dataType[$key]["type"]["sub"] === "YEAR") {
                         $data[$key] = $value->format("Y");
                     }
                 } else {
                     if (\DateTime::createFromFormat("Y-m-d", $value) || \DateTime::createFromFormat("Y-m-d H:i:s", $value) || \DateTime::createFromFormat("U", $value) || \DateTime::createFromFormat("H:i:s", $value) || \DateTime::createFromFormat("Y", $value)) {
                         $data[$key] = $value;
                     } else {
                         // exception not datetime
                     }
                 }
                 break;
         }
     }
     return $data;
 }