CRM-19441 - Simplify api call
authorColeman Watts <coleman@civicrm.org>
Sun, 9 Oct 2016 21:16:40 +0000 (17:16 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 9 Oct 2016 21:21:28 +0000 (17:21 -0400)
Can do this as one call instead of two thanks to CRM-19448

CRM/Case/Form/CaseView.php

index 0b47a03a0e63b02387b1e9814355282684b878fd..cc26a408237a82292fad6f42c4c191394f2ef6fd 100644 (file)
@@ -375,33 +375,27 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
 
     // see if we have any tagsets which can be assigned to cases
     $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case');
-    $tagSetTagNames = array();
+    $tagSetTags = array();
     if ($parentNames) {
       $this->assign('showTags', TRUE);
       $tagSetItems = civicrm_api3('entityTag', 'get', array(
         'entity_id' => $this->_caseID,
         'entity_table' => 'civicrm_case',
+        'tag_id.parent_id.is_tagset' => 1,
         'options' => array('limit' => 0),
+        'return' => array("tag_id.parent_id", "tag_id.parent_id.name", "tag_id.name"),
       ));
-      if ($tagSetItems['count']) {
-        $tagSetTags = civicrm_api3('tag', 'get', array(
-          'id' => array('IN' => array_keys($tagSetItems['values'])),
-          'parent_id.is_tagset' => 1,
-          'return' => array("parent_id", "parent_id.name", "name"),
-          'options' => array('limit' => 0),
-        ));
-        foreach ($tagSetTags['values'] as $id => $tag) {
-          $tagSetTagNames += array(
-            $tag['parent_id'] => array(
-              'name' => $tag['parent_id.name'],
-              'items' => array(),
-            ),
-          );
-          $tagSetTagNames[$tag['parent_id']]['items'][$id] = $tag['name'];
-        }
+      foreach ($tagSetItems['values'] as $tag) {
+        $tagSetTags += array(
+          $tag['tag_id.parent_id'] => array(
+            'name' => $tag['tag_id.parent_id.name'],
+            'items' => array(),
+          ),
+        );
+        $tagSetTags[$tag['tag_id.parent_id']]['items'][] = $tag['tag_id.name'];
       }
     }
-    $this->assign('tagSetTags', $tagSetTagNames);
+    $this->assign('tagSetTags', $tagSetTags);
     CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE);
 
     $this->addButtons(array(