Skip to content

Commit

Permalink
Merge pull request civicrm#11467 from JMAConsulting/CRM-21613
Browse files Browse the repository at this point in the history
CRM-21613: Search issues on 'Manage Tag' page
  • Loading branch information
colemanw authored and sluc23 committed Jan 10, 2018
2 parents 9ee9588 + 3506c55 commit 6751d2e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
23 changes: 16 additions & 7 deletions CRM/Admin/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,31 @@ public static function getTagTree() {
$substring = CRM_Utils_Type::escape(CRM_Utils_Array::value('str', $_GET), 'String');
$result = array();

$whereClauses = array(
'is_tagset <> 1',
$parent ? "parent_id = $parent" : 'parent_id IS NULL',
);
$whereClauses = array('is_tagset <> 1');
$orderColumn = 'name';

// fetch all child tags in Array('parent_tag' => array('child_tag_1', 'child_tag_2', ...)) format
$childTagIDs = CRM_Core_BAO_Tag::getChildTags($substring);
$parentIDs = array_keys($childTagIDs);

if ($substring) {
if ($parent) {
$whereClauses[] = "parent_id = $parent";
}
elseif ($substring) {
$whereClauses['substring'] = " name LIKE '%$substring%' ";
if (!empty($parentIDs)) {
$whereClauses['substring'] = sprintf("( %s OR id IN (%s) )", $whereClauses['substring'], implode(',', $parentIDs));
$whereClauses['substring'] = sprintf(" %s OR id IN (%s) ", $whereClauses['substring'], implode(',', $parentIDs));
}
$orderColumn = 'id';
}
else {
$whereClauses[] = "parent_id IS NULL";
}

$dao = CRM_Utils_SQL_Select::from('civicrm_tag')
->where($whereClauses)
->groupBy('id')
->orderBy('name')
->orderBy($orderColumn)
->execute();

while ($dao->fetch()) {
Expand Down Expand Up @@ -369,6 +374,10 @@ public static function getTagTree() {
}
}

if ($substring) {
$result = array_values(array_unique($result));
}

if (!empty($_REQUEST['is_unit_test'])) {
return $result;
}
Expand Down
11 changes: 11 additions & 0 deletions CRM/Core/BAO/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,17 @@ public static function getChildTags($searchString = NULL) {
->execute();
while ($dao->fetch()) {
$childTagIDs[$dao->parent_id] = (array) explode(',', $dao->child_id);
$parentID = $dao->parent_id;
if ($searchString) {
// recursively search for parent tag ID and it's child if any
while ($parentID) {
$newParentID = CRM_Core_DAO::singleValueQuery(" SELECT parent_id FROM civicrm_tag WHERE id = $parentID ");
if ($newParentID) {
$childTagIDs[$newParentID] = array($parentID);
}
$parentID = $newParentID;
}
}
}

// check if child tag has any childs, if found then include those child tags inside parent tag
Expand Down
5 changes: 3 additions & 2 deletions templates/CRM/Tag/Page/Tag.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@
});

$('input[name=filter_tag_tree]', $panel).on('keyup change', function() {
if ($(this).val() == null) {
$('.tag-tree', $panel).jstree(true).refresh();
if ($(this).val() === '') {
$('.tag-tree', $panel).jstree("clear_search");
$('.tag-tree', $panel).jstree("refresh", true, true);
}
else {
$(".tag-tree", $panel).jstree("search", $(this).val());
Expand Down

0 comments on commit 6751d2e

Please sign in to comment.