/**
  * Permet de définir si le formulaire de paramètre pour les versions est valide ou non
  * @param type $values
  * @return type
  * @throws sfValidatorErrorSchema 
  */
 protected function doClean($values)
 {
     $errorSchema = new sfValidatorErrorSchema($this);
     $name = MyFunction::sluggifyForXML($values['name']);
     $id = isset($values["id"]) ? $values["id"] : -1;
     /** @var EiVersionStructureTable $tableVersionStr */
     $tableVersionStr = Doctrine_Core::getTable("EiVersionStructure");
     if ($this->str->getEiVersionStructureParentId()) {
         $existing = $tableVersionStr->findByEiVersionStructureParentIdAndSlug($this->str->getEiVersionStructureParentId(), $name);
         /** @var Doctrine_Collection $existing */
         if ($existing->count() > 0 && $this->isNew == false) {
             // On retire l'élément si présent dans la liste.
             foreach ($existing as $key => $elt) {
                 if ($elt->getId() == $this->str->getId()) {
                     $existing->remove($key);
                 }
             }
         }
     } else {
         $existing = $tableVersionStr->findByEiVersionStructureParentIdAndSlug("is null", $name);
     }
     $count = $existing->count();
     if ($count > 0 && $this->isNew || $count >= 1 && !$this->isNew) {
         $errorSchema->addError(new sfValidatorError($this, 'name'), 'name');
     }
     // ON VERIFIE S'IL S'AGIT D'UN BLOC FOREACH QU'UN NOEUD SOIT RENSEIGNE.
     if ($this->str instanceof EiBlockForeach) {
         if (isset($values["Iterator"]) && $values["Iterator"] != null && isset($values["Iterator"]["ei_dataset_structure_id"])) {
             $idNode = $values["Iterator"]["ei_dataset_structure_id"];
             /** @var EiNodeDataSet $node */
             $node = Doctrine_Core::getTable("EiNodeDataSet")->find($idNode);
             if (!$node) {
                 $errorSchema->addError(new sfValidatorError($this, 'iterator_invalid'), 'iterator');
             } elseif (!($node->getType() == EiDataSetStructure::$TYPE_NODE && !$node->isRoot())) {
                 $errorSchema->addError(new sfValidatorError($this, 'iterator_type_invalid'), 'iterator');
             }
         } else {
             $errorSchema->addError(new sfValidatorError($this, 'iterator_empty'), 'iterator');
         }
     }
     // si l'on a trouvé des erreurs, alors on transmet une exception
     if (count($errorSchema)) {
         throw new sfValidatorErrorSchema($this, $errorSchema);
     }
     return $values;
 }
 /**
  * @param EiVersionStructure $parent
  * @return $this
  */
 public function getCommonParent(EiVersionStructure $parent)
 {
     if ($parent->getId() == $this->getEiVersionStructureId()) {
         return $this;
     } elseif ($this->getEiTestSetBlockStackParent() != null) {
         return $this->getEiTestSetBlockStackParent()->getCommonParent($parent);
     } else {
         return null;
     }
 }
 /**
  * Méthode permettant de localiser la partie du JDD à lier à l'élément du block.
  *
  * TODO: Unifier les deux méthodes en une seule.
  * TODO: A vérifier
  *
  * Liée à EiTestSetBlockStack->getDataFromDataSet
  *
  * @param EiTestSet $testSet
  * @param EiVersionStructure $block
  * @param EiTestSetBlockStack $previousStack
  * @param EiTestSetBlockStack $parentStack
  * @return mixed|null
  */
 public function getDataFromDataSet(EiTestSet $testSet, EiVersionStructure $block, EiTestSetBlockStack $previousStack = null, EiTestSetBlockStack $parentStack = null)
 {
     /** @var EiTestSetDataSetTable $tableDSS */
     $tableDSS = Doctrine_Core::getTable("EiTestSetDataSet");
     $mapping = $block->getMappingDataSet(EiBlockDataSetMapping::$TYPE_IN);
     $dssStr = null;
     // Cas où il y a un mapping et que le parent est nul : On prend le premier élément que l'on trouve.
     if ($parentStack == null && $mapping != null) {
         $dssStr != null ? $tableDSS->getRelatedDataFromUniqueDataSetStructure($testSet->getId(), $mapping) : null;
     } elseif ($mapping != null) {
         // On vérifie que le block en question est une boucle.
         if ($block->isEiLoop()) {
             // On récupère le contexte du père.
             $contexte = $parentStack->getContext();
             $index = 1;
             //                var_dump("DataSet Père : " . $parentStack->getEiTestSetDatasetId());
             //                var_dump("Contexte DataSet Père : " . $contexte);
             // Si le block courant est de même nature que le block précédent
             if ($parentStack->getEiVersionStructureId() != $block->getId() && $block->getId() == $previousStack->getEiVersionStructureId()) {
                 //                    var_dump("DataSet Structure CAS 1");
                 // On vérifie s'il s'agit de la même boucle mais concerne une partie différente.
                 if ($previousStack->getPartIndex() < $previousStack->getPartsCount()) {
                     $index = $previousStack->getRepetitionIndex();
                     $contexte .= "-" . $index;
                 } else {
                     $index = $previousStack->getRepetitionIndex() + 1;
                     $contexte .= "-" . $index;
                 }
             } elseif ($parentStack->getEiVersionStructureId() != $block->getId()) {
                 //                    var_dump("DataSet Structure CAS 2");
                 $parentStr = $parentStack->getEiTestSetDataSet() != null ? $parentStack->getEiTestSetDataSet()->getEiDataSetStructure() : null;
                 if ($parentStr != null && $mapping->getEiDataSetStructureMapping()->getNode()->isDescendantOf($parentStr)) {
                     //                        var_dump("DataSet Structure CAS 2.1");
                     $parentMapping = $parentStr != null ? $parentStr->getId() : null;
                     $myMappingParent = $mapping->getEiDataSetStructureMapping()->getEiDatasetStructureParentId();
                     if ($parentMapping == null || $myMappingParent == $parentMapping) {
                         $contexte .= "-1";
                     } else {
                         if (preg_match("/([0-9]+)\$/", $contexte, $matched)) {
                             $length = strlen($matched[1]);
                         } else {
                             $length = 1;
                         }
                         $contexte = substr($contexte, 0, -$length) . 1;
                     }
                 } else {
                     //                        var_dump("DataSet Structure CAS 2.2");
                     $contexteArray = array();
                     for ($cpt = 0; $cpt <= $mapping->getEiDataSetStructureMapping()->getLevel(); $cpt++) {
                         $contexteArray[] = 1;
                     }
                     $contexte = implode("-", $contexteArray);
                     //                        var_dump("New context : " . $contexte);
                 }
             } else {
                 //                    var_dump("DataSet Structure CAS 3");
                 if (preg_match("/([0-9]+)\$/", $contexte, $matched)) {
                     $length = strlen($matched[1]);
                 } else {
                     $length = 1;
                 }
                 $contexte = substr($contexte, 0, -$length);
                 // On vérifie s'il s'agit de la même boucle mais concerne une partie différente.
                 if (!$parentStack->isComplete()) {
                     $index = $parentStack->getRepetitionIndex();
                 } else {
                     $index = $parentStack->getRepetitionIndex() + 1;
                 }
                 $contexte .= $index;
                 //                    var_dump($parentStack->getEiVersionStructureId(), $block->getId());
                 //                    var_dump($contexte);
             }
             $dssStr = $tableDSS->getDataFromContext($testSet->getId(), $mapping->getEiDatasetStructureId(), $contexte, $index);
         }
     }
     return $dssStr;
 }
