/** * @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; } }
/** * 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; }
/** * Ajouter une fonction à une version/sous_version * @author Grégory Elhaimer * @param sfWebRequest $request * @return type */ public function executeAjouter(sfWebRequest $request) { $this->getUrlParameters($request); $this->checkProject($request); $this->checkProfile($request, $this->ei_project); //Récupération du profil $this->forward404Unless($this->ei_version, "Version not found."); $this->checkFunction($request, $this->ei_project); $this->forward404Unless($this->kal_function); /* Récupération du User courant et du package par défaut */ $this->defaultPackage = $this->getDefaultPackage($this->ei_user, $this->ei_project); $function_ref = $request->getParameter('function_ref'); $function_id = $request->getParameter('function_id'); $subjectFunctions = array(); /* Récupération d'une liaison éventuelle liaison existente entre la fonction et le bug */ if ($function_id != null && $function_ref != null && $this->defaultPackage != null) { /* Recherche du sujet par rapport au package par défaut. * Ici, on vérifie que plusieurs bugs ne sont pas associés au même package , auquel cas on déclenche un exception pour contacter l'administrateur . */ $this->defaultPackageSubjects = Doctrine_Core::getTable('EiSubject')->findByPackageIdAndPackageRefAndProjectIdAndProjectRef($this->defaultPackage->getTicketId(), $this->defaultPackage->getTicketRef(), $this->ei_project->getProjectId(), $this->ei_project->getRefId()); if (count($this->defaultPackageSubjects) > 1) { //Plusieurs sujets avec la même intervention.On déclenche une alerte système. throw new Exception('Please contact administrator.There many intervention with the same package ...'); } elseif (count($this->defaultPackageSubjects) == 1) { $this->ei_subject = $this->defaultPackageSubjects->getFirst(); $link = Doctrine_Core::getTable('EiSubjectFunctions')->findOneBySubjectIdAndFunctionIdAndFunctionRef($this->ei_subject->getId(), $function_id, $function_ref); if ($link != null) { $subjectFunctions[] = array('sf_subject_id' => $link->getSubjectId(), 'sf_function_id' => $link->getFunctionId(), 'sf_function_ref' => $link->getFunctionRef(), 'sf_automate' => $link->getAutomate()); } } } //création et initialisation de la fonction $ei_fonction = new EiFonction(); $ei_fonction->setName($this->kal_function->getNodeTree()->getName()); $ei_fonction->setProjectId($this->project_id); $ei_fonction->setProjectRef($this->project_ref); $ei_fonction->setFunctionId($this->kal_function->getFunctionId()); $ei_fonction->setFunctionRef($this->kal_function->getFunctionRef()); $ei_fonction->setSubjectFunctions($subjectFunctions); $this->ei_version_structure = Doctrine_Core::getTable('EiVersionStructure')->find($request->getParameter('ei_version_structure_id')); $this->forward404Unless($this->ei_version_structure && $this->ei_version_structure->getEiVersionId() == $this->ei_version->getId()); $ei_version_structure = new EiVersionStructure(); $ei_version_structure->setType('EiFonction'); $ei_version_structure->setEiVersion($this->ei_version); $ei_version_structure->setEiVersionStructureParentId($this->ei_version_structure->getId()); $ei_fonction->setEiVersionStructure($ei_version_structure); $ei_fonction = $ei_fonction->save(); if ($insert_after = $request->getParameter('insert_after')) { $aft_version = Doctrine_Core::getTable('EiVersionStructure')->find($insert_after); $this->forward404Unless($aft_version); $ei_version_structure->getNode()->insertAsNextSiblingOf($aft_version); } else { $ei_version_structure->getNode()->insertAsFirstChildOf($this->ei_version_structure); } $form = new EiFonctionForm($ei_fonction, array('params' => $ei_fonction->getEiParams(), 'mappings' => $ei_fonction->getEiFunctionMapping())); return $this->renderPartial('ajouterFonction', array('form' => $form, 'insert_after' => $ei_version_structure->getId(), 'obj' => $ei_fonction, 'paramsForUrl' => array('ei_version_id' => $this->ei_version->getId(), 'ei_version_structure_id' => $this->ei_version_structure->getId(), 'project_id' => $this->project_id, 'project_ref' => $this->project_ref, 'profile_id' => $this->profile_id, 'profile_ref' => $this->profile_ref, 'profile_name' => $this->profile_name, 'default_notice_lang' => $this->ei_project->getDefaultNoticeLang()))); }
/** * @param $versionId * @param $rgt * @param $level * @return bool */ public function isLast($versionId, $rgt, $level) { $lastElement = Doctrine_Query::create()->from('EiVersionStructure version')->andWhere('version.ei_version_id = ?', $versionId)->andWhereIn('version.type', EiVersionStructure::getBlockTypes())->andWhere("version.level = ?", $level)->orderBy('version.lft DESC')->limit(1)->fetchOne(); return $lastElement != null && $lastElement->getRgt() == $rgt ? true : false; }
/** * Méthode permettant de savoir si la sous-partie du block commence par un block ou non. * * @param EiTestSetBlockStack $stack * @param null $pIndex * @return bool */ public function firstFragmentElementIsFunction(EiTestSetBlockStack $stack = null, $pIndex = null) { $last = ""; $index = 1; $pIndex = $pIndex == null ? $stack->getPartIndex() : $pIndex; $res = $this->getNextVersionStructureFragmentsObjects($stack); // var_dump("Is Function ? "); // var_dump($pIndex . "/" . $stack->getPartsCount()); if (!is_bool($res)) { foreach ($res as $elt) { // var_dump("Index : " . $index); // var_dump($elt["type"] . " / " . $last); if ($pIndex == $index && !($elt["type"] == EiVersionStructure::$TYPE_FONCTION && $last == EiVersionStructure::$TYPE_FONCTION)) { // var_dump("CAS 1 : " . ($elt["type"] == EiVersionStructure::$TYPE_FONCTION ? 1:0)); return $elt["type"] == EiVersionStructure::$TYPE_FONCTION; } if (in_array($elt["type"], EiVersionStructure::getBlockTypes())) { // var_dump("CAS 2"); $index++; } elseif ($elt["type"] == EiVersionStructure::$TYPE_FONCTION && $last != EiVersionStructure::$TYPE_FONCTION) { // var_dump("CAS 3"); $index++; } $last = $elt["type"]; } } // exit; return false; }
/** * @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; } }
/** * Créer la version par defaut pour le scénario en cours de création et * en retourne son identifiant. * * @return integer */ public function createDefaultVersion(EiUserDefaultPackage $ei_user_default_package = null, Doctrine_Connection $conn = null) { if ($conn == null) { $conn = Doctrine_Manager::connection(); } //creation de la version par defaut du scénario $def_version = new EiVersion(); $def_version->ei_scenario_id = $this->getId(); $def_version->libelle = 'S' . $this->getId() . '-version1'; $def_version->save($conn); if ($ei_user_default_package != null) { //Création de la relation entre la version du scénario et le package $ei_scenario_package = new EiScenarioPackage(); $ei_scenario_package->setEiScenarioId($this->getId()); $ei_scenario_package->setPackageId($ei_user_default_package->getTicketId()); $ei_scenario_package->setPackageRef($ei_user_default_package->getTicketRef()); $ei_scenario_package->setEiVersionId($def_version->getId()); $ei_scenario_package->save($conn); } $ei_version_structure = new EiVersionStructure(); $ei_version_structure->setName("Root"); $ei_version_structure->setEiVersion($def_version); $ei_version_structure->setType(EiVersionStructure::$TYPE_BLOCK); $ei_version_structure->save($conn); $treeObject = Doctrine_Core::getTable('EiVersionStructure')->getTree(); $treeObject->createRoot($ei_version_structure); return $def_version->getId(); }
public function getPath() { return EiVersionStructure::getPath($this->getEiVersionStructure()); }
public function executeCreate(sfWebRequest $request) { $this->checkProject($request); $this->checkProfile($request, $this->ei_project); $this->checkEiScenario($request, $this->ei_project); /* On recherche le package par défaut. S'il n'est pas définit , on le spécifie à l'utilisateur au lieu de lui retourner le formulaire */ $this->searchDefPackAndRedirect(); if (!($request->isMethod(sfRequest::POST) || $request->isXmlHttpRequest())) { $this->forward404("Request error ..."); } //vérification des paramètres. $this->getUrlParameters($request); $this->ei_block_root = Doctrine_Core::getTable('EiBlock')->getEiBlockRoot($this->ei_scenario_id); if (!$this->ei_block_root) { return $this->createJSONErrorResponse("The version could not be created. Scenario's root block not found."); } $ei_blocks = Doctrine_Core::getTable('EiVersionStructure')->getEiBlocksTree($this->ei_block_root->getId(), EiVersionStructure::getBlockTypes()); //création de la version $ei_version = new EiVersion(); $ei_version->setEiScenarioId($this->ei_scenario_id); $ei_version->setEiScenarioBlocks($ei_blocks); $ei_version->setOldVersionId($this->ei_block_root->getEiVersionId()); $this->form = new EiVersionForm($ei_version, array('ei_scenario_package' => new EiScenarioPackage())); $ei_scenario_package_form = $request->getParameter($this->form->getName()); $ei_scenario_package_datas = $ei_scenario_package_form['ei_scenario_package']; if ($ei_scenario_package_datas['package_id'] != null && $ei_scenario_package_datas['package_ref'] != null) { $this->ei_package = Doctrine_core::getTable('EiTicket')->findOneByTicketIdAndTicketRef($ei_scenario_package_datas['package_id'], $ei_scenario_package_datas['package_ref']); /* On recherche si pour le package par défaut et le scénario , il existe une version */ $this->ei_scenario_package = Doctrine_Core::getTable('EiScenarioPackage')->findOneByEiScenarioIdAndPackageIdAndPackageRef($this->ei_scenario_id, $ei_scenario_package_datas['package_id'], $ei_scenario_package_datas['package_ref']); } else { //Erreur dû au fait qu'on ne permet pas la création d'une version sans spécification de package throw new Exception('No package set for version !'); } $this->processForm($request, $this->form); $this->setTemplate('new'); }