From: Coleman Watts Date: Thu, 14 Aug 2014 18:23:00 +0000 (+0100) Subject: CRM-15117 - Show tag descriptions in tagTree X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=802577429d39ecb22ed5b3c3f0219d2ec16b521e;p=civicrm-core.git CRM-15117 - Show tag descriptions in tagTree Also improves CRM_Core_BAO_Tag::buildTree to remove the 3-level limit. --- diff --git a/CRM/Core/BAO/Tag.php b/CRM/Core/BAO/Tag.php index 2aa097f503..1b8e840aa2 100644 --- a/CRM/Core/BAO/Tag.php +++ b/CRM/Core/BAO/Tag.php @@ -79,11 +79,12 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { } /** + * Build a nested array from hierarchical tags. Supports infinite levels of nesting. * @param null $usedFor * @param bool $excludeHidden */ function buildTree($usedFor = NULL, $excludeHidden = FALSE) { - $sql = "SELECT civicrm_tag.id, civicrm_tag.parent_id,civicrm_tag.name FROM civicrm_tag "; + $sql = "SELECT id, parent_id, name, description FROM civicrm_tag"; $whereClause = array(); if ($usedFor) { @@ -101,42 +102,22 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray, TRUE, NULL, FALSE, FALSE); - $orphan = array(); + $refs = array(); while ($dao->fetch()) { + $thisref = &$refs[$dao->id]; + + $thisref['parent_id'] = $dao->parent_id; + $thisref['name'] = $dao->name; + $thisref['description'] = $dao->description; + if (!$dao->parent_id) { - $this->tree[$dao->id]['name'] = $dao->name; + $this->tree[$dao->id] = &$thisref; } else { - if (array_key_exists($dao->parent_id, $this->tree)) { - $parent = &$this->tree[$dao->parent_id]; - if (!isset($this->tree[$dao->parent_id]['children'])) { - $this->tree[$dao->parent_id]['children'] = array(); - } - } - else { - //3rd level tag - if (!array_key_exists($dao->parent_id, $orphan)) { - $orphan[$dao->parent_id] = array('children' => array()); - } - $parent = &$orphan[$dao->parent_id]; - } - $parent['children'][$dao->id] = array('name' => $dao->name); + $refs[$dao->parent_id]['children'][$dao->id] = &$thisref; } } - if (sizeof($orphan)) { - //hang the 3rd level lists at the right place - foreach ($this->tree as & $level1) { - if (!isset($level1['children'])) { - continue; - } - foreach ($level1['children'] as $key => & $level2) { - if (array_key_exists($key, $orphan)) { - $level2['children'] = $orphan[$key]['children']; - } - } - } - } } /** diff --git a/templates/CRM/Tag/Form/Tagtree.hlp b/templates/CRM/Tag/Form/Tagtree.hlp new file mode 100644 index 0000000000..e5d9719349 --- /dev/null +++ b/templates/CRM/Tag/Form/Tagtree.hlp @@ -0,0 +1,30 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.5 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2014 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} + +{htxt id=$id} + {crmAPI var='result' entity='tag' action='getsingle' return="description" id=$id} + {$result.description} +{/htxt} diff --git a/templates/CRM/Tag/Form/Tagtree.tpl b/templates/CRM/Tag/Form/Tagtree.tpl index cbbf37aa06..3c017cdba0 100644 --- a/templates/CRM/Tag/Form/Tagtree.tpl +++ b/templates/CRM/Tag/Form/Tagtree.tpl @@ -28,7 +28,10 @@ {foreach from=$tree item="node" key="id"}
  • - + {if $node.children} {* Recurse... *} {include file="CRM/Tag/Form/Tagtree.tpl" tree=$node.children}