Beispiel #4
0
 /**
  * @param EiVersion $copie
  * @param Doctrine_Connection $conn
  * @param null $ei_scenario_id
  * @param array $allowedTypes
  * @return EiVersion
  * @throws Exception
  */
 public function createStructureCopy(EiVersion $copie, Doctrine_Connection $conn = null, $ei_scenario_id = null, array $allowedTypes = array())
 {
     /** @var sfLogger $logger */
     $logger = sfContext::getInstance()->getLogger();
     // Déclaration de la table EiVersionStructure.
     /** @var EiVersionStructureTable $tableVersionStr */
     $tableVersionStr = Doctrine_Core::getTable('EiVersionStructure');
     // Tableau des correspondances.
     $correspondances = array();
     $correspondancesF = array();
     $version_id = $this->old_version_id == false ? $this->getId() : $this->old_version_id;
     $allowedTypes = count($allowedTypes) == 0 ? EiVersionStructure::getAllTypes() : $allowedTypes;
     $ignored = 0;
     //*******************************************************//
     //**********          COPIE STRUCTURE          **********//
     //*******************************************************//
     $logger->info("--------------------------------------------");
     $logger->info("----------     COPIE SCENARIO     ----------");
     $logger->info("--------------------------------------------");
     // Création d'une collection de structure de version.
     /** @var Doctrine_Collection $nouvelleStructure */
     $nouvelleStructure = new Doctrine_Collection('EiVersionStructure');
     // Variable temporaire contenant le noeud père.
     /** @var EiVersionStructure $ei_version_str_prec */
     $ei_version_str_prec = null;
     // Variable temporaire contenant le niveau où l'on se situait dans l'arbre à la boucle précédente.
     $level_prec = 0;
     // Variables temporaires.
     /** @var EiVersionStructure $parent */
     $root_id = $parent = null;
     // On récupère la structure complète de la version actuelle.
     $currentVersionTree = $tableVersionStr->getEiVersionTree($version_id, $allowedTypes);
     // On parcourt chaque élément.
     /** @var EiVersionStructure $ei_version_str */
     foreach ($currentVersionTree as $i => $ei_version_str) {
         $logger->info("----------     PARCOURS ELT STRUCTURE N° " . $ei_version_str->getId() . "     ----------");
         if (in_array($ei_version_str->getType(), $allowedTypes)) {
             //*************************************************************//
             //**********          DETERMINATION DU PERE          **********//
             //*************************************************************//
             // Si le niveau précédent est inférieur au niveau parcouru, alors, le parent est la dernière version structure.
             if ($ei_version_str->getLevel() > $level_prec) {
                 $parent = $ei_version_str_prec;
             } elseif ($ei_version_str->getLevel() < $level_prec) {
                 // On réalise la différence entre les deux niveau.
                 $j = $level_prec - $ei_version_str->getLevel();
                 // On remonte d'autant de fois afin de récupérer le père.
                 while ($j > 0) {
                     $parent = $parent->getNode()->getParent();
                     $j--;
                 }
             }
             //*******************************************************************************//
             //**********          ENREGISTREMENT DES INFORMATIONS DE BASE          **********//
             //*******************************************************************************//
             $strElementCopie = new EiVersionStructure();
             $strElementCopie->setRootId($root_id);
             $strElementCopie->setLft($ei_version_str->getLft());
             $strElementCopie->setRgt($ei_version_str->getRgt());
             $strElementCopie->setLevel($ei_version_str->getLevel());
             $strElementCopie->setName($ei_version_str->getName());
             $strElementCopie->setDescription($ei_version_str->getDescription());
             $strElementCopie->setSlug($ei_version_str->getSlug());
             $strElementCopie->setEiVersion($copie);
             $strElementCopie->setType($ei_version_str->getType());
             // Si l'élément possède un père, on le précise.
             if ($parent) {
                 $strElementCopie->setEiVersionStructureParentId($parent->getId());
             }
             // On sauvegarde l'élément.
             $strElementCopie->save($conn);
             // Mise à jour du tableau des correspondances.
             $correspondances[$ei_version_str->getId()] = $strElementCopie->getId();
             //**********************************************************//
             //**********          CREATION FONCTION          ***********//
             //**********************************************************//
             // S'il s'agit d'une fonction, on crée la copie.
             if ($ei_version_str->isEiFonction()) {
                 $logger->info("----------     CREATION FONCTION     ----------");
                 $fct = $ei_version_str->getEiFonction()->createCopie($strElementCopie, $conn);
                 $strElementCopie->setEiFonctionId($fct->getId());
                 $correspondancesF[$ei_version_str->getEiFonctionId()] = $fct->getId();
             } elseif ($ei_version_str->isEiBlock()) {
                 $logger->info("----------     CREATION BLOCK     ----------");
                 $ei_version_str_prec = $strElementCopie;
             }
             $level_prec = $ei_version_str->getLevel();
             if ($i == 0) {
                 $root_id = $strElementCopie->getId();
                 $strElementCopie->setRootId($root_id);
                 $strElementCopie->save($conn);
             }
             $nouvelleStructure->add($strElementCopie);
         }
     }
     foreach ($currentVersionTree as $i => $ei_version_str) {
         //**********************************************************//
         //**********          CAS BLOCK FOREACH           **********//
         //**********************************************************//
         if ($ei_version_str->getType() == EiVersionStructure::$TYPE_FOREACH) {
             $logger->info("----------     CREATION FOREACH     ----------");
             /** @var EiMappingStructureSyncIn $oldMapping */
             $oldMapping = $ei_version_str->getEiVersionStructureDataSetMapping()->getFirst();
             $mapping = new EiMappingStructureSyncIn();
             $mapping->setEiDatasetStructureId($oldMapping->getEiDatasetStructureId());
             $mapping->setEiVersionStructureId($correspondances[$ei_version_str->getId()]);
             $mapping->save($conn);
         } elseif ($ei_version_str->isEiBlockParam()) {
             $logger->info("----------     CREATION BLOCK PARAM     ----------");
             // Copie des mappings IN et OUT.
             /** @var EiBlockDataSetMapping $oldMappingIn */
             $oldMappingIn = $ei_version_str->getMappingDataSet(EiBlockDataSetMapping::$TYPE_IN);
             /** @var EiBlockDataSetMapping $oldMappingOut */
             $oldMappingOut = $ei_version_str->getMappingDataSet(EiBlockDataSetMapping::$TYPE_OUT);
             if ($oldMappingIn != null) {
                 $logger->info("----------     MAPPING IN :  " . $oldMappingIn->getEiDatasetStructureId() . " / " . $correspondances[$ei_version_str->getId()] . "    ----------");
                 $newMappingIn = new EiMappingStructureSyncIn();
                 $newMappingIn->setEiDatasetStructureId($oldMappingIn->getEiDatasetStructureId());
                 $newMappingIn->setEiVersionStructureId($correspondances[$ei_version_str->getId()]);
                 $newMappingIn->save($conn);
             }
             if ($oldMappingOut != null) {
                 $logger->info("----------     MAPPING OUT :  " . $oldMappingOut->getEiDatasetStructureId() . " / " . $correspondances[$ei_version_str->getId()] . "    ----------");
                 $newMappingOut = new EiMappingStructureSyncOut();
                 $newMappingOut->setEiDatasetStructureId($oldMappingOut->getEiDatasetStructureId());
                 $newMappingOut->setEiVersionStructureId($correspondances[$ei_version_str->getId()]);
                 $newMappingOut->save($conn);
             }
         } elseif ($ei_version_str->isEiFonction() && in_array($ei_version_str->getType(), $allowedTypes)) {
             $logger->info("----------     CREATION PARAM FONCTION     ----------");
             // Récupération de l'ensemble des paramètres OUT.
             /** @var EiParamBlockFunctionMapping[] $outParams */
             $outParams = $ei_version_str->getEiFonction()->getEiFunctionMapping();
             $logger->info("----------     " . count($outParams) . " PARAMS.");
             // Copie de chaque paramètre de mapping OUT.
             /** @var EiParamBlockFunctionMapping $oldMapping */
             foreach ($outParams as $oldMapping) {
                 if ($oldMapping->getEiFunctionId() != "" && $oldMapping->getEiParamFunctionId() != "") {
                     /** @var EiParamBlockFunctionMapping $mapping */
                     $mapping = new EiParamBlockFunctionMapping();
                     $mapping->setEiParamBlockId($oldMapping->getEiParamBlockId() == "" ? null : $correspondances[$oldMapping->getEiParamBlockId()]);
                     $mapping->setEiFunctionId($correspondancesF[$oldMapping->getEiFunctionId()]);
                     $mapping->setEiParamFunctionId($oldMapping->getEiParamFunctionId());
                     $mapping->save($conn);
                 }
             }
         } elseif (!in_array($ei_version_str->getType(), $allowedTypes)) {
             $ignored++;
         }
     }
     // On affecte à la copie la structure complète.
     $copie->setEiVersionStructures($nouvelleStructure);
     // Sauvegarde de la copie de version.
     $copie->save($conn);
     //*****************************************************//
     //**********          VERIFICATIONS          **********//
     //*****************************************************//
     // On récupère l'arbre de la structure de la copie.
     $arbreNouvelleVersion = $tableVersionStr->getEiVersionTree($copie->getId());
     // On vérifie que le nombre d'éléments est le même de chaque côté sinon on lève une exception.
     if (count($currentVersionTree) != count($arbreNouvelleVersion) + $ignored) {
         throw new Exception('Version copie failed');
     }
     return $copie;
 }
 /**
  * @param EiTestSet $testSet
  * @param EiVersionStructure $block
  * @return mixed|null
  *
  * @createdAt 18/08/2015
  * @updatedAt 18/08/2015
  */
 public function getParentBlock($testSet, $block)
 {
     // Récupération de la connexion BDD.
     $conn = Doctrine_Manager::connection();
     try {
         // Définition requête SQL permettant de générer
         $searchSql = "\nSELECT id\nFROM " . $this->getTableName() . "\nWHERE ei_version_structure_id = " . $block->getId() . "\nAND ei_test_set_id = " . $testSet->getId() . "\nORDER BY lft DESC\nLIMIT 1;";
         // Récupération du block parent.
         $blockId = $conn->execute($searchSql)->fetch();
         if (!is_bool($blockId) && isset($blockId["id"])) {
             return $this->find($blockId["id"]);
         }
     } catch (Exception $exc) {
         return null;
     }
 }
 /**
  * @param EiBlockParam[] $parametres
  */
 private function proceedStep2_2(array $parametres)
 {
     // Déclaration des variables contenant la liste des scénario structure parents manipulés et versions.
     /** @var EiVersionStructure[] $parentsVersion */
     $parentsVersion = array();
     $last = array();
     foreach ($parametres as $param) {
         // On récupère la version parente.
         /** @var EiVersionStructure $versionStrParente */
         $versionStrParente = Doctrine_Core::getTable("EiVersionStructure")->find($param["vs_id"]);
         $parentsVersion[$versionStrParente->getId()][] = $param["id"];
         // Création du paramètre.
         $paramVersion = new EiVersionStructure();
         $paramVersion->setType(EiVersionStructure::$TYPE_BLOCK_PARAM);
         $paramVersion->setEiVersionId($versionStrParente->getEiVersionId());
         $paramVersion->setEiVersionStructureParentId($versionStrParente->getId());
         $paramVersion->setName($param["name"]);
         $paramVersion->setDescription($param["description"]);
         $paramVersion->save();
         $req = "UPDATE ei_version_structure SET ei_scenario_structure_id = " . $param["id"] . " WHERE id = " . $paramVersion->getId() . ";";
         $this->connexion->execute($req);
         $this->displayResultStep("Création du paramètre " . $param["name"] . " pour la version " . $versionStrParente->getEiVersionId());
         if (count($parentsVersion[$versionStrParente->getId()]) == 1) {
             $paramVersion->getNode()->insertAsFirstChildOf($versionStrParente);
         } else {
             $paramVersion->getNode()->insertAsNextSiblingOf($last[$versionStrParente->getId()]);
         }
         $last[$versionStrParente->getId()] = $paramVersion;
     }
 }