/** * 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()))); }
public function getFullFonctions($ei_version_structure, $defaultPackage = null) { /* On s'assure que tout marche bien même si le package par défaut n'est pas renseigné */ if ($defaultPackage == null) { $defPackId = 0; $defPackRef = 0; $defInterventionId = 0; } else { $defPackId = $defaultPackage['package_id']; $defPackRef = $defaultPackage['package_ref']; $defInterventionId = $defaultPackage['subject_id']; } $query = "\n SELECT fct.*, t.name as fctname,\n ep.param_id as ep_paramid, ep.param_type, ep.name as paramname, ep.default_value as paramdefaultvalue, ep.description as paramdescription,\n p.valeur, p.id as id_eiparam, p.param_id, p.observation,\n mapping.id as id_mapping, mapping.ei_param_function_id, mapping.ei_param_block_id as mapping_ei_param_block_id, mapping.expression as mapping_expression,\n mapping.ei_function_id as mapping_ei_function_id,\n sf.subject_id as sf_subject_id ,sf.function_id as sf_function_id,sf.function_ref as sf_function_ref,\n IF(sc.ticket_id IS NOT NULL and sc.ticket_ref IS NOT NULL,1,IF(sf.automate IS NOT NULL,0,NULL)) as sf_automate,\n s.id as s_id,s.name as s_name ,s.package_id as s_package_id ,s.package_ref as s_package_ref \n FROM ei_fonction fct\n\n INNER JOIN ei_version_structure ei_str\n ON ei_str.ei_fonction_id = fct.id\n\n LEFT JOIN ei_function_has_param ep\n ON fct.function_ref = ep.function_ref AND ep.function_id = fct.function_id\n\n LEFT JOIN ei_param p\n ON p.param_id = ep.param_id AND p.id_fonction = fct.id\n\n LEFT JOIN ei_param_block_function_mapping mapping\n ON mapping.ei_function_id = fct.id AND mapping.ei_param_function_id = ep.param_id\n\n LEFT JOIN ei_tree t\n ON fct.function_ref=t.ref_obj AND fct.function_id=t.obj_id\n left join ei_script sc on sc.function_id=fct.function_id and sc.function_ref=fct.function_ref and sc.ticket_id=" . $defPackId . " and sc.ticket_ref=" . $defPackRef . " \n left join ei_subject_functions sf on sf.function_id=fct.function_id and sf.function_ref=fct.function_ref and sf.subject_id=" . $defInterventionId . " \n left join ei_subject s on s.id=sf.subject_id and s.id=" . $defInterventionId . " and s.package_id=" . $defPackId . " and s.package_ref=" . $defPackRef . "\n \n WHERE ei_str.ei_version_structure_parent_id = " . $ei_version_structure->getId() . "\n ORDER BY ei_str.lft\n "; $fonctions = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll($query); $fctArray = array(); $count = count($fonctions); $i = 0; $params = new Doctrine_Collection('EiParamBlockFunctionMapping'); $mappings = new Doctrine_Collection('EiParamBlockFunctionMapping'); $paramsRegistered = array(); $mappingsRegistered = array(); $subjectFonctions = array(); while ($i < $count) { $j = $i; $fct = $fonctions[$i]; while ($j < $count && $fct['id'] == $fonctions[$j]['id']) { if ($fonctions[$j]['id_eiparam'] != null && !in_array($fonctions[$j]['id_eiparam'], $paramsRegistered)) { $param = new EiParam(); $paramsRegistered[] = $fonctions[$j]["id_eiparam"]; $param->setId($fonctions[$j]['id_eiparam']); $param->setIdFonction($fonctions[$j]['id']); $param->setParamId($fonctions[$j]['param_id']); $param->setValeur($fonctions[$j]['valeur']); $param->setObservation($fonctions[$j]['observation']); $param->setName($fonctions[$j]['paramname']); $param->setDescription($fonctions[$j]['paramdescription']); $param->setDefaultValue($fonctions[$j]['paramdefaultvalue']); $params->add($param); } if ($fonctions[$j]["id_mapping"] != null && !in_array($fonctions[$j]["id_mapping"], $mappingsRegistered)) { $mapping = new EiParamBlockFunctionMapping(); $mappingsRegistered[] = $fonctions[$j]["id_mapping"]; $mapping->setId($fonctions[$j]["id_mapping"]); $mapping->setEiParamFunctionId($fonctions[$j]["ei_param_function_id"]); $mapping->setEiFunctionId($fonctions[$j]["mapping_ei_function_id"]); $mapping->setExpression($fonctions[$j]["mapping_expression"]); if ($fonctions[$j]["mapping_ei_param_block_id"] != null) { $mapping->setEiParamBlockId($fonctions[$j]["mapping_ei_param_block_id"]); } $mappings->add($mapping); } if ($fonctions[$j]["sf_automate"] != null && !in_array($defInterventionId, $subjectFonctions)) { $subjectFonctions[] = array('sf_subject_id' => $defInterventionId, 'sf_function_id' => $fonctions[$j]["function_id"], 'sf_function_ref' => $fonctions[$j]["function_ref"], 'sf_automate' => $fonctions[$j]["sf_automate"]); } $j++; } $aux = new EiFonction(); $aux->setId($fct['id']); $aux->setSubjectFunctions($subjectFonctions); $aux->setFunctionId($fct['function_id']); $aux->setFunctionRef($fct['function_ref']); $aux->setDescription($fct['description']); $aux->setProjectId($fct['project_id']); $aux->setProjectRef($fct['project_ref']); $aux->setName($fct['fctname']); $aux->setEiVersionStructureId($fct["ei_version_structure_id"]); $aux->setEiParams($params); $aux->setEiFunctionMapping($mappings); $params = new Doctrine_Collection('EiParam'); $mappings = new Doctrine_Collection('EiParamBlockFunctionMapping'); $paramsRegistered = array(); $mappingsRegistered = array(); $fctArray[] = $aux; $i = $j; $subjectFonctions = array(); } return $fctArray; }