From 52c7b3a244764b246d593aa21c0eabe3b791f8c6 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Tue, 26 Mar 2013 18:19:18 +0530 Subject: [PATCH] worked on CRM-12216, added option to create multiple activities for each 'with/target contact' --- CRM/Activity/Form/Activity.php | 63 ++++++++++++++++++++---- templates/CRM/Activity/Form/Activity.tpl | 4 ++ 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index 205d12616a..e47154efd4 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -46,6 +46,13 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { */ public $_activityId; + /** + * store activity ids when multiple activities are created + * + * @var int + */ + public $_activityIds = array(); + /** * The id of activity type * @@ -733,6 +740,11 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } $this->assign('surveyActivity', $this->_isSurveyActivity); + // this option should be available only during add mode + if ($this->_action & CRM_Core_Action::ADD) { + $this->add('advcheckbox', 'is_multi_activity', ts('Create a separate activity for each selected contact?')); + } + $this->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger' ); @@ -1017,6 +1029,32 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $params['target_contact_id'] = $this->_contactIds; } + $activity = array(); + if (CRM_Utils_Array::value('is_multi_activity', $params) && + !CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id']) + ) { + $targetContacts = $params['target_contact_id']; + foreach($targetContacts as $targetContactId) { + $params['target_contact_id'] = array($targetContactId); + // save activity + $activity[] = $this->processActivity($params); + } + } + else { + // save activity + $activity = $this->processActivity($params); + } + + return array('activity' => $activity); + } + + /** + * Process activity creation + * + * @param array $params associated array of submitted values + * @access protected + */ + protected function processActivity(&$params) { $activityAssigned = array(); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { @@ -1056,12 +1094,17 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $this->endPostProcess($params, $activity); // CRM-9590 - $this->_activityId = $activity->id; + if (CRM_Utils_Array::value('is_multi_activity', $params)) { + $this->_activityIds[] = $activity->id; + } + else { + $this->_activityId = $activity->id; + } // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { - $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); + CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = ts('A followup activity has been scheduled.'); } @@ -1091,7 +1134,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $ics->addAttachment( $attachments, $mailToContacts ); // CRM-8400 add param with _currentlyViewedContactId for URL link in mail - $result = CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); + CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); $ics->cleanup(); @@ -1105,14 +1148,14 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2. %3', - array( - 1 => $params['subject'], - 2 => $followupStatus, - 3 => $mailStatus - ) - ), ts('Saved'), 'success'); + array( + 1 => $params['subject'], + 2 => $followupStatus, + 3 => $mailStatus + ) + ), ts('Saved'), 'success'); - return array('activity' => $activity); + return $activity; } /** diff --git a/templates/CRM/Activity/Form/Activity.tpl b/templates/CRM/Activity/Form/Activity.tpl index 4eb2c331bc..ec16caf04c 100644 --- a/templates/CRM/Activity/Form/Activity.tpl +++ b/templates/CRM/Activity/Form/Activity.tpl @@ -132,6 +132,10 @@ {ts}With Contact{/ts} {include file="CRM/Contact/Form/NewContact.tpl" noLabel=true skipBreak=true multiClient=true} + {if $action eq 1} +
+ {$form.is_multi_activity.html} {$form.is_multi_activity.label} + {/if} {else} {ts}With Contact{/ts} -- 2.25.1