From 3f3bdea4de33389a928e3c8fec8dd994f6104e25 Mon Sep 17 00:00:00 2001 From: Alex Orluc <alex.orluc@maarch.org> Date: Thu, 23 Feb 2017 00:00:15 +0100 Subject: [PATCH] FEAT #5234 refactor search adv for tags --- .../indexing_searching/search_adv.php | 2 +- modules/tags/class/TagControler_Abstract.php | 27 +++++---------- modules/tags/tags_search.php | 34 +++++-------------- 3 files changed, 18 insertions(+), 45 deletions(-) diff --git a/apps/maarch_entreprise/indexing_searching/search_adv.php b/apps/maarch_entreprise/indexing_searching/search_adv.php index 87efacb6e47..ea16b4dd98d 100644 --- a/apps/maarch_entreprise/indexing_searching/search_adv.php +++ b/apps/maarch_entreprise/indexing_searching/search_adv.php @@ -277,7 +277,7 @@ if($core_tools->is_module_loaded('tags')) if ($tag_return_value){ foreach($tag_return_value as $tagelem) { - array_push($arr_tmptag, array('VALUE' => functions::protect_string_db($tagelem['tag_label']), 'LABEL' => $tagelem['tag_label'])); + array_push($arr_tmptag, array('VALUE' => functions::protect_string_db($tagelem['tag_id']), 'LABEL' => $tagelem['tag_label'])); } } else diff --git a/modules/tags/class/TagControler_Abstract.php b/modules/tags/class/TagControler_Abstract.php index 81d46bcccd7..f7306848b23 100755 --- a/modules/tags/class/TagControler_Abstract.php +++ b/modules/tags/class/TagControler_Abstract.php @@ -323,27 +323,16 @@ abstract class tag_controler_Abstract extends ObjectControler * Searching a list of ressources by label * @Return : an Array with label's ressources or 0 */ - public function getresarray_byLabel($tag_label, $coll_id){ - $array = array(); - + public function getresarray_byId($tag_id){ + $result = array(); $db = new Database(); $stmt = $db->query( - "SELECT res_id AS bump FROM " ._TAG_TABLE_NAME - . " WHERE tag_label = ? AND coll_id = ?" - . " AND res_id <> 0" - ,array($tag_label,$coll_id)); - - while ($result = $stmt->fetchObject()) - { - array_push($array, $result->bump); - } - - if ($array) - { - return $array; - } - - return false; + "SELECT res_id FROM tag_res" + . " WHERE tag_id = ?" + ,array($tag_id)); + + $result = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); + return $result; } diff --git a/modules/tags/tags_search.php b/modules/tags/tags_search.php index 82b5f4cbfef..fbd58e33ce2 100755 --- a/modules/tags/tags_search.php +++ b/modules/tags/tags_search.php @@ -49,29 +49,13 @@ if ($coll_id == '') { } $tag_resid_return = array(); $json_txt .= " 'tags_chosen' : ["; -//$tags_chosen_tmp = array(); -for ($getag_i = 0; $getag_i <count($_REQUEST['tags_chosen']); $getag_i++) { - $return_tags_res_id = array(); - $return_tags_res_id = $tag->getresarray_byLabel($_REQUEST['tags_chosen'][$getag_i], $targetColl); - //array_push($tags_chosen_tmp, $func->protect_string_db($_REQUEST['tags_chosen'][$getag_i])); - $json_txt .= "'".addslashes($_REQUEST['tags_chosen'][$getag_i])."',"; - if ($return_tags_res_id) { - foreach ($return_tags_res_id as $elem) { - array_push($tag_resid_return, $elem); - } - } else { - array_push($tag_resid_return, 0); - } - +$json_txt .= "'".implode("','", $_REQUEST['tags_chosen'])."'"; +$return_tags_res_id = array(); +foreach ($_REQUEST['tags_chosen'] as $tagId) { + $result = $tag->getresarray_byId($tagId); + $return_tags_res_id = array_merge($return_tags_res_id,$result); } - -foreach ($tag_resid_return as $finaltagsearch) { - - $tag_resid_in .= "'".$finaltagsearch."',"; -} -$tag_resid_in = substr($tag_resid_in, 0, -1); -$where_request .= " res_id in (:tags) and "; -$arrayPDO = array_merge($arrayPDO, array(":tags" => $tag_resid_return)); - -$json_txt = substr($json_txt, 0, -1); -$json_txt .= '],'; +$return_tags_res_id = "'".implode("','", $return_tags_res_id)."'"; +$where_request .= " res_id in (".$return_tags_res_id.") and "; +//$arrayPDO = array_merge($arrayPDO, array(":tags" => $return_tags_res_id)); +$json_txt .= '],'; \ No newline at end of file -- GitLab