Exemplo n.º 1
0
 private function _insert()
 {
     $dateNow = date('Y-m-d H:i:s', time());
     $sql = '
             INSERT INTO animals (category, subcategory, name, description, eat, date_created)
             VALUES (:category, :subcategory, :name, :description, :eat, :date_created) ';
     $params = array('category' => $this->_category, 'subcategory' => $this->_subcategory, 'name' => $this->_name, 'description' => $this->_description, 'eat' => $this->_eat, 'date_created' => $dateNow);
     self::$db->prepare($sql, $params)->execute();
     if (self::$db->getAffectedRows() > 0) {
         $this->id = self::$db->getLastInsertId();
         $animal = new \models\Animal($this->id);
         if ($animal->setId($this->id)->save()) {
             return true;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * White information from XML files to database 
  */
 public function writeXMLInDB()
 {
     if ($this->isDerectory()) {
         $dirTree = $this->getXMLPaths($this->_dir_path);
         foreach ($dirTree as $value) {
             $xml_content = simplexml_load_file($value);
             foreach ($xml_content as $key => $value) {
                 $is_exist = \models\Animal::getAnimals(array('name' => $value->name));
                 if ($is_exist) {
                     //update
                     $animal_id = key($is_exist);
                     $animal = new \models\Animal($animal_id);
                     $animal->setCategory($value->category);
                     $animal->setSubcategory($value->subcategory);
                     $animal->setName($value->name);
                     $animal->setDescription($value->description);
                     $animal->setEat($value->eat);
                     $animal->save();
                 } else {
                     //new animal
                     $animal = new \models\Animal();
                     $animal->setCategory($value->category);
                     $animal->setSubcategory($value->subcategory);
                     $animal->setName($value->name);
                     $animal->setDescription($value->description);
                     $animal->setEat($value->eat);
                     $animal->save();
                 }
             }
         }
     }
 }