Beispiel #1
0
 /**
  * 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 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;
     }
 }
Beispiel #3
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;
 }
 /**
  * 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();
 }