From: Dave Greenberg Date: Tue, 14 Jan 2014 02:26:20 +0000 (-0800) Subject: CRM-10043 - merge in changes to Activity.tpl and splitting of ActivityJs.tpl with... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=90b0558185037b057c6a381a4b71bb3d89c430b0;p=civicrm-core.git CRM-10043 - merge in changes to Activity.tpl and splitting of ActivityJs.tpl with the follow-up assignee changes. --- diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index e1b85267ca..f8ff6340a6 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -2023,6 +2023,7 @@ AND cl.modified_id = c.id $followupParams['activity_type_id'] = $params['followup_activity_type_id']; // Get Subject of Follow-up Activiity, CRM-4491 $followupParams['subject'] = CRM_Utils_Array::value('followup_activity_subject', $params); + $followupParams['assignee_contact_id'] = CRM_Utils_Array::value('followup_assignee_contact_id', $params); //create target contact for followup if (CRM_Utils_Array::value('target_contact_id', $params)) { diff --git a/CRM/Activity/BAO/ActivityAssignment.php b/CRM/Activity/BAO/ActivityAssignment.php index 8251649335..ffd021e054 100644 --- a/CRM/Activity/BAO/ActivityAssignment.php +++ b/CRM/Activity/BAO/ActivityAssignment.php @@ -105,7 +105,7 @@ AND civicrm_contact.is_deleted = 0 /** * Retrieve assignee names by activity_id * - * @param int $id ID of the activity + * @param array $activityIDs IDs of the activities * @param boolean $isDisplayName if set returns display names of assignees * @param boolean $skipDetails if false returns all details of assignee contact. * @@ -114,9 +114,9 @@ AND civicrm_contact.is_deleted = 0 * @access public * */ - static function getAssigneeNames($activityID, $isDisplayName = FALSE, $skipDetails = TRUE) { + static function getAssigneeNames($activityIDs, $isDisplayName = FALSE, $skipDetails = TRUE) { $assigneeNames = array(); - if (empty($activityID)) { + if (empty($activityIDs)) { return $assigneeNames; } $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); @@ -126,20 +126,21 @@ AND civicrm_contact.is_deleted = 0 if (!$skipDetails) { $whereClause = " AND ce.is_primary= 1"; } + $inClause = implode(",", $activityIDs); $query = " -SELECT contact_a.id, contact_a.sort_name, contact_a.display_name, ce.email +SELECT contact_a.id, contact_a.sort_name, contact_a.display_name, ce.email, + civicrm_activity_contact.activity_id FROM civicrm_contact contact_a INNER JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = contact_a.id LEFT JOIN civicrm_email ce ON ce.contact_id = contact_a.id -WHERE civicrm_activity_contact.activity_id = %1 +WHERE civicrm_activity_contact.activity_id IN ( $inClause ) AND contact_a.is_deleted = 0 AND civicrm_activity_contact.record_type_id = $assigneeID {$whereClause} "; - $queryParam = array(1 => array($activityID, 'Integer')); - $dao = CRM_Core_DAO::executeQuery($query, $queryParam); + $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { if (!$isDisplayName) { $assigneeNames[$dao->id] = $dao->sort_name; @@ -154,6 +155,7 @@ AND civicrm_activity_contact.record_type_id = $assigneeID $assigneeNames[$dao->id]['sort_name'] = $dao->sort_name; $assigneeNames[$dao->id]['email'] = $dao->email; $assigneeNames[$dao->id]['role'] = ts('Activity Assignee'); + $assigneeNames[$dao->id]['activity_id'] = $dao->activity_id; } } } diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index a323b8bbfc..4950aea6a2 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -304,7 +304,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { // Set title if (isset($activityTName)) { $activityName = CRM_Utils_Array::value($this->_activityTypeId, $activityTName); - $this->assign('pageTitle', ts('%1 Activity', $activityName)); + $this->assign('pageTitle', ts('%1 Activity', array( 1 => $activityName))); if ($this->_currentlyViewedContactId) { $displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId); @@ -810,10 +810,13 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $admin ); + $followupAssigneeContactField =& $this->add( 'text', 'followup_assignee_contact_id', ts('assignee') ); + $this->add('hidden', 'source_contact_qid', '', array('id' => 'source_contact_qid')); CRM_Contact_Form_NewContact::buildQuickForm($this); $this->add('text', 'assignee_contact_id', ts('assignee')); + $this->add( 'text', 'followup_assignee_contact_id', ts('assignee')); if ($sourceContactField->getValue()) { $this->assign('source_contact', $sourceContactField->getValue()); @@ -1040,6 +1043,13 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { else { $params['assignee_contact_id'] = array(); } + // civicrm-10043 - 14/12/13 + if ( CRM_Utils_Array::value( 'followup_assignee_contact_id', $params ) ) { + $params['followup_assignee_contact_id'] = explode( ',', $params['followup_assignee_contact_id'] ); + } + else { + $params['followup_assignee_contact_id'] = array( ); + } // get ids for associated contacts if (!$params['source_contact_id']) { @@ -1141,42 +1151,69 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { // create follow up activity if needed $followupStatus = ''; + $followupActivity = NULL; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { - CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); + $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = ts('A followup activity has been scheduled.'); } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; - if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && - CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, - 'activity_assignee_notification' - ) - ) { - $mailToContacts = array(); - $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE); + if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, + 'activity_assignee_notification')) { + $activityIDs = array($activity->id); + if ($followupActivity) { + $activityIDs = array_merge($activityIDs, array($followupActivity->id)); + } + $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityIDs, TRUE, FALSE); - //build an associative array with unique email addresses. - foreach ($activityAssigned as $id => $dnc) { - if (isset($id) && array_key_exists($id, $assigneeContacts)) { - $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; + if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { + $mailToContacts = array(); + + //build an associative array with unique email addresses. + foreach ($activityAssigned as $id => $dnc) { + if (isset($id) && array_key_exists($id, $assigneeContacts)) { + $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; + } } - } - if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { - //include attachments while sending a copy of activity. - $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); + 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); - $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); - // CRM-8400 add param with _currentlyViewedContactId for URL link in mail - CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); + $ics->cleanup(); - $ics->cleanup(); + $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) { + $mailToFollowupContacts = array(); + foreach ($assigneeContacts as $values) { + if ($values['activity_id'] == $followupActivity->id) { + $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); - $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); + 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)."); + } } } diff --git a/CRM/Case/Form/Activity.php b/CRM/Case/Form/Activity.php index 9b4bf0cfe8..be60a2c26d 100644 --- a/CRM/Case/Form/Activity.php +++ b/CRM/Case/Form/Activity.php @@ -619,7 +619,7 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity { $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s)."); } else { - $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE); + $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activity->id), TRUE, FALSE); $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s)."); } diff --git a/CRM/Case/XMLProcessor/Report.php b/CRM/Case/XMLProcessor/Report.php index a06b40f1b5..869db441c7 100644 --- a/CRM/Case/XMLProcessor/Report.php +++ b/CRM/Case/XMLProcessor/Report.php @@ -405,7 +405,7 @@ WHERE a.id = %1 if (!empty($activityDAO->assigneeID)) { //allow multiple assignee contacts.CRM-4503. - $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityDAO->id, TRUE); + $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activityDAO->id), TRUE); foreach ($assignee_contact_names as & $assignee) { // add Assignee to the strings to be redacted across the case session diff --git a/templates/CRM/Activity/Form/Activity.tpl b/templates/CRM/Activity/Form/Activity.tpl index 73a9f945ba..a155479296 100644 --- a/templates/CRM/Activity/Form/Activity.tpl +++ b/templates/CRM/Activity/Form/Activity.tpl @@ -261,6 +261,14 @@ {$form.followup_activity_subject.label} {$form.followup_activity_subject.html|crmAddClass:huge} + + {ts}Assign To{/ts} + {$form.followup_assignee_contact_id.html} + {edit}{ts}You can optionally assign this activity to someone. Assigned activities will appear in their Activities listing at CiviCRM Home.{/ts} + + {/edit} + + diff --git a/templates/CRM/Activity/Form/ActivityJs.tpl b/templates/CRM/Activity/Form/ActivityJs.tpl index 8ee7da8284..e8753aa6e2 100644 --- a/templates/CRM/Activity/Form/ActivityJs.tpl +++ b/templates/CRM/Activity/Form/ActivityJs.tpl @@ -26,18 +26,21 @@ {* added onload javascript for source contact*} {literal}