$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()) {
}
}
+ if ($substring) {
+ $result = array_values(array_unique($result));
+ }
+
if (!empty($_REQUEST['is_unit_test'])) {
return $result;
}
->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
});
$('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());