Skip to content
Snippets Groups Projects
Commit 6fd5424b authored by Kurund Jalmi's avatar Kurund Jalmi
Browse files

fixes to case view tagset and tags CRM-14052

----------------------------------------
* CRM-14052: Tagset fixes
  http://issues.civicrm.org/jira/browse/CRM-14052
parent 78633f1e
No related branches found
No related tags found
No related merge requests found
......@@ -433,7 +433,12 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
$this->setDefaults(array('case_tag' => $tags));
foreach ($tags as $tid) {
$tags[$tid] = $allTags[$tid];
if (isset($allTags[$tid])) {
$tags[$tid] = $allTags[$tid];
}
else {
unset($tags[$tid]);
}
}
$this->assign('tags', implode(', ', array_filter($tags)));
......@@ -453,7 +458,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
else {
$this->assign('showTagsets', FALSE);
}
CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE);
CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, TRUE, TRUE);
$this->addButtons(array(
array(
......
......@@ -72,6 +72,7 @@ class CRM_Case_Page_AJAX {
$caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Integer');
$tags = CRM_Utils_Type::escape($_POST['tag'], 'String');
$tagList = $_POST['taglist'];
if (empty($caseId)) {
echo 'false';
......@@ -83,20 +84,28 @@ class CRM_Case_Page_AJAX {
$tagIds = explode(',', $tags);
}
$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);
$skipEntityDelete = FALSE;
if (!empty($tagIds)) {
$skipEntityDelete = TRUE;
$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, $skipEntityDelete);
}
$session = CRM_Core_Session::singleton();
$activityParams = array();
......
......@@ -234,13 +234,30 @@ class CRM_Core_Form_Tag {
/**
* Function to save entity tags when it is not save used AJAX
*
* @param array $params associated array
* @param int $entityId entity id, eg: contact id, activity id, case id, file id
* @param string $entityTable entity table
* @param object $form form object
* @param boolean $skipDelete TRUE if you need to skip delete action in tag entity table
*
* @return void
* @access public
* @static
*/
static function postProcess(&$params, $entityId, $entityTable = 'civicrm_contact', &$form) {
static function postProcess(&$params, $entityId, $entityTable = 'civicrm_contact', &$form, $skipDelete = FALSE) {
if ($form && !empty($form->_entityTagValues)) {
$existingTags = $form->_entityTagValues;
}
else {
$existingTags = CRM_Core_BAO_EntityTag::getTag($entityId, $entityTable);
}
$allTagIds = array();
foreach ($params as $parentId => $value) {
if (!$value) {
if (!$value || empty($value)) {
continue;
}
$tagsIDs = explode(',', $value);
$insertValues = array();
$insertSQL = NULL;
......@@ -252,11 +269,11 @@ class CRM_Core_Form_Tag {
$tagValue = explode(':::', $tagId);
if (isset($tagValue[1]) && $tagValue[1] == 'value') {
$params = array(
$tagParams = array(
'name' => $tagValue[0],
'parent_id' => $parentId,
);
$tagObject = CRM_Core_BAO_Tag::add($params, CRM_Core_DAO::$_nullArray);
$tagObject = CRM_Core_BAO_Tag::add($tagParams, CRM_Core_DAO::$_nullArray);
$tagId = $tagObject->id;
}
}
......@@ -265,23 +282,31 @@ class CRM_Core_Form_Tag {
if ($form && $form->_action != CRM_Core_Action::UPDATE) {
$insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) ";
}
elseif (!$form || !array_key_exists($tagId, $form->_entityTagValues)) {
elseif (!array_key_exists($tagId, $existingTags)) {
$insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) ";
}
}
if (!empty($insertValues)) {
$insertSQL = 'INSERT INTO civicrm_entity_tag ( tag_id, entity_id, entity_table ) VALUES ' . implode(', ', $insertValues) . ';';
$insertSQL = 'INSERT INTO civicrm_entity_tag ( tag_id, entity_id, entity_table )
VALUES ' . implode(', ', $insertValues) . ';';
CRM_Core_DAO::executeQuery($insertSQL);
}
}
}
// delete tags that are missing
if (!empty($allTagIds)) {
$validTagIds = implode(',', $allTagIds);
$deleteSQL = "DELETE FROM civicrm_entity_tag WHERE entity_id={$entityId} AND entity_table='{$entityTable}'
AND tag_id NOT IN ({$validTagIds})";
// delete tags that are missing from civicrm_entity_tag table
if (!$skipDelete) {
$inClause = '';
if (!empty($allTagIds)) {
$validTagIds = implode(',', $allTagIds);
$inClause = " AND civicrm_entity_tag.tag_id NOT IN ({$validTagIds})";
}
$deleteSQL = "
DELETE FROM civicrm_entity_tag USING civicrm_entity_tag, civicrm_tag
WHERE civicrm_entity_tag.tag_id = civicrm_tag.id AND civicrm_tag.parent_id IS NOT NULL
AND civicrm_entity_tag.entity_id={$entityId} AND civicrm_entity_tag.entity_table='{$entityTable}' {$inClause}";
CRM_Core_DAO::executeQuery($deleteSQL);
}
}
......
......@@ -781,7 +781,7 @@ function addRole() {
<div class="crm-accordion-body">
{assign var="tagExits" value=0}
{if $tags}
<div class="crm-block crm-content-block crm-case-caseview-display-tags">{$tags}</div>
<div class="crm-block crm-content-block crm-case-caseview-display-tags">&nbsp;&nbsp;{$tags}</div>
{assign var="tagExits" value=1}
{/if}
......@@ -853,18 +853,15 @@ function addTags() {
}
});
var tagList = '';
cj("#manageTags input[name^=case_taglist]").each(function( ) {
if (!tagsChecked) {
tagsChecked = cj(this).val() + '';
}
else {
tagsChecked = tagsChecked + ',' + cj(this).val();
}
var tagList = {};
cj("#manageTags input[name^=case_taglist]").each(function(){
var tsId = cj(this).attr('id').split('_');
tagList[tsId[2]] = cj(this).val();
});
var postUrl = {/literal}"{crmURL p='civicrm/case/ajax/processtags' h=0 }"{literal};
var data = 'case_id=' + caseID + '&tag=' + tagsChecked + '&key=' + {/literal}"{crmKey name='civicrm/case/ajax/processtags'}"{literal};
var key = {/literal}"{crmKey name='civicrm/case/ajax/processtags'}"{literal};
var data = {'case_id': caseID, 'tag': tagsChecked, 'taglist': tagList, 'key': key};
cj.ajax({ type: "POST", url: postUrl, data: data, async: false });
cj(this).dialog("close");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment