Ejemplo n.º 1
0
 /**
  * TODO: Améliorer la gestion des max_execution_time
  * Create data lines from XML to Nested Tree.
  *
  * @param $file
  * @param null $root_data_line
  * @throws Exception
  */
 public function createDataLines($file, $root_data_line = null)
 {
     $maxExecutionTime = ini_get("max_execution_time");
     set_time_limit(0);
     $this->save();
     $xml = new DOMDocument();
     if (is_file($file) && @$xml->load($file) === false || !is_file($file) && is_string($file) && @$xml->loadXML($file) === false) {
         throw new Exception('Your XML file seems to be corrupted. Please check the syntax.');
     }
     //récupération de la racine.
     $root = $xml->documentElement;
     $root_data_line = $root_data_line === null ? $this->createRootDataLine() : $root_data_line;
     //**************************************************//
     //***   ETAPE 1 : Récupération de la Structure   ***//
     //**************************************************//
     /** @var EiDataSetStructure[] $ei_dataset_structures */
     $ei_dataset_structures = $this->tableStructure->createQuery('str')->where("str.ei_scenario_id =  ?", $this->root_str->getEiScenarioId())->fetchArray();
     //********************************************//
     //***   ETAPE 2 : Analyse du fichier XML   ***//
     //********************************************//
     $compteur = 1;
     $index = 0;
     $listeElts = array();
     $this->evaluateDataLines($listeElts, $compteur, $index, $ei_dataset_structures, $root);
     //************************************//
     //***   ETAPE 4 : Calcul des IDs   ***//
     //************************************//
     /** @var EiDataLineTable $DataLinesTable */
     $DataLinesTable = Doctrine_Core::getTable("EiDataLine");
     $conn = Doctrine_Manager::connection();
     // On retire le root.
     $rootTab = array_shift($listeElts);
     $conn->beginTransaction();
     $DataLinesTable->insertDataLinesFromTab($listeElts, $root_data_line->getId(), $this->getId(), $conn);
     $root_data_line->setRgt($rootTab["rgt"]);
     $root_data_line->save($conn);
     $conn->commit();
     set_time_limit($maxExecutionTime);
 }