From 2bbb4a91982a3d31ffde11d6c02990596bac85ba Mon Sep 17 00:00:00 2001 From: yashodha Date: Mon, 22 Jun 2015 18:00:39 +0530 Subject: [PATCH] cleanup --- CRM/Activity/BAO/Activity.php | 20 +++++++++++++++ CRM/Activity/Form/Activity.php | 35 +++++++-------------------- CRM/Contact/Form/Task/EmailCommon.php | 12 +++------ 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index e26d9aa20f..e34301eae7 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -2727,4 +2727,24 @@ INNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n } } + /** + * Send activity as attachment + * + * @param object $activity + * @param array $mailToContacts + * + * @return boolean + */ + public static function sendToAssignee($activity, $mailToContacts) { + if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { + $ics = new CRM_Activity_BAO_ICalendar($activity); + $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); + $ics->addAttachment($attachments, $mailToContacts); + + CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); + $ics->cleanup(); + return TRUE; + } + return FALSE; + } } diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index 39d9c37e31..ef3e8bfa5a 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -1089,21 +1089,11 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } } - if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { - //include attachments while sending a copy of activity. - $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); - - $ics = new CRM_Activity_BAO_ICalendar($activity); - $ics->addAttachment($attachments, $mailToContacts); - - // CRM-8400 add param with _currentlyViewedContactId for URL link in mail - CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); - - $ics->cleanup(); - - $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); - } - } + $sent = CRM_Activity_BAO_Activity::sendToAssignee($activity, $mailToContacts); + if ($sent) { + $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); + } + } // Also send email to follow-up activity assignees if set if ($followupActivity) { @@ -1114,17 +1104,10 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } } - if (!CRM_Utils_array::crmIsEmptyArray($mailToFollowupContacts)) { - $ics = new CRM_Activity_BAO_ICalendar($followupActivity); - $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $followupActivity->id); - $ics->addAttachment($attachments, $mailToFollowupContacts); - - CRM_Case_BAO_Case::sendActivityCopy(NULL, $followupActivity->id, $mailToFollowupContacts, $attachments, NULL); - - $ics->cleanup(); - - $mailStatus .= '
' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s)."); - } + $sentFollowup = CRM_Activity_BAO_Activity::sendToAssignee($followupActivity, $mailToFollowupContacts); + if ($sentFollowup) { + $mailStatus .= '
' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s)."); + } } } diff --git a/CRM/Contact/Form/Task/EmailCommon.php b/CRM/Contact/Form/Task/EmailCommon.php index e3f2935d49..902e779868 100644 --- a/CRM/Contact/Form/Task/EmailCommon.php +++ b/CRM/Contact/Form/Task/EmailCommon.php @@ -541,14 +541,10 @@ class CRM_Contact_Form_Task_EmailCommon { $mailToFollowupContacts[$values['email']] = $values; } - if (!CRM_Utils_array::crmIsEmptyArray($mailToFollowupContacts)) { - $ics = new CRM_Activity_BAO_ICalendar($followupActivity); - $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $followupActivity->id); - $ics->addAttachment($attachments, $mailToFollowupContacts); - CRM_Case_BAO_Case::sendActivityCopy(NULL, $followupActivity->id, $mailToFollowupContacts, $attachments, NULL); - $ics->cleanup(); - $followupStatus .= '
' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s)."); - } + $sentFollowup = CRM_Activity_BAO_Activity::sendToAssignee($followupActivity, $mailToFollowupContacts); + if ($sentFollowup) { + $mailStatus .= '
' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s)."); + } } } } -- 2.25.1