CRM-19441 - Fix display and saving of case tags
authorColeman Watts <coleman@civicrm.org>
Mon, 3 Oct 2016 19:47:53 +0000 (15:47 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 9 Oct 2016 20:57:45 +0000 (16:57 -0400)
CRM/Case/Form/CaseView.php
CRM/Case/Page/AJAX.php
CRM/Core/Form/Tag.php
templates/CRM/Case/Form/CaseView.tpl

index 886e3ef27f0580ec32a0feda0b6b8f67426cffa0..0b47a03a0e63b02387b1e9814355282684b878fd 100644 (file)
@@ -375,12 +375,33 @@ 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();
     if ($parentNames) {
-      $this->assign('showTagsets', TRUE);
-    }
-    else {
-      $this->assign('showTagsets', FALSE);
+      $this->assign('showTags', TRUE);
+      $tagSetItems = civicrm_api3('entityTag', 'get', array(
+        'entity_id' => $this->_caseID,
+        'entity_table' => 'civicrm_case',
+        'options' => array('limit' => 0),
+      ));
+      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'];
+        }
+      }
     }
+    $this->assign('tagSetTags', $tagSetTagNames);
     CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE);
 
     $this->addButtons(array(
index 8c7d125281910f832147ee0b4a7b358f5b83bbdc..d451c7f7b2bc9905e00a6753a330670c942b5a8c 100644 (file)
@@ -55,24 +55,22 @@ class CRM_Case_Page_AJAX {
       $tagIds = explode(',', $tags);
     }
 
-    if (!empty($tagIds)) {
-      $params = array(
-        'entity_id' => $caseId,
-        'entity_table' => 'civicrm_case',
-      );
-
-      CRM_Core_BAO_EntityTag::del($params);
-
-      foreach ($tagIds as $tagid) {
-        if (is_numeric($tagid)) {
-          $params['tag_id'] = $tagid;
-          CRM_Core_BAO_EntityTag::add($params);
-        }
+    $params = array(
+      'entity_id' => $caseId,
+      'entity_table' => 'civicrm_case',
+    );
+
+    CRM_Core_BAO_EntityTag::del($params);
+
+    foreach ($tagIds as $tagid) {
+      if (is_numeric($tagid)) {
+        $params['tag_id'] = $tagid;
+        CRM_Core_BAO_EntityTag::add($params);
       }
     }
 
     if (!empty($tagList)) {
-      CRM_Core_Form_Tag::postProcess($tagList, $caseId, 'civicrm_case', CRM_Core_DAO::$_nullObject);
+      CRM_Core_Form_Tag::postProcess($tagList, $caseId, 'civicrm_case');
     }
 
     $session = CRM_Core_Session::singleton();
index 2a0183e59ccdf503c6ad7852d1f438cf41b5f7a2..4a29d89f474a936ec637896850499a7e019818be 100644 (file)
@@ -127,7 +127,7 @@ class CRM_Core_Form_Tag {
    * @param CRM_Core_Form $form
    *   Form object.
    */
-  public static function postProcess(&$params, $entityId, $entityTable = 'civicrm_contact', &$form) {
+  public static function postProcess(&$params, $entityId, $entityTable = 'civicrm_contact', &$form = NULL) {
     if ($form && !empty($form->_entityTagValues)) {
       $existingTags = $form->_entityTagValues;
     }
index 04270aa28e402333a5aa087ef83635eb0687e5ea..3de01fc521c527be9a9da1424ba4aca5716c2efd 100644 (file)
 {include file="CRM/Case/Form/ActivityToCase.tpl"}
 
 {* pane to display / edit regular tags or tagsets for cases *}
-{if $showTags OR $showTagsets}
-
+{if $showTags}
 <div id="casetags" class="crm-accordion-wrapper  crm-case-tags-block">
  <div class="crm-accordion-header">
   {ts}Case Tags{/ts}
  </div><!-- /.crm-accordion-header -->
  <div class="crm-accordion-body">
-  {assign var="tagExits" value=0}
   {if $tags}
-    <div class="crm-block crm-content-block crm-case-caseview-display-tags">&nbsp;&nbsp;{$tags}</div>
-    {assign var="tagExits" value=1}
+    <p class="crm-block crm-content-block crm-case-caseview-display-tags">&nbsp;&nbsp;{$tags}</p>
   {/if}
 
-   {foreach from=$tagsetInfo.case item=displayTagset}
-     {if $displayTagset.entityTagsArray}
-       <div class="crm-block crm-content-block crm-case-caseview-display-tagset">
-         &nbsp;&nbsp;{$displayTagset.parentName}:
-         {foreach from=$displayTagset.entityTagsArray item=val name="tagsetList"}
-           &nbsp;{$val.name}{if !$smarty.foreach.tagsetList.last},{/if}
-         {/foreach}
-       </div>
-       {assign var="tagExits" value=1}
-     {/if}
+   {foreach from=$tagSetTags item=displayTagset}
+     <p class="crm-block crm-content-block crm-case-caseview-display-tagset">
+       &nbsp;&nbsp;<strong>{$displayTagset.name}:</strong>
+       {', '|implode:$displayTagset.items}
+     </p>
    {/foreach}
 
-   {if !$tagExits }
+   {if !$tags && !$tagSetTags }
      <div class="status">
        {ts}There are no tags currently assigned to this case.{/ts}
      </div>
    {/if}
 
   <div class="crm-submit-buttons">
-    <a class="button case-miniform" href="#manageTagsDialog" data-key="{crmKey name='civicrm/case/ajax/processtags'}">{if $tagExits}{ts}Edit Tags{/ts}{else}{ts}Add Tags{/ts}{/if}</a>
+    <a class="button case-miniform" href="#manageTagsDialog" data-key="{crmKey name='civicrm/case/ajax/processtags'}">
+      {if $tags || $tagSetTags}{ts}Edit Tags{/ts}{else}{ts}Add Tags{/ts}{/if}
+    </a>
   </div>
 
  </div><!-- /.crm-accordion-body -->