From bd343dccd00d65ea10b239f5a1384b2311a3a9dc Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 17 Jul 2014 13:47:19 +0100 Subject: [PATCH] CRM-15003 - Supply contacts' open case as a default --- CRM/Case/BAO/Case.php | 3 +++ CRM/Case/Form/ActivityToCase.php | 11 +++++++++++ templates/CRM/Case/Form/ActivityToCase.tpl | 3 +++ 3 files changed, 17 insertions(+) diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 0ca273ae2f..b251ffa58d 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -2049,6 +2049,9 @@ SELECT civicrm_contact.id as casemanager_id, $search = ($config->includeWildCardInName) ? "%$sortName%" : "$sortName%"; $where[] = "( sort_name LIKE '$search' )"; } + if ($cid = CRM_Utils_Array::value('contact_id', $params)) { + $where[] = " c.id = $cid "; + } if (is_array($excludeCaseIds) && !CRM_Utils_System::isNull($excludeCaseIds) ) { diff --git a/CRM/Case/Form/ActivityToCase.php b/CRM/Case/Form/ActivityToCase.php index 85f56d9155..7cfd525f85 100644 --- a/CRM/Case/Form/ActivityToCase.php +++ b/CRM/Case/Form/ActivityToCase.php @@ -72,6 +72,17 @@ class CRM_Case_Form_ActivityToCase extends CRM_Core_Form { $defaults['file_on_case_activity_subject'] = $defaults['subject']; $defaults['file_on_case_target_contact_id'] = $defaults['target_contact']; + $cid = CRM_Utils_Request::retrieve('cid', 'Integer'); + if ($cid) { + $cases = CRM_Case_BAO_Case::getUnclosedCases(array('contact_id' => $cid), $this->_currentCaseId); + foreach ($cases as $id => $details) { + $defaults['file_on_case_unclosed_case_id'] = $id; + $value = array('label' => $details['sort_name'] . ' - ' . $details['case_type']); + $this->updateElementAttr('file_on_case_unclosed_case_id', array('data-value' => json_encode($value))); + break; + } + } + return $defaults; } diff --git a/templates/CRM/Case/Form/ActivityToCase.tpl b/templates/CRM/Case/Form/ActivityToCase.tpl index 1f5a9da24b..ee8963d638 100644 --- a/templates/CRM/Case/Form/ActivityToCase.tpl +++ b/templates/CRM/Case/Form/ActivityToCase.tpl @@ -53,6 +53,9 @@ formatSelection: function(row) { return row.label; }, + initSelection: function($el, callback) { + callback($el.data('value')); + }, ajax: { url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal}, data: function(term) { -- 2.25.1