Exemplo n.º 1
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();
                 }
             }
         }
     }
 }