From dcecc495e042dc45c45e23a0e02d1e02caef2341 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 1 Oct 2021 20:51:55 +1300 Subject: [PATCH] Use Case form for case actions --- CRM/Activity/Page/AJAX.php | 2 +- CRM/Case/Form/CaseView.php | 2 +- CRM/Case/Form/Task.php | 21 +++++-- CRM/Case/Form/Task/Email.php | 70 ++++++++++++++++++++++++ CRM/Case/xml/Menu/Case.xml | 6 ++ CRM/Contact/Form/Task/EmailTrait.php | 5 -- templates/CRM/Case/Form/CaseView.tpl | 2 +- templates/CRM/Case/Form/Task/Email.tpl | 1 + tests/phpunit/CRM/Case/Form/TaskTest.php | 4 +- 9 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 CRM/Case/Form/Task/Email.php create mode 100644 templates/CRM/Case/Form/Task/Email.tpl diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index 7cf1613e2f..4f85789576 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -217,7 +217,7 @@ class CRM_Activity_Page_AJAX { } // email column links/icon if ($row['email']) { - $row['email'] = ''; + $row['email'] = ''; } // view end date if set diff --git a/CRM/Case/Form/CaseView.php b/CRM/Case/Form/CaseView.php index c1031b20f5..2123f2f7ee 100644 --- a/CRM/Case/Form/CaseView.php +++ b/CRM/Case/Form/CaseView.php @@ -251,7 +251,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { $activityLinks = ['' => ts('Add Activity')]; foreach ($aTypes as $type => $label) { if ($type == $emailActivityType) { - $url = CRM_Utils_System::url('civicrm/activity/email/add', + $url = CRM_Utils_System::url('civicrm/case/email/add', "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype=$type", FALSE, NULL, FALSE ); diff --git a/CRM/Case/Form/Task.php b/CRM/Case/Form/Task.php index d1f318ac43..45c73958e1 100644 --- a/CRM/Case/Form/Task.php +++ b/CRM/Case/Form/Task.php @@ -34,11 +34,7 @@ class CRM_Case_Form_Task extends CRM_Core_Form_Task { * @inheritDoc */ public function setContactIDs() { - // @todo Parameters shouldn't be needed and should be class member - // variables instead, set appropriately by each subclass. - $this->_contactIds = $this->getContactIDsFromComponent($this->_entityIds, - 'civicrm_case_contact', 'case_id' - ); + $this->_contactIds = $this->getContactIDs(); } /** @@ -86,4 +82,19 @@ class CRM_Case_Form_Task extends CRM_Core_Form_Task { return 'case_id'; } + protected function getContactIDs(): array { + if (isset($this->_contactIds)) { + return $this->_contactIds; + } + $contactIDSFromUrl = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this); + if (!empty($contactIDSFromUrl)) { + return explode(',', $contactIDSFromUrl); + } + // @todo Parameters shouldn't be needed and should be class member + // variables instead, set appropriately by each subclass. + return $this->getContactIDsFromComponent($this->_entityIds, + 'civicrm_case_contact', 'case_id' + ); + } + } diff --git a/CRM/Case/Form/Task/Email.php b/CRM/Case/Form/Task/Email.php new file mode 100644 index 0000000000..47c4bb16bd --- /dev/null +++ b/CRM/Case/Form/Task/Email.php @@ -0,0 +1,70 @@ +getCaseID()) { + // For a single case, list tokens relevant for only that case type + $caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $this->getCaseID(), 'case_type_id'); + $tokens += CRM_Core_SelectValues::caseTokens($caseTypeId); + } + + return $tokens; + } + + /** + * Get the subject for the message. + * + * The case handling should possibly be on the case form..... + * + * @param string $subject + * + * @return string + * @throws \CRM_Core_Exception + */ + protected function getSubject(string $subject):string { + // CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects + if ($this->getCaseID()) { + $hash = substr(sha1(CIVICRM_SITE_KEY . $this->getCaseID()), 0, 7); + $subject = "[case #$hash] $subject"; + } + return $subject; + } + +} diff --git a/CRM/Case/xml/Menu/Case.xml b/CRM/Case/xml/Menu/Case.xml index 0d77eb9f8e..91348e1c9a 100644 --- a/CRM/Case/xml/Menu/Case.xml +++ b/CRM/Case/xml/Menu/Case.xml @@ -135,4 +135,10 @@ civicrm/ajax/get-cases CRM_Case_Page_AJAX::getCases + + civicrm/case/email/add + action=add,task=email + Email + CRM_Case_Form_Task_Email + diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php index cb04bdc304..bbbd67ebf0 100644 --- a/CRM/Contact/Form/Task/EmailTrait.php +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -581,11 +581,6 @@ trait CRM_Contact_Form_Task_EmailTrait { * @throws \CRM_Core_Exception */ protected function getSubject(string $subject):string { - // CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects - if ($this->getCaseID()) { - $hash = substr(sha1(CIVICRM_SITE_KEY . $this->getCaseID()), 0, 7); - $subject = "[case #$hash] $subject"; - } return $subject; } diff --git a/templates/CRM/Case/Form/CaseView.tpl b/templates/CRM/Case/Form/CaseView.tpl index 89c4672778..0c2422ba03 100644 --- a/templates/CRM/Case/Form/CaseView.tpl +++ b/templates/CRM/Case/Form/CaseView.tpl @@ -45,7 +45,7 @@ {foreach from=$caseRoles.client item=client} - {$client.display_name}{if $client.email}{crmAPI var='email_type_id' entity='OptionValue' action='getsingle' return="value" name="Email" option_group_id="activity_type"}{/if} + {$client.display_name}{if $client.email}{crmAPI var='email_type_id' entity='OptionValue' action='getsingle' return="value" name="Email" option_group_id="activity_type"}{/if} {if $client.phone} diff --git a/templates/CRM/Case/Form/Task/Email.tpl b/templates/CRM/Case/Form/Task/Email.tpl new file mode 100644 index 0000000000..b47a6c442a --- /dev/null +++ b/templates/CRM/Case/Form/Task/Email.tpl @@ -0,0 +1 @@ +{include file="CRM/Contact/Form/Task/Email.tpl"} diff --git a/tests/phpunit/CRM/Case/Form/TaskTest.php b/tests/phpunit/CRM/Case/Form/TaskTest.php index 9e0e3610b0..01e6bbf5d5 100644 --- a/tests/phpunit/CRM/Case/Form/TaskTest.php +++ b/tests/phpunit/CRM/Case/Form/TaskTest.php @@ -17,9 +17,9 @@ class CRM_Case_Form_TaskTest extends CiviCaseTestCase { * * @dataProvider contactIDProvider */ - public function testSetContactIDs($input, $selected_search_results, $expected) { + public function testSetContactIDs($input, $selected_search_results, $expected): void { $this->createCaseContacts($input); - $task = new CRM_Case_Form_Task(); + $task = $this->getFormObject('CRM_Case_Form_Task'); // This simulates the selection from the search results list. What we're // testing is that no matter what order the cases were created or what -- 2.25.1