Skip to content

Commit

Permalink
[Ref] Move id fetching to the classes
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Aug 13, 2021
1 parent 483eccb commit db4d540
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 23 deletions.
71 changes: 48 additions & 23 deletions CRM/Contact/Form/Task/EmailTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ public function buildQuickForm() {

if ($this->_single) {
// also fix the user context stack
if ($this->_caseId) {
if ($this->getCaseID()) {
$ccid = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseContact', $this->_caseId,
'contact_id', 'case_id'
);
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"&reset=1&action=view&cid={$ccid}&id={$this->_caseId}"
"&reset=1&action=view&cid={$ccid}&id=" . $this->getCaseID()
);
}
elseif ($this->_context) {
Expand Down Expand Up @@ -412,7 +412,7 @@ public function submit($formValues) {
}

// send the mail
list($sent, $activityIds) = CRM_Activity_BAO_Activity::sendEmail(
[$sent, $activityIds] = CRM_Activity_BAO_Activity::sendEmail(
$formattedContactDetails,
$this->getSubject($formValues['subject']),
$formValues['text_message'],
Expand All @@ -425,9 +425,9 @@ public function submit($formValues) {
$bcc,
array_keys($this->_toContactDetails),
$additionalDetails,
$this->getVar('_contributionIds') ?? [],
$this->getContributionIDs(),
CRM_Utils_Array::value('campaign_id', $formValues),
$this->getVar('_caseId')
$this->getCaseID()
);

if ($sent) {
Expand Down Expand Up @@ -583,24 +583,6 @@ protected function getAttachments(array $formValues): array {
return $attachments;
}

/**
* Get the subject for the message.
*
* The case handling should possibly be on the case form.....
*
* @param string $subject
*
* @return string
*/
protected function getSubject(string $subject):string {
// CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects
if (isset($this->_caseId) && is_numeric($this->_caseId)) {
$hash = substr(sha1(CIVICRM_SITE_KEY . $this->_caseId), 0, 7);
$subject = "[case #$hash] $subject";
}
return $subject;
}

/**
* Create any follow up activities.
*
Expand Down Expand Up @@ -661,4 +643,47 @@ public static function saveTemplateFormRule(array $fields) {
return empty($errors) ? TRUE : $errors;
}

/**
* Get selected contribution IDs.
*
* @return array
*/
protected function getContributionIDs(): array {
return [];
}

/**
* Get case ID - if any.
*
* @return int|null
*
* @throws \CRM_Core_Exception
*/
protected function getCaseID(): ?int {
$caseID = CRM_Utils_Request::retrieve('caseid', 'String', $this);
if ($caseID) {
return (int) $caseID;
}
return NULL;
}

/**
* 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;
}

}
11 changes: 11 additions & 0 deletions CRM/Contribute/Form/Task/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
class CRM_Contribute_Form_Task_Email extends CRM_Contribute_Form_Task {
use CRM_Contact_Form_Task_EmailTrait;

/**
* Get selected contribution IDs.
*
* @return array
*
* @throws \CRM_Core_Exception
*/
protected function getContributionIDs(): array {
return $this->getIDs();
}

/**
* List available tokens for this form.
*
Expand Down

0 comments on commit db4d540

Please sign in to comment.