/** * Méthode permettant de récupérer les IDs de tous les paramètres de blocs parents (directs) et frères * (or blocs communs, occurences de boucles). * * @param EiTestSetBlockParam $blockParam * * @TODO: Améliorer la façon dont la requête est traitée. */ public function getAllParentsId(EiTestSetBlockParam $blockParam) { // Récupération de la connexion BDD. $conn = Doctrine_Manager::connection(); $parentsIds = array(); $sqlDirectParents = "\n SELECT id, lft, rgt, level, ei_version_structure_id as vs_id\n FROM ei_test_set_block_param\n WHERE ei_test_set_id = " . $blockParam->getEiTestSetId() . "\n AND lft < " . $blockParam->getLft() . "\n AND rgt > " . $blockParam->getRgt() . "\n ORDER BY lft;\n "; $directParents = $conn->execute($sqlDirectParents)->fetchAll(); if (is_array($directParents) && count($directParents) > 0) { $sqlBrothers = "\n SELECT id, lft, rgt, level, ei_version_structure_id as vs_id\n FROM ei_test_set_block_param\n WHERE ei_test_set_id = " . $blockParam->getEiTestSetId() . "\n AND lft < " . $blockParam->getLft() . "\n AND type IN (" . implode(",", EiVersionStructure::getBlockTypesWithQuotes()) . ")\n "; foreach ($directParents as $directParent) { $parentsIds[] = $directParent["id"]; $sqlBrothers .= "\n AND NOT(ei_version_structure_id = " . $directParent["vs_id"] . " AND level = " . $directParent["level"] . ")\n "; } $sqlBrothers .= "\n AND NOT(ei_version_structure_id = " . $blockParam->getEiVersionStructureId() . " AND level = " . $blockParam->getLevel() . ")\n "; $sqlBrothers .= "\n ORDER BY lft;\n "; $brothers = $conn->execute($sqlBrothers)->fetchAll(); if (is_array($brothers) && count($brothers) > 0) { foreach ($brothers as $brother) { if (!in_array($brother["id"], $parentsIds)) { $parentsIds[] = $brother["id"]; } } } } return $parentsIds; }