CRM-15117 - Show tag descriptions in tagTree
authorColeman Watts <coleman@civicrm.org>
Thu, 14 Aug 2014 18:23:00 +0000 (19:23 +0100)
committerColeman Watts <coleman@civicrm.org>
Thu, 14 Aug 2014 18:23:00 +0000 (19:23 +0100)
Also improves CRM_Core_BAO_Tag::buildTree to remove the 3-level limit.

CRM/Core/BAO/Tag.php
templates/CRM/Tag/Form/Tagtree.hlp [new file with mode: 0644]
templates/CRM/Tag/Form/Tagtree.tpl

index 2aa097f503290c6ceed37efaa1069bfccf616315..1b8e840aa22da624b8e0b0454e927a5cd4035582 100644 (file)
@@ -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 (file)
index 0000000..e5d9719
--- /dev/null
@@ -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}
index cbbf37aa062d607d5972b1cec65e9571d1bc53d4..3c017cdba02c4b5dceb8ac71a3a3c123027b99a9 100644 (file)
   {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}