/** * Function that sends e-mail copy of activity * * @param $clientId * @param int $activityId activity Id * @param array $contacts array of related contact * * @param null $attachments * @param $caseId * * @return void * @access public */ static function sendActivityCopy($clientId, $activityId, $contacts, $attachments = NULL, $caseId) { if (!$activityId) { return; } $tplParams = $activityInfo = array(); //if its a case activity if ($caseId) { $activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityId, 'activity_type_id'); $nonCaseActivityTypes = CRM_Core_PseudoConstant::activityType(); if (!empty($nonCaseActivityTypes[$activityTypeId])) { $anyActivity = TRUE; } else { $anyActivity = FALSE; } $tplParams['isCaseActivity'] = 1; $tplParams['client_id'] = $clientId; } else { $anyActivity = TRUE; } $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isRedact = $xmlProcessorProcess->getRedactActivityEmail(); $xmlProcessorReport = new CRM_Case_XMLProcessor_Report(); $activityInfo = $xmlProcessorReport->getActivityInfo($clientId, $activityId, $anyActivity, $isRedact); if ($caseId) { $activityInfo['fields'][] = array('label' => 'Case ID', 'type' => 'String', 'value' => $caseId); } $tplParams['activity'] = $activityInfo; foreach ($tplParams['activity']['fields'] as $k => $val) { if (CRM_Utils_Array::value('label', $val) == ts('Subject')) { $activitySubject = $val['value']; break; } } $session = CRM_Core_Session::singleton(); // CRM-8926 If user is not logged in, use the activity creator as userID if (!($userID = $session->get('userID'))) { $userID = CRM_Activity_BAO_Activity::getSourceContactID($activityId); } //also create activities simultaneously of this copy. $activityParams = array(); $activityParams['source_record_id'] = $activityId; $activityParams['source_contact_id'] = $userID; $activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name'); $activityParams['activity_date_time'] = date('YmdHis'); $activityParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'); $activityParams['medium_id'] = CRM_Core_OptionGroup::getValue('encounter_medium', 'email', 'name'); $activityParams['case_id'] = $caseId; $activityParams['is_auto'] = 0; $activityParams['target_id'] = $clientId; $tplParams['activitySubject'] = $activitySubject; // if it’s a case activity, add hashed id to the template (CRM-5916) if ($caseId) { $tplParams['idHash'] = substr(sha1(CIVICRM_SITE_KEY . $caseId), 0, 7); } $result = array(); list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); $receiptFrom = "{$name} <{$address}>"; $recordedActivityParams = array(); foreach ($contacts as $mail => $info) { $tplParams['contact'] = $info; self::buildPermissionLinks($tplParams, $activityParams); $displayName = CRM_Utils_Array::value('display_name', $info); list($result[CRM_Utils_Array::value('contact_id', $info)], $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_case', 'valueName' => 'case_activity', 'contactId' => CRM_Utils_Array::value('contact_id', $info), 'tplParams' => $tplParams, 'from' => $receiptFrom, 'toName' => $displayName, 'toEmail' => $mail, 'attachments' => $attachments)); $activityParams['subject'] = $activitySubject . ' - copy sent to ' . $displayName; $activityParams['details'] = $message; if (!empty($result[$info['contact_id']])) { /* * Really only need to record one activity with all the targets combined. * Originally the template was going to possibly have different content, e.g. depending on permissions, * but it's always the same content at the moment. */ if (empty($recordedActivityParams)) { $recordedActivityParams = $activityParams; } else { $recordedActivityParams['subject'] .= "; {$displayName}"; } $recordedActivityParams['target_contact_id'][] = $info['contact_id']; } else { unset($result[CRM_Utils_Array::value('contact_id', $info)]); } } if (!empty($recordedActivityParams)) { $activity = CRM_Activity_BAO_Activity::create($recordedActivityParams); //create case_activity record if its case activity. if ($caseId) { $caseParams = array('activity_id' => $activity->id, 'case_id' => $caseId); self::processCaseActivity($caseParams); } } return $result; }