/** * Process the form submission. * * * @param array $params * * @return void */ public function postProcess($params = NULL) { $transaction = new CRM_Core_Transaction(); if ($this->_action & CRM_Core_Action::DELETE) { $statusMsg = NULL; //block deleting activities which affects //case attributes.CRM-4543 $activityCondition = " AND v.name IN ('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date')"; $caseAttributeActivities = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $activityCondition); if (!array_key_exists($this->_activityTypeId, $caseAttributeActivities)) { $params = array('id' => $this->_activityId); $activityDelete = CRM_Activity_BAO_Activity::deleteActivity($params, TRUE); if ($activityDelete) { $statusMsg = ts('The selected activity has been moved to the Trash. You can view and / or restore deleted activities by checking "Deleted Activities" from the Case Activities search filter (under Manage Case).<br />'); } } else { $statusMsg = ts("Selected Activity cannot be deleted."); } $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus('', $statusMsg, 'info'); return; } if ($this->_action & CRM_Core_Action::RENEW) { $statusMsg = NULL; $params = array('id' => $this->_activityId); $activityRestore = CRM_Activity_BAO_Activity::restoreActivity($params); if ($activityRestore) { $statusMsg = ts('The selected activity has been restored.<br />'); } CRM_Core_Session::setStatus('', $statusMsg, 'info'); return; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); //set parent id if its edit mode if ($parentId = CRM_Utils_Array::value('parent_id', $this->_defaults)) { $params['parent_id'] = $parentId; } // store the dates with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); $params['activity_type_id'] = $this->_activityTypeId; // format with contact (target contact) values if (isset($params['target_contact_id'])) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } // format activity custom data if (!empty($params['hidden_custom'])) { if ($this->_activityId) { // unset custom fields-id from params since we want custom // fields to be saved for new activity. foreach ($params as $key => $value) { $match = array(); if (preg_match('/^(custom_\\d+_)(\\d+)$/', $key, $match)) { $params[$match[1] . '-1'] = $params[$key]; // for autocomplete transfer hidden value instead of label if ($params[$key] && isset($params[$key . '_id'])) { $params[$match[1] . '-1_id'] = $params[$key . '_id']; unset($params[$key . '_id']); } unset($params[$key]); } } } // build custom data getFields array $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_activityId, 'Activity'); } // assigning formatted value if (!empty($params['assignee_contact_id'])) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } if (isset($this->_activityId)) { // activity which hasn't been modified by a user yet if ($this->_defaults['is_auto'] == 1) { $params['is_auto'] = 0; } // always create a revision of an case activity. CRM-4533 $newActParams = $params; // add target contact values in update mode if (empty($params['target_contact_id']) && !empty($this->_defaults['target_contact'])) { $newActParams['target_contact_id'] = $this->_defaults['target_contact']; } } if (!isset($newActParams)) { // add more attachments if needed for old activity CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($params); foreach ($this->_caseId as $key => $val) { $params['case_id'] = $val; // activity create/update $activity = CRM_Activity_BAO_Activity::create($params); $vvalue[] = array('case_id' => $val, 'actId' => $activity->id); // call end post process, after the activity has been created/updated. $this->endPostProcess($params, $activity); } } else { // since the params we need to set are very few, and we don't want rest of the // work done by bao create method , lets use dao object to make the changes $params = array('id' => $this->_activityId); $params['is_current_revision'] = 0; $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->save(); } // create a new version of activity if activity was found to // have been modified/created by user if (isset($newActParams)) { // set proper original_id if (!empty($this->_defaults['original_id'])) { $newActParams['original_id'] = $this->_defaults['original_id']; } else { $newActParams['original_id'] = $activity->id; } //is_current_revision will be set to 1 by default. // add attachments if any CRM_Core_BAO_File::formatAttachment($newActParams, $newActParams, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($newActParams); foreach ($this->_caseId as $key => $val) { $newActParams['case_id'] = $val; $activity = CRM_Activity_BAO_Activity::create($newActParams); $vvalue[] = array('case_id' => $val, 'actId' => $activity->id); // call end post process, after the activity has been created/updated. $this->endPostProcess($newActParams, $activity); } // copy files attached to old activity if any, to new one, // as long as users have not selected the 'delete attachment' option. if (empty($newActParams['is_delete_attachment'])) { CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id); } // copy back params to original var $params = $newActParams; } foreach ($vvalue as $vkey => $vval) { if ($vval['actId']) { // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $vval['actId']); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { CRM_Core_Form_Tag::postProcess($params['taglist'], $vval['actId'], 'civicrm_activity', $this); } } // update existing case record if needed $caseParams = $params; $caseParams['id'] = $vval['case_id']; if (!empty($caseParams['case_status_id'])) { $caseParams['status_id'] = $caseParams['case_status_id']; } // unset params intended for activities only unset($caseParams['subject'], $caseParams['details'], $caseParams['status_id'], $caseParams['custom']); $case = CRM_Case_BAO_Case::create($caseParams); // create case activity record $caseParams = array('activity_id' => $vval['actId'], 'case_id' => $vval['case_id']); CRM_Case_BAO_Case::processCaseActivity($caseParams); } // Insert civicrm_log record for the activity (e.g. store the // created / edited by contact id and date for the activity) // Note - civicrm_log is already created by CRM_Activity_BAO_Activity::create() // send copy to selected contacts. $mailStatus = ''; $mailToContacts = array(); //CRM-5695 //check for notification settings for assignee contacts $selectedContacts = array('contact_check'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $selectedContacts[] = 'assignee_contact_id'; } foreach ($vvalue as $vkey => $vval) { foreach ($selectedContacts as $dnt => $val) { if (array_key_exists($val, $params) && !CRM_Utils_array::crmIsEmptyArray($params[$val])) { if ($val == 'contact_check') { $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s)."); } else { $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($vval['actId']), TRUE, FALSE); $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s)."); } //build an associative array with unique email addresses. foreach ($params[$val] as $key => $value) { if ($val == 'contact_check') { $id = $key; } else { $id = $value; } if (isset($id) && array_key_exists($id, $this->_relatedContacts) && isset($this->_relatedContacts[$id]['email'])) { //if email already exists in array then append with ', ' another role only otherwise add it to array. if ($contactDetails = CRM_Utils_Array::value($this->_relatedContacts[$id]['email'], $mailToContacts)) { $caseRole = CRM_Utils_Array::value('role', $this->_relatedContacts[$id]); $mailToContacts[$this->_relatedContacts[$id]['email']]['role'] = $contactDetails['role'] . ', ' . $caseRole; } else { $mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id]; } } } } } $extraParams = array('case_id' => $vval['case_id'], 'client_id' => $this->_currentlyViewedContactId); $result = CRM_Activity_BAO_Activity::sendToAssignee($activity, $mailToContacts, $extraParams); if (empty($result)) { $mailStatus = ''; } // create follow up activity if needed $followupStatus = ''; if (!empty($params['followup_activity_type_id'])) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($vval['actId'], $params); if ($followupActivity) { $caseParams = array('activity_id' => $followupActivity->id, 'case_id' => $vval['case_id']); CRM_Case_BAO_Case::processCaseActivity($caseParams); $followupStatus = ts("A followup activity has been scheduled.") . '<br /><br />'; } } $title = ts("%1 Saved", array(1 => $this->_activityTypeName)); CRM_Core_Session::setStatus($followupStatus . $mailStatus, $title, 'success'); } }
/** * Function to process the form * * @access public * @return None */ public function postProcess($params = null) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted sucessfully.")); return; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } //set activity type id if (!CRM_Utils_Array::value('activity_type_id', $params)) { $params['activity_type_id'] = $this->_activityTypeId; } if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', false, false, null, null, true)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // assigning formated value to related variable if (CRM_Utils_Array::value('target_contact_id', $params)) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } else { $params['source_contact_id'] = $this->_submitValues['source_contact_qid']; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); // format target params if (!$this->_single) { $params['target_contact_id'] = $this->_contactIds; } $activityAssigned = array(); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // 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); $followupStatus = "A followup activity has been scheduled."; } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; $config =& CRM_Core_Config::singleton(); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && $config->activityAssigneeNotification) { $mailToContacts = array(); $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, 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($mailToContacts)) { //include attachments while sendig a copy of activity. $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); require_once "CRM/Case/BAO/Case.php"; $result = CRM_Case_BAO_Case::sendActivityCopy(null, $activity->id, $mailToContacts, $attachments, null); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // set status message if (CRM_Utils_Array::value('subject', $params)) { $params['subject'] = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2. %3', array(1 => $params['subject'], 2 => $followupStatus, 3 => $mailStatus))); return array('activity' => $activity); }
/** * Process the form after the input has been submitted and validated. * * @param CRM_Core_Form $form */ public static function postProcess(&$form) { if (count($form->_contactIds) > self::MAX_EMAILS_KILL_SWITCH) { CRM_Core_Error::fatal(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.', array(1 => self::MAX_EMAILS_KILL_SWITCH))); } // check and ensure that $formValues = $form->controller->exportValues($form->getName()); $fromEmail = $formValues['fromEmailAddress']; $from = CRM_Utils_Array::value($fromEmail, $form->_emails); $subject = $formValues['subject']; // CRM-13378: Append CC and BCC information at the end of Activity Details and format cc and bcc fields $elements = array('cc_id', 'bcc_id'); $additionalDetails = NULL; $ccValues = $bccValues = array(); foreach ($elements as $element) { if (!empty($formValues[$element])) { $allEmails = explode(',', $formValues[$element]); foreach ($allEmails as $value) { list($contactId, $email) = explode('::', $value); $contactURL = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$contactId}", TRUE); switch ($element) { case 'cc_id': $ccValues['email'][] = '"' . $form->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>'; $ccValues['details'][] = "<a href='{$contactURL}'>" . $form->_contactDetails[$contactId]['display_name'] . "</a>"; break; case 'bcc_id': $bccValues['email'][] = '"' . $form->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>'; $bccValues['details'][] = "<a href='{$contactURL}'>" . $form->_contactDetails[$contactId]['display_name'] . "</a>"; break; } } } } $cc = $bcc = ''; if (!empty($ccValues)) { $cc = implode(',', $ccValues['email']); $additionalDetails .= "\ncc : " . implode(", ", $ccValues['details']); } if (!empty($bccValues)) { $bcc = implode(',', $bccValues['email']); $additionalDetails .= "\nbcc : " . implode(", ", $bccValues['details']); } // CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects if (isset($form->_caseId) && is_numeric($form->_caseId)) { $hash = substr(sha1(CIVICRM_SITE_KEY . $form->_caseId), 0, 7); $subject = "[case #{$hash}] {$subject}"; } // process message template if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) { $messageTemplate = array('msg_text' => $formValues['text_message'], 'msg_html' => $formValues['html_message'], 'msg_subject' => $formValues['subject'], 'is_active' => TRUE); if (!empty($formValues['saveTemplate'])) { $messageTemplate['msg_title'] = $formValues['saveTemplateName']; CRM_Core_BAO_MessageTemplate::add($messageTemplate); } if (!empty($formValues['template']) && !empty($formValues['updateTemplate'])) { $messageTemplate['id'] = $formValues['template']; unset($messageTemplate['msg_title']); CRM_Core_BAO_MessageTemplate::add($messageTemplate); } } $attachments = array(); CRM_Core_BAO_File::formatAttachment($formValues, $attachments, NULL, NULL); // format contact details array to handle multiple emails from same contact $formattedContactDetails = array(); $tempEmails = array(); foreach ($form->_contactIds as $key => $contactId) { // if we dont have details on this contactID, we should ignore // potentially this is due to the contact not wanting to receive email if (!isset($form->_contactDetails[$contactId])) { continue; } $email = $form->_toContactEmails[$key]; // prevent duplicate emails if same email address is selected CRM-4067 // we should allow same emails for different contacts $emailKey = "{$contactId}::{$email}"; if (!in_array($emailKey, $tempEmails)) { $tempEmails[] = $emailKey; $details = $form->_contactDetails[$contactId]; $details['email'] = $email; unset($details['email_id']); $formattedContactDetails[] = $details; } } // send the mail list($sent, $activityId) = CRM_Activity_BAO_Activity::sendEmail($formattedContactDetails, $subject, $formValues['text_message'], $formValues['html_message'], NULL, NULL, $from, $attachments, $cc, $bcc, array_keys($form->_toContactDetails), $additionalDetails); $followupStatus = ''; if ($sent) { $followupActivity = NULL; if (!empty($formValues['followup_activity_type_id'])) { $params['followup_activity_type_id'] = $formValues['followup_activity_type_id']; $params['followup_activity_subject'] = $formValues['followup_activity_subject']; $params['followup_date'] = $formValues['followup_date']; $params['followup_date_time'] = $formValues['followup_date_time']; $params['target_contact_id'] = $form->_contactIds; $params['followup_assignee_contact_id'] = explode(',', $formValues['followup_assignee_contact_id']); $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activityId, $params); $followupStatus = ts('A followup activity has been scheduled.'); if (Civi::settings()->get('activity_assignee_notification')) { if ($followupActivity) { $mailToFollowupContacts = array(); $assignee = array($followupActivity->id); $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($assignee, TRUE, FALSE); foreach ($assigneeContacts as $values) { $mailToFollowupContacts[$values['email']] = $values; } $sentFollowup = CRM_Activity_BAO_Activity::sendToAssignee($followupActivity, $mailToFollowupContacts); if ($sentFollowup) { $followupStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s)."); } } } } $count_success = count($form->_toContactDetails); CRM_Core_Session::setStatus(ts('One message was sent successfully. ', array('plural' => '%count messages were sent successfully. ', 'count' => $count_success)) . $followupStatus, ts('Message Sent', array('plural' => 'Messages Sent', 'count' => $count_success)), 'success'); } // Display the name and number of contacts for those email is not sent. // php 5.4 throws out a notice since the values of these below arrays are arrays. // the behavior is not documented in the php manual, but it does the right thing // suppressing the notices to get things in good shape going forward $emailsNotSent = @array_diff_assoc($form->_allContactDetails, $form->_contactDetails); if ($emailsNotSent) { $not_sent = array(); foreach ($emailsNotSent as $contactId => $values) { $displayName = $values['display_name']; $email = $values['email']; $contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contactId}"); $not_sent[] = "<a href='{$contactViewUrl}' title='{$email}'>{$displayName}</a>" . ($values['on_hold'] ? '(' . ts('on hold') . ')' : ''); } $status = '(' . ts('because no email address on file or communication preferences specify DO NOT EMAIL or Contact is deceased or Primary email address is On Hold') . ')<ul><li>' . implode('</li><li>', $not_sent) . '</li></ul>'; CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array('count' => count($emailsNotSent), 'plural' => '%count Messages Not Sent')), 'info'); } if (isset($form->_caseId)) { // if case-id is found in the url, create case activity record $cases = explode(',', $form->_caseId); foreach ($cases as $key => $val) { if (is_numeric($val)) { $caseParams = array('activity_id' => $activityId, 'case_id' => $val); CRM_Case_BAO_Case::processCaseActivity($caseParams); } } } }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return array rows in the given offset and rowCount */ function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_activityClause); $rows = array(); $mailingIDs = CRM_Mailing_BAO_Mailing::mailingACLIDs(); $accessCiviMail = CRM_Core_Permission::check('access CiviMail'); //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel(); while ($result->fetch()) { $row = array(); // ignore rows where we dont have an activity id if (empty($result->activity_id)) { continue; } // the columns we are interested in foreach (self::$_properties as $property) { if (isset($result->{$property})) { $row[$property] = $result->{$property}; } } $contactId = CRM_Utils_Array::value('contact_id', $row); if (!$contactId) { $contactId = CRM_Utils_Array::value('source_contact_id', $row); } $row['target_contact_name'] = CRM_Activity_BAO_ActivityTarget::getTargetNames($row['activity_id']); $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($row['activity_id']); if (CRM_Utils_Array::value('source_contact_id', $row)) { $row['source_contact_name'] = CRM_Contact_BAO_Contact::displayName($row['source_contact_id']); } if ($this->_context == 'search') { $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->activity_id; } $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id); $accessMailingReport = FALSE; $activityType = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name', TRUE); $activityTypeId = CRM_Utils_Array::key($row['activity_type'], $activityType); if ($row['activity_is_test']) { $row['activity_type'] = $row['activity_type'] . " (test)"; } $bulkActivityTypeID = CRM_Utils_Array::key('Bulk Email', $activityType); $row['mailingId'] = ''; if ($accessCiviMail && in_array($result->source_record_id, $mailingIDs) && $bulkActivityTypeID == $activityTypeId) { $row['mailingId'] = CRM_Utils_System::url('civicrm/mailing/report', "mid={$result->source_record_id}&reset=1&cid={$result->source_contact_id}&context=activitySelector"); $row['recipients'] = ts('(recipients)'); $row['target_contact_name'] = ''; $row['assignee_contact_name'] = ''; $accessMailingReport = TRUE; } $activityActions = new CRM_Activity_Selector_Activity($result->contact_id, NULL); $actionLinks = $activityActions->actionLinks($activityTypeId, CRM_Utils_Array::value('source_record_id', $row), $accessMailingReport, CRM_Utils_Array::value('activity_id', $row), $this->_key, $this->_compContext); $row['action'] = CRM_Core_Action::formLink($actionLinks, NULL, array('id' => $result->activity_id, 'cid' => $contactId, 'cxt' => $this->_context)); //carry campaign to selector. $row['campaign'] = CRM_Utils_Array::value($result->activity_campaign_id, $allCampaigns); $row['campaign_id'] = $result->activity_campaign_id; if ($engagementLevel = CRM_Utils_Array::value('activity_engagement_level', $row)) { $row['activity_engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel); } $rows[] = $row; } return $rows; }
/** * Pass a known activity id as an id and make sure 1 Assignees is retrieved */ public function testGetAssigneeNamesOneId() { $activity = $this->activityCreate(); $assignees = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activity['id'])); $this->assertEquals(count($assignees), 1, '1 assignee names retrieved'); }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return array rows in the given offset and rowCount */ function &getRows($action, $offset, $rowCount, $sort, $output = null) { $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, false, false, false, false, $this->_activityClause); $rows = array(); require_once 'CRM/Mailing/BAO/Mailing.php'; require_once 'CRM/Mailing/Info.php'; $mailingIDs =& CRM_Mailing_BAO_Mailing::mailingACLIDs(); $accessCiviMail = CRM_Core_Permission::check('access CiviMail'); while ($result->fetch()) { $row = array(); // ignore rows where we dont have an activity id if (empty($result->activity_id)) { continue; } // the columns we are interested in foreach (self::$_properties as $property) { if (isset($result->{$property})) { $row[$property] = $result->{$property}; } } $contactId = CRM_Utils_Array::value('contact_id', $row); if (!$contactId) { $contactId = CRM_Utils_Array::value('source_contact_id', $row); } $row['target_contact_name'] = CRM_Activity_BAO_ActivityTarget::getTargetNames($row['activity_id']); $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($row['activity_id']); if (CRM_Utils_Array::value('source_contact_id', $row)) { $row['source_contact_name'] = CRM_Contact_BAO_Contact::displayName($row['source_contact_id']); } if ($this->_context == 'search') { $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->activity_id; } require_once 'CRM/Contact/BAO/Contact/Utils.php'; $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, false, $result->contact_id); $accessMailingReport = false; $activityType = CRM_Core_PseudoConstant::activityType(true, true); $activityTypeId = CRM_Utils_Array::key($row['activity_type'], $activityType); if ($row['activity_is_test']) { $row['activity_type'] = $row['activity_type'] . " (test)"; } $bulkActivityTypeID = CRM_Utils_Array::key('Bulk Email', $activityType); if ($accessCiviMail && in_array($result->source_record_id, $mailingIDs) && $bulkActivityTypeID == $activityTypeId) { $row['mailingId'] = CRM_Utils_System::url('civicrm/mailing/report', "mid={$result->source_record_id}&reset=1&cid={$result->source_contact_id}&context=activitySelector"); $row['recipients'] = ts('(recipients)'); $row['target_contact_name'] = ''; $row['assignee_contact_name'] = ''; $accessMailingReport = true; } require_once 'CRM/Activity/Selector/Activity.php'; $activityActions = new CRM_Activity_Selector_Activity($result->contact_id, null); $actionLinks = $activityActions->actionLinks($activityTypeId, CRM_Utils_Array::value('source_record_id', $row), $accessMailingReport, CRM_Utils_Array::value('activity_id', $row), $this->_key, $this->_compContext); $row['action'] = CRM_Core_Action::formLink($actionLinks, null, array('id' => $result->activity_id, 'cid' => $contactId, 'cxt' => $this->_context)); $rows[] = $row; } return $rows; }
/** * Function to delete the activity * @param array $params associated array * * @return void * @access public * */ public function deleteActivity(&$params, $moveToTrash = false) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); if (!$moveToTrash) { if (!isset($params['id'])) { if (is_array($params['activity_type_id'])) { $activityTypes = implode(',', $params['activity_type_id']); } else { $activityTypes = $params['activity_type_id']; } $query = "DELETE FROM civicrm_activity WHERE source_record_id = {$params['source_record_id']} AND activity_type_id IN ( {$activityTypes} )"; $dao = CRM_Core_DAO::executeQuery($query); } else { $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $result = $activity->delete(); } } else { $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->is_deleted = 1; $result = $activity->save(); //log activty delete.CRM-4525. $logMsg = "Case Activity deleted for"; $msgs = array(); $sourceContactId = CRM_Core_DAO::getfieldValue('CRM_Activity_DAO_Activity', $activity->id, 'source_contact_id'); if ($sourceContactId) { $msgs[] = " source={$sourceContactId}"; } //get target contacts. $targetContactIds = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id); if (!empty($targetContactIds)) { $msgs[] = " target =" . implode(',', array_keys($targetContactIds)); } //get assignee contacts. $assigneeContactIds = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id); if (!empty($assigneeContactIds)) { $msgs[] = " assignee =" . implode(',', array_keys($assigneeContactIds)); } $logMsg .= implode(', ', $msgs); self::logActivityAction($activity, $logMsg); } // delete the recently created Activity require_once 'CRM/Utils/Recent.php'; if ($result) { $activityRecent = array('id' => $activity->id, 'type' => 'Activity'); CRM_Utils_Recent::del($activityRecent); } $transaction->commit(); return $result; }
/** * Process activity creation * * @param array $params associated array of submitted values * @access protected */ protected function processActivity(&$params) { $activityAssigned = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // CRM-9590 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)) { 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); //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); $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)."); } } // set status message $subject = ''; if (CRM_Utils_Array::value('subject', $params)) { $subject = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2 %3', array(1 => $subject, 2 => $followupStatus, 3 => $mailStatus)), ts('Saved'), 'success'); return $activity; }
/** * process the form after the input has been submitted and validated * * @access public * * @return None */ public function postProcess() { $params = $this->exportValues(); $this->_contacts = array(); //get assignee contacts if ($params['assigned_to']) { foreach ($this->_activityHolderIds as $key => $id) { $ids = array_keys(CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($id)); $this->_contacts = array_merge($this->_contacts, $ids); } } //get target contacts if ($params['with_contact']) { foreach ($this->_activityHolderIds as $key => $id) { $ids = array_keys(CRM_Activity_BAO_ActivityTarget::getTargetNames($id)); $this->_contacts = array_merge($this->_contacts, $ids); } } //get 'Added by' contacts if ($params['created_by']) { parent::setContactIDs(); if (!empty($this->_contactIds)) { $this->_contacts = array_merge($this->_contacts, $this->_contactIds); } } $this->_contacts = array_unique($this->_contacts); //bounce to pick option if no contacts to send to if (empty($this->_contacts)) { $urlParams = "_qf_PickOption_display=true&qfKey={$params['qfKey']}"; $urlRedirect = CRM_Utils_System::url('civicrm/activity/search', $urlParams); CRM_Core_Error::statusBounce(ts('It appears you have no contacts with emails from the selected recipients.'), $urlRedirect); } $this->set('contacts', $this->_contacts); }
function alterDisplay(&$rows) { // custom code to alter rows $entryFound = false; $activityType = CRM_Core_PseudoConstant::activityType(true, true, false, 'label', true); $activityStatus = CRM_Core_PseudoConstant::activityStatus(); $viewLinks = false; require_once 'CRM/Core/Permission.php'; if (CRM_Core_Permission::check('access CiviCRM')) { $viewLinks = true; $onHover = ts('View Contact Summary for this Contact'); $onHoverAct = ts('View Activity Record'); } foreach ($rows as $rowNum => $row) { if (array_key_exists('civicrm_contact_contact_source', $row)) { if ($value = $row['civicrm_contact_source_contact_id']) { if ($viewLinks) { $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $value, $this->_absoluteUrl); $rows[$rowNum]['civicrm_contact_contact_source_link'] = $url; $rows[$rowNum]['civicrm_contact_contact_source_hover'] = $onHover; } $entryFound = true; } } if (array_key_exists('civicrm_contact_contact_assignee', $row) && $row['civicrm_activity_assignment_assignee_contact_id']) { $assignee = array(); //retrieve all contact assignees and build list with links require_once 'CRM/Activity/BAO/ActivityAssignment.php'; $activity_assignment_ids = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($row['civicrm_activity_id'], false, true); foreach ($activity_assignment_ids as $cid => $assignee_name) { if ($viewLinks) { $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $cid, $this->_absoluteUrl); $assignee[] = '<a title="' . $onHover . '" href="' . $url . '">' . $assignee_name . '</a>'; } else { $assignee[] = $assignee_name; } } $rows[$rowNum]['civicrm_contact_contact_assignee'] = implode('; ', $assignee); $entryFound = true; } if (array_key_exists('civicrm_contact_contact_target', $row) && $row['civicrm_activity_target_target_contact_id']) { $target = array(); //retrieve all contact targets and build list with links require_once 'CRM/Activity/BAO/ActivityTarget.php'; $activity_target_ids = CRM_Activity_BAO_ActivityTarget::getTargetNames($row['civicrm_activity_id']); foreach ($activity_target_ids as $cid => $target_name) { if ($viewLinks) { $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $cid, $this->_absoluteUrl); $target[] = '<a title="' . $onHover . '" href="' . $url . '">' . $target_name . '</a>'; } else { $target[] = $target_name; } } $rows[$rowNum]['civicrm_contact_contact_target'] = implode('; ', $target); $entryFound = true; } if (array_key_exists('civicrm_activity_activity_type_id', $row)) { if ($value = $row['civicrm_activity_activity_type_id']) { $rows[$rowNum]['civicrm_activity_activity_type_id'] = $activityType[$value]; if ($viewLinks) { // case activities get a special view link if ($rows[$rowNum]['civicrm_case_activity_case_id']) { $url = CRM_Utils_System::url("civicrm/case/activity/view", 'reset=1&cid=' . $rows[$rowNum]['civicrm_contact_source_contact_id'] . '&aid=' . $rows[$rowNum]['civicrm_activity_id'] . '&caseID=' . $rows[$rowNum]['civicrm_case_activity_case_id'], $this->_absoluteUrl); } else { $url = CRM_Utils_System::url("civicrm/contact/view/activity", 'action=view&reset=1&cid=' . $rows[$rowNum]['civicrm_contact_source_contact_id'] . '&id=' . $rows[$rowNum]['civicrm_activity_id'] . '&atype=' . $value, $this->_absoluteUrl); } $rows[$rowNum]['civicrm_activity_activity_type_id_link'] = $url; $rows[$rowNum]['civicrm_activity_activity_type_id_hover'] = $onHoverAct; } $entryFound = true; } } if (array_key_exists('civicrm_activity_status_id', $row)) { if ($value = $row['civicrm_activity_status_id']) { $rows[$rowNum]['civicrm_activity_status_id'] = $activityStatus[$value]; $entryFound = true; } } if (!$entryFound) { break; } } }
/** * Function to process the form * * @access public * * @return None */ public function postProcess($params = NULL) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash); // delete tags for the entity $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted successfully.")); return; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } //set activity type id if (!CRM_Utils_Array::value('activity_type_id', $params)) { $params['activity_type_id'] = $this->_activityTypeId; } if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // assigning formated value to related variable if (CRM_Utils_Array::value('target_contact_id', $params)) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } else { $params['source_contact_id'] = $this->_submitValues['source_contact_qid']; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); // format target params if (!$this->_single) { $params['target_contact_id'] = $this->_contactIds; } $activityAssigned = array(); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // CRM-9590 $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); $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); //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 sendig a copy of activity. $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); // CRM-8400 add param with _currentlyViewedContactId for URL link in mail $result = CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // set status message if (CRM_Utils_Array::value('subject', $params)) { $params['subject'] = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2. %3', array(1 => $params['subject'], 2 => $followupStatus, 3 => $mailStatus))); return array('activity' => $activity); }
function &getActivity($clientID, $activityDAO, &$activityTypeInfo) { require_once 'CRM/Core/OptionGroup.php'; if (empty($this->_redactionStringRules)) { $this->_redactionStringRules = array(); } $activity = array(); $activity['fields'] = array(); if ($clientID) { $clientID = CRM_Utils_Type::escape($clientID, 'Integer'); $activity['editURL'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}"); $client = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name'); // add Client SortName as well as Display to the strings to be redacted across the case session // suffixed with a randomly generated 4-digit number if (!array_key_exists($client, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($client => 'name_' . rand(10000, 100000))); $clientSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name'); if (!array_key_exists($clientSortName, $this->_redactionStringRules)) { $this->_redactionStringRules[$clientSortName] = $this->_redactionStringRules[$client]; } } $activity['fields'][] = array('label' => 'Client', 'value' => $this->redact($client), 'type' => 'String'); } // Activity Type info is a special field $activity['fields'][] = array('label' => 'Activity Type', 'value' => $activityTypeInfo['label'], 'type' => 'String'); $activity['fields'][] = array('label' => 'Subject', 'value' => $this->redact($activityDAO->subject), 'type' => 'Memo'); $creator = $this->getCreatedBy($activityDAO->id); // add Creator to the strings to be redacted across the case session if (!array_key_exists($creator, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($creator => 'name_' . rand(10000, 100000))); } $activity['fields'][] = array('label' => 'Created By', 'value' => $this->redact($creator), 'type' => 'String'); $reporter = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $activityDAO->source_contact_id, 'display_name'); // add Reporter SortName as well as Display to the strings to be redacted across the case session // suffixed with a randomly generated 4-digit number if (!array_key_exists($reporter, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($reporter => 'name_' . rand(10000, 100000))); $reporterSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $activityDAO->source_contact_id, 'sort_name'); if (!array_key_exists($reporterSortName, $this->_redactionStringRules)) { $this->_redactionStringRules[$reporterSortName] = $this->_redactionStringRules[$reporter]; } } $activity['fields'][] = array('label' => 'Reported By', 'value' => $this->redact($reporter), 'type' => 'String'); // For Emails, include the recipient if (($activityTypeInfo['name'] == 'Email' || $activityTypeInfo['name'] == 'Inbound Email') && $activityDAO->targetID) { // Re-lookup the target ID since the DAO only has the first recipient if there are multiple. // Maybe not the best solution. require_once 'CRM/Activity/BAO/ActivityTarget.php'; $targetNames = CRM_Activity_BAO_ActivityTarget::getTargetNames($activityDAO->id); $targetRedacted = array(); foreach ($targetNames as $targetID => $target) { // add Recipient SortName as well as Display to the strings to be redacted across the case session // suffixed with a randomly generated 4-digit number if (!array_key_exists($target, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($target => 'name_' . rand(10000, 100000))); $targetSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name'); if (!array_key_exists($targetSortName, $this->_redactionStringRules)) { $this->_redactionStringRules[$targetSortName] = $this->_redactionStringRules[$target]; } } $targetRedacted[] = $this->redact($target); } $activity['fields'][] = array('label' => 'Recipient', 'value' => implode('; ', $targetRedacted), 'type' => 'String'); } if ($activityDAO->assigneeID) { //allow multiple assignee contacts.CRM-4503. require_once 'CRM/Activity/BAO/ActivityAssignment.php'; $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityDAO->id, true); foreach ($assignee_contact_names as &$assignee) { // add Assignee to the strings to be redacted across the case session $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($assignee => 'name_' . rand(10000, 100000))); $assignee = $this->redact($assignee); } $assigneeContacts = implode(', ', $assignee_contact_names); $activity['fields'][] = array('label' => 'Assigned To', 'value' => $assigneeContacts, 'type' => 'String'); } if ($activityDAO->medium_id) { $activity['fields'][] = array('label' => 'Medium', 'value' => CRM_Core_OptionGroup::getLabel('encounter_medium', $activityDAO->medium_id), 'type' => 'String'); } $activity['fields'][] = array('label' => 'Location', 'value' => $activityDAO->location, 'type' => 'String'); $activity['fields'][] = array('label' => 'Date and Time', 'value' => $activityDAO->activity_date_time, 'type' => 'Date'); $activity['fields'][] = array('label' => 'Details', 'value' => $this->redact($activityDAO->details), 'type' => 'Memo'); // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg if ($activityDAO->duration) { $activity['fields'][] = array('label' => 'Duration', 'value' => $activityDAO->duration . ' ' . ts('minutes'), 'type' => 'Int'); } $activity['fields'][] = array('label' => 'Status', 'value' => CRM_Core_OptionGroup::getLabel('activity_status', $activityDAO->status_id), 'type' => 'String'); $activity['fields'][] = array('label' => 'Priority', 'value' => CRM_Core_OptionGroup::getLabel('priority', $activityDAO->priority_id), 'type' => 'String'); //for now empty custom groups $activity['customGroups'] = $this->getCustomData($clientID, $activityDAO, $activityTypeInfo); //CRM_Core_Error::debug($activity); exit(); return $activity; }
/** * Function to delete the activity * * @param array $params associated array * * @return void * @access public * */ public static function deleteActivity(&$params, $moveToTrash = FALSE) { // CRM-9137 if (CRM_Utils_Array::value('id', $params) && !is_array($params['id'])) { CRM_Utils_Hook::pre('delete', 'Activity', $params['id'], $params); } else { CRM_Utils_Hook::pre('delete', 'Activity', NULL, $params); } $transaction = new CRM_Core_Transaction(); if (is_array(CRM_Utils_Array::value('source_record_id', $params))) { $sourceRecordIds = implode(',', $params['source_record_id']); } else { $sourceRecordIds = CRM_Utils_Array::value('source_record_id', $params); } $result = NULL; if (!$moveToTrash) { if (!isset($params['id'])) { if (is_array($params['activity_type_id'])) { $activityTypes = implode(',', $params['activity_type_id']); } else { $activityTypes = $params['activity_type_id']; } $query = "DELETE FROM civicrm_activity WHERE source_record_id IN ({$sourceRecordIds}) AND activity_type_id IN ( {$activityTypes} )"; $dao = CRM_Core_DAO::executeQuery($query); } else { $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $result = $activity->delete(); // CRM-8708 $activity->case_id = CRM_Case_BAO_Case::getCaseIdByActivityId($activity->id); } } else { $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->is_deleted = 1; $result = $activity->save(); //log activty delete.CRM-4525. $logMsg = 'Case Activity deleted for'; $msgs = array(); $sourceContactId = CRM_Core_DAO::getfieldValue('CRM_Activity_DAO_Activity', $activity->id, 'source_contact_id'); if ($sourceContactId) { $msgs[] = " source={$sourceContactId}"; } //get target contacts. $targetContactIds = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id); if (!empty($targetContactIds)) { $msgs[] = " target =" . implode(',', array_keys($targetContactIds)); } //get assignee contacts. $assigneeContactIds = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id); if (!empty($assigneeContactIds)) { $msgs[] = " assignee =" . implode(',', array_keys($assigneeContactIds)); } $logMsg .= implode(', ', $msgs); self::logActivityAction($activity, $logMsg); } // delete the recently created Activity if ($result) { $activityRecent = array('id' => $activity->id, 'type' => 'Activity'); CRM_Utils_Recent::del($activityRecent); } $transaction->commit(); if (isset($activity)) { // CRM-8708 $activity->case_id = CRM_Case_BAO_Case::getCaseIdByActivityId($activity->id); CRM_Utils_Hook::post('delete', 'Activity', $activity->id, $activity); } return $result; }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $statusMsg = null; //block deleting activities which affects //case attributes.CRM-4543 $activityCondition = " AND v.name IN ('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date')"; $caseAttributeActivities = CRM_Core_OptionGroup::values('activity_type', false, false, false, $activityCondition); if (!array_key_exists($this->_activityTypeId, $caseAttributeActivities)) { $params = array('id' => $this->_activityId); $activityDelete = CRM_Activity_BAO_Activity::deleteActivity($params, true); if ($activityDelete) { $statusMsg = ts('The selected activity has been moved to the Trash. You can view and / or restore deleted activities by checking "Deleted Activities" from the Case Activities search filter (under Manage Case).<br />'); } } else { $statusMsg = ts("Selected Activity cannot be deleted."); } require_once 'CRM/Core/BAO/EntityTag.php'; $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus($statusMsg); return; } if ($this->_action & CRM_Core_Action::RENEW) { $statusMsg = null; $params = array('id' => $this->_activityId); $activityRestore = CRM_Activity_BAO_Activity::restoreActivity($params); if ($activityRestore) { $statusMsg = ts('The selected activity has been restored.<br />'); } CRM_Core_Session::setStatus($statusMsg); return; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); if ($params['source_contact_id']) { $params['source_contact_id'] = $params['source_contact_qid']; } //set parent id if its edit mode if ($parentId = CRM_Utils_Array::value('parent_id', $this->_defaults)) { $params['parent_id'] = $parentId; } // required for status msg $recordStatus = 'created'; // store the dates with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); $params['activity_type_id'] = $this->_activityTypeId; require_once 'CRM/Case/XMLProcessor/Process.php'; $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->assign('multiClient', $isMultiClient); $targetContacts = array($this->_currentlyViewedContactId); if (CRM_Utils_Array::value('hidden_target_contact', $params) && CRM_Utils_Array::value('target_contact_id', $params)) { $targetContacts = array_unique(explode(',', $params['target_contact_id'])); } $params['target_contact_id'] = $targetContacts; // format activity custom data if (CRM_Utils_Array::value('hidden_custom', $params)) { if ($this->_activityId) { // unset custom fields-id from params since we want custom // fields to be saved for new activity. foreach ($params as $key => $value) { $match = array(); if (preg_match('/^(custom_\\d+_)(\\d+)$/', $key, $match)) { $params[$match[1] . '-1'] = $params[$key]; // for autocomplete transfer hidden value instead of label if ($params[$key] && isset($params[$key . '_id'])) { $params[$match[1] . '-1_id'] = $params[$key . '_id']; unset($params[$key . '_id']); } unset($params[$key]); } } } // build custom data getFields array $customFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', false, false, null, null, true)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $assineeContacts = explode(',', $params['assignee_contact_id']); $assineeContacts = array_unique($assineeContacts); unset($params['assignee_contact_id']); } else { $params['assignee_contact_id'] = $assineeContacts = array(); } if (isset($this->_activityId)) { // activity which hasn't been modified by a user yet if ($this->_defaults['is_auto'] == 1) { $params['is_auto'] = 0; } // always create a revision of an case activity. CRM-4533 $newActParams = $params; // add target contact values in update mode if (empty($params['target_contact_id']) && !empty($this->_defaults['target_contact'])) { $newActParams['target_contact_id'] = $this->_defaults['target_contact']; } // record status for status msg $recordStatus = 'updated'; } if (!isset($newActParams)) { // add more attachments if needed for old activity CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($params); $params['case_id'] = $this->_caseId; // activity create/update $activity = CRM_Activity_BAO_Activity::create($params); // call end post process, after the activity has been created/updated. $this->endPostProcess($params, $activity); } else { // since the params we need to set are very few, and we don't want rest of the // work done by bao create method , lets use dao object to make the changes $params = array('id' => $this->_activityId); $params['is_current_revision'] = 0; $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->save(); } // create a new version of activity if activity was found to // have been modified/created by user if (isset($newActParams)) { // set proper original_id if (CRM_Utils_Array::value('original_id', $this->_defaults)) { $newActParams['original_id'] = $this->_defaults['original_id']; } else { $newActParams['original_id'] = $activity->id; } //is_current_revision will be set to 1 by default. // add attachments if any CRM_Core_BAO_File::formatAttachment($newActParams, $newActParams, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($newActParams); $newActParams['case_id'] = $this->_caseId; $activity = CRM_Activity_BAO_Activity::create($newActParams); // call end post process, after the activity has been created/updated. $this->endPostProcess($newActParams, $activity); // copy files attached to old activity if any, to new one, // as long as users have not selected the 'delete attachment' option. if (!CRM_Utils_Array::value('is_delete_attachment', $newActParams)) { CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id); } // copy back params to original var $params = $newActParams; } if ($activity->id) { // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { require_once 'CRM/Core/Form/Tag.php'; CRM_Core_Form_Tag::postProcess($params['taglist'], $activity->id, 'civicrm_activity', $this); } } $params['assignee_contact_id'] = $assineeContacts; // update existing case record if needed $caseParams = $params; $caseParams['id'] = $this->_caseId; if (CRM_Utils_Array::value('case_type_id', $caseParams)) { $caseParams['case_type_id'] = CRM_Case_BAO_Case::VALUE_SEPERATOR . $caseParams['case_type_id'] . CRM_Case_BAO_Case::VALUE_SEPERATOR; } if (CRM_Utils_Array::value('case_status_id', $caseParams)) { $caseParams['status_id'] = $caseParams['case_status_id']; } // unset params intended for activities only unset($caseParams['subject'], $caseParams['details'], $caseParams['status_id'], $caseParams['custom']); $case = CRM_Case_BAO_Case::create($caseParams); // create case activity record $caseParams = array('activity_id' => $activity->id, 'case_id' => $this->_caseId); CRM_Case_BAO_Case::processCaseActivity($caseParams); // create activity assignee records $assigneeParams = array('activity_id' => $activity->id); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); $activityId = isset($this->_activityId) ? $this->_activityId : $activity->id; $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); foreach ($params['assignee_contact_id'] as $key => $id) { $assigneeParams['assignee_contact_id'] = $id; CRM_Activity_BAO_Activity::createActivityAssignment($assigneeParams); } //modify assigne_contact as per newly assigned contact before sending copy. CRM-4509. $params['assignee_contact_id'] = $activityAssigned; } // Insert civicrm_log record for the activity (e.g. store the // created / edited by contact id and date for the activity) // Note - civicrm_log is already created by CRM_Activity_BAO_Activity::create() // send copy to selected contacts. $mailStatus = ''; $mailToContacts = array(); //CRM-5695 //check for notification settings for assignee contacts $selectedContacts = array('contact_check'); $config =& CRM_Core_Config::singleton(); if ($config->activityAssigneeNotification) { $selectedContacts[] = 'assignee_contact_id'; } foreach ($selectedContacts as $dnt => $val) { if (array_key_exists($val, $params) && !CRM_Utils_array::crmIsEmptyArray($params[$val])) { if ($val == 'contact_check') { $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); $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s)."); } //build an associative array with unique email addresses. foreach ($params[$val] as $id => $dnc) { if (isset($id) && array_key_exists($id, $this->_relatedContacts)) { //if email already exists in array then append with ', ' another role only otherwise add it to array. if ($contactDetails = CRM_Utils_Array::value($this->_relatedContacts[$id]['email'], $mailToContacts)) { $caseRole = CRM_Utils_Array::value('role', $this->_relatedContacts[$id]); $mailToContacts[$this->_relatedContacts[$id]['email']]['role'] = $contactDetails['role'] . ', ' . $caseRole; } else { $mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id]; } } } } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sendig a copy of activity. $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); $result = CRM_Case_BAO_Case::sendActivityCopy($this->_currentlyViewedContactId, $activity->id, $mailToContacts, $attachments, $this->_caseId); if (empty($result)) { $mailStatus = ''; } } else { $mailStatus = ''; } // 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); if ($followupActivity) { $caseParams = array('activity_id' => $followupActivity->id, 'case_id' => $this->_caseId); CRM_Case_BAO_Case::processCaseActivity($caseParams); $followupStatus = ts("A followup activity has been scheduled."); } } CRM_Core_Session::setStatus(ts("'%1' activity has been %2. %3 %4", array(1 => $this->_activityTypeName, 2 => $recordStatus, 3 => $followupStatus, 4 => $mailStatus))); }
function &getActivity($clientID, $activityDAO, &$activityTypeInfo) { if (empty($this->_redactionStringRules)) { $this->_redactionStringRules = array(); } $activity = array(); $activity['fields'] = array(); if ($clientID) { $clientID = CRM_Utils_Type::escape($clientID, 'Integer'); if (!in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) { $activity['editURL'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}"); } else { $activity['editURL'] = ''; } $client = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name'); // add Client SortName as well as Display to the strings to be redacted across the case session // suffixed with a randomly generated 4-digit number if (!array_key_exists($client, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($client => 'name_' . rand(10000, 100000))); $clientSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name'); if (!array_key_exists($clientSortName, $this->_redactionStringRules)) { $this->_redactionStringRules[$clientSortName] = $this->_redactionStringRules[$client]; } } $activity['fields'][] = array('label' => 'Client', 'value' => $this->redact($client), 'type' => 'String'); } $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); if (!empty($activityDAO->targetID)) { // Re-lookup the target ID since the DAO only has the first recipient if there are multiple. // Maybe not the best solution. $targetNames = CRM_Activity_BAO_ActivityContact::getNames($activityDAO->id, $targetID); $processTarget = FALSE; $label = ts('With Contact(s)'); if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) { $processTarget = TRUE; $label = ts('Recipient'); } if (!$processTarget) { foreach ($targetNames as $targetID => $targetName) { if ($targetID != $clientID) { $processTarget = TRUE; break; } } } if ($processTarget) { $targetRedacted = array(); foreach ($targetNames as $targetID => $target) { // add Recipient SortName as well as Display to the strings to be redacted across the case session // suffixed with a randomly generated 4-digit number if (!array_key_exists($target, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($target => 'name_' . rand(10000, 100000))); $targetSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name'); if (!array_key_exists($targetSortName, $this->_redactionStringRules)) { $this->_redactionStringRules[$targetSortName] = $this->_redactionStringRules[$target]; } } $targetRedacted[] = $this->redact($target); } $activity['fields'][] = array('label' => $label, 'value' => implode('; ', $targetRedacted), 'type' => 'String'); } } // Activity Type info is a special field $activity['fields'][] = array('label' => ts('Activity Type'), 'value' => $activityTypeInfo['label'], 'type' => 'String'); $activity['fields'][] = array('label' => ts('Subject'), 'value' => htmlspecialchars($this->redact($activityDAO->subject)), 'type' => 'Memo'); $creator = $this->getCreatedBy($activityDAO->id); // add Creator to the strings to be redacted across the case session if (!array_key_exists($creator, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($creator => 'name_' . rand(10000, 100000))); } $activity['fields'][] = array('label' => ts('Created By'), 'value' => $this->redact($creator), 'type' => 'String'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $source_contact_id = CRM_Activity_BAO_Activity::getActivityContact($activityDAO->id, $sourceID); $reporter = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $source_contact_id, 'display_name'); // add Reporter SortName as well as Display to the strings to be redacted across the case session // suffixed with a randomly generated 4-digit number if (!array_key_exists($reporter, $this->_redactionStringRules)) { $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($reporter => 'name_' . rand(10000, 100000))); $reporterSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $source_contact_id, 'sort_name'); if (!array_key_exists($reporterSortName, $this->_redactionStringRules)) { $this->_redactionStringRules[$reporterSortName] = $this->_redactionStringRules[$reporter]; } } $activity['fields'][] = array('label' => ts('Reported By'), 'value' => $this->redact($reporter), 'type' => 'String'); if (!empty($activityDAO->assigneeID)) { //allow multiple assignee contacts.CRM-4503. $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 $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($assignee => 'name_' . rand(10000, 100000))); $assignee = $this->redact($assignee); } $assigneeContacts = implode(', ', $assignee_contact_names); $activity['fields'][] = array('label' => ts('Assigned To'), 'value' => $assigneeContacts, 'type' => 'String'); } if ($activityDAO->medium_id) { $activity['fields'][] = array('label' => ts('Medium'), 'value' => CRM_Core_OptionGroup::getLabel('encounter_medium', $activityDAO->medium_id, FALSE), 'type' => 'String'); } $activity['fields'][] = array('label' => ts('Location'), 'value' => $activityDAO->location, 'type' => 'String'); $activity['fields'][] = array('label' => ts('Date and Time'), 'value' => $activityDAO->activity_date_time, 'type' => 'Date'); $activity['fields'][] = array('label' => ts('Details'), 'value' => $this->redact(CRM_Utils_String::stripAlternatives($activityDAO->details)), 'type' => 'Memo'); // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg if ($activityDAO->duration) { $activity['fields'][] = array('label' => ts('Duration'), 'value' => $activityDAO->duration . ' ' . ts('minutes'), 'type' => 'Int'); } $activity['fields'][] = array('label' => ts('Status'), 'value' => CRM_Core_OptionGroup::getLabel('activity_status', $activityDAO->status_id), 'type' => 'String'); $activity['fields'][] = array('label' => ts('Priority'), 'value' => CRM_Core_OptionGroup::getLabel('priority', $activityDAO->priority_id), 'type' => 'String'); //for now empty custom groups $activity['customGroups'] = $this->getCustomData($clientID, $activityDAO, $activityTypeInfo); return $activity; }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ public function postProcess() { $params = $this->exportValues(); $this->_contacts = array(); //get assignee contacts if ($params['assigned_to']) { require_once 'CRM/Activity/BAO/ActivityAssignment.php'; foreach ($this->_activityHolderIds as $key => $id) { $ids = array_keys(CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($id)); $this->_contacts = array_merge($this->_contacts, $ids); } } //get target contacts if ($params['with_contact']) { require_once 'CRM/Activity/BAO/ActivityTarget.php'; foreach ($this->_activityHolderIds as $key => $id) { $ids = array_keys(CRM_Activity_BAO_ActivityTarget::getTargetNames($id)); $this->_contacts = array_merge($this->_contacts, $ids); } } //get 'Added by' contacts if ($params['created_by']) { parent::setContactIDs(); if (!empty($this->_contactIds)) { $this->_contacts = array_merge($this->_contacts, $this->_contactIds); } } $this->_contacts = array_unique($this->_contacts); $this->set('contacts', $this->_contacts); }
/** * Process activity creation. * * @param array $params * Associated array of submitted values. * * @return self|null|object */ protected function processActivity(&$params) { $activityAssigned = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } // Save static tags. CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); // Save free tags. if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // CRM-9590 if (!empty($params['is_multi_activity'])) { $this->_activityIds[] = $activity->id; } else { $this->_activityId = $activity->id; } // create follow up activity if needed $followupStatus = ''; $followupActivity = NULL; if (!empty($params['followup_activity_type_id'])) { $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 (Civi::settings()->get('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); 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]; } } $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) { $mailToFollowupContacts = array(); foreach ($assigneeContacts as $values) { if ($values['activity_id'] == $followupActivity->id) { $mailToFollowupContacts[$values['email']] = $values; } } $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)."); } } } // set status message $subject = ''; if (!empty($params['subject'])) { $subject = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2 %3', array(1 => $subject, 2 => $followupStatus, 3 => $mailStatus)), ts('Saved'), 'success'); return $activity; }
/** * Function to delete the activity * @param array $params associated array * * @return void * @access public * */ public function deleteActivity(&$params, $moveToTrash = false) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $activity =& new CRM_Activity_DAO_Activity(); $activity->copyValues($params); if (!$moveToTrash) { $result = $activity->delete(); } else { $activity->is_deleted = 1; $result = $activity->save(); //log activty delete.CRM-4525. $logMsg = "Case Activity deleted for"; $msgs = array(); $sourceContactId = CRM_Core_DAO::getfieldValue('CRM_Activity_DAO_Activity', $activity->id, 'source_contact_id'); if ($sourceContactId) { $msgs[] = " source={$sourceContactId}"; } //get target contacts. $targetContactIds = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id); if (!empty($targetContactIds)) { $msgs[] = " target =" . implode(',', array_keys($targetContactIds)); } //get assignee contacts. $assigneeContactIds = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id); if (!empty($assigneeContactIds)) { $msgs[] = " assigne =" . implode(',', array_keys($assigneeContactIds)); } $logMsg .= implode(', ', $msgs); self::logActivityAction($activity, $logMsg); } // delete the recently created Activity require_once 'CRM/Utils/Recent.php'; if ($result) { CRM_Utils_Recent::del($activity->id); } $transaction->commit(); return $result; }