}
/**
+ * 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) {
$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'];
- }
- }
- }
- }
}
/**
--- /dev/null
+{*
+ +--------------------------------------------------------------------+
+ | 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}
{foreach from=$tree item="node" key="id"}
<li id="tag_{$id}">
<input name="tagList[{$id}]" id="check_{$id}" type="checkbox" {if $tagged[$id]}checked="checked"{/if}/>
- <label for="check_{$id}" id="tagLabel_{$id}">{$node.name}</label>
+ <label for="check_{$id}" id="tagLabel_{$id}">
+ {$node.name}
+ {if $node.description}{help id=$id title=$node.name file="CRM/Tag/Form/Tagtree"}{/if}
+ </label>
{if $node.children}
{* Recurse... *}
{include file="CRM/Tag/Form/Tagtree.tpl" tree=$node.children}