cleanup
authoryashodha <yashodha.chaku@webaccessglobal.com>
Mon, 22 Jun 2015 12:30:39 +0000 (18:00 +0530)
committeryashodha <yashodha.chaku@webaccessglobal.com>
Mon, 22 Jun 2015 12:30:39 +0000 (18:00 +0530)
CRM/Activity/BAO/Activity.php
CRM/Activity/Form/Activity.php
CRM/Contact/Form/Task/EmailCommon.php

index e26d9aa20fdd5368bdbcf22e3ab7043aaa838e4f..e34301eae7ec2e0ef144f202c56d4523cc01af75 100644 (file)
@@ -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;
+  }
 }
index 39d9c37e319e9778bbf1e4049bc75a6309d0f9ad..ef3e8bfa5a39f1d0f14ffe58b25222b05a257404 100644 (file)
@@ -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 .= '<br />' . 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 .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s)."); 
+       }
       }
     }
 
index e3f2935d498d336996b51694014ebc0de777ab56..902e7798687c35328e8315b914b598157f7ac36e 100644 (file)
@@ -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 .= '<br />' . 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 .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s)."); 
+           }
           }
         }
       }