From 79564bd412ebb145ca1ca4bdc05f2d782441f8b9 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 3 Oct 2016 15:47:53 -0400 Subject: [PATCH] CRM-19441 - Fix display and saving of case tags --- CRM/Case/Form/CaseView.php | 29 ++++++++++++++++++++++++---- CRM/Case/Page/AJAX.php | 26 ++++++++++++------------- CRM/Core/Form/Tag.php | 2 +- templates/CRM/Case/Form/CaseView.tpl | 28 +++++++++++---------------- 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/CRM/Case/Form/CaseView.php b/CRM/Case/Form/CaseView.php index 886e3ef27f..0b47a03a0e 100644 --- a/CRM/Case/Form/CaseView.php +++ b/CRM/Case/Form/CaseView.php @@ -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( diff --git a/CRM/Case/Page/AJAX.php b/CRM/Case/Page/AJAX.php index 8c7d125281..d451c7f7b2 100644 --- a/CRM/Case/Page/AJAX.php +++ b/CRM/Case/Page/AJAX.php @@ -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(); diff --git a/CRM/Core/Form/Tag.php b/CRM/Core/Form/Tag.php index 2a0183e59c..4a29d89f47 100644 --- a/CRM/Core/Form/Tag.php +++ b/CRM/Core/Form/Tag.php @@ -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; } diff --git a/templates/CRM/Case/Form/CaseView.tpl b/templates/CRM/Case/Form/CaseView.tpl index 04270aa28e..3de01fc521 100644 --- a/templates/CRM/Case/Form/CaseView.tpl +++ b/templates/CRM/Case/Form/CaseView.tpl @@ -269,39 +269,33 @@ {include file="CRM/Case/Form/ActivityToCase.tpl"} {* pane to display / edit regular tags or tagsets for cases *} -{if $showTags OR $showTagsets} - +{if $showTags}
{ts}Case Tags{/ts}
- {assign var="tagExits" value=0} {if $tags} -
  {$tags}
- {assign var="tagExits" value=1} +

  {$tags}

{/if} - {foreach from=$tagsetInfo.case item=displayTagset} - {if $displayTagset.entityTagsArray} -
-   {$displayTagset.parentName}: - {foreach from=$displayTagset.entityTagsArray item=val name="tagsetList"} -  {$val.name}{if !$smarty.foreach.tagsetList.last},{/if} - {/foreach} -
- {assign var="tagExits" value=1} - {/if} + {foreach from=$tagSetTags item=displayTagset} +

+   {$displayTagset.name}: + {', '|implode:$displayTagset.items} +

{/foreach} - {if !$tagExits } + {if !$tags && !$tagSetTags }
{ts}There are no tags currently assigned to this case.{/ts}
{/if}
-- 2.25.1