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; }