/** * @param $caseType * @param array $params * * @return bool * @throws Exception */ public function run($caseType, &$params) { $xml = $this->retrieve($caseType); if ($xml === FALSE) { $docLink = CRM_Utils_System::docURL2("user/case-management/setup"); CRM_Core_Error::fatal(ts("Configuration file could not be retrieved for case type = '%1' %2.", array(1 => $caseType, 2 => $docLink))); return FALSE; } $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $this->_isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->process($xml, $params); }
function run($caseType, &$params) { $xml = $this->retrieve($caseType); if ($xml === false) { require_once 'CRM/Utils/System.php'; $docLink = CRM_Utils_System::docURL2("CiviCase Configuration"); CRM_Core_Error::fatal(ts("Configuration file could not be retrieved for case type = '%1' %2.", array(1 => $caseType, 2 => $docLink))); return false; } require_once 'CRM/Case/XMLProcessor/Process.php'; $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $this->_isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->process($xml, $params); }
public function buildQuickForm() { $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->assign('multiClient', $isMultiClient); if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) { $title = 'Delete'; if ($this->_action & CRM_Core_Action::RENEW) { $title = 'Restore'; } $this->addButtons(array(array('type' => 'next', 'name' => $title, 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Case'); CRM_Custom_Form_CustomData::buildQuickForm($this); // we don't want to show button on top of custom form $this->assign('noPreCustomButton', TRUE); $s = CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'subject'); if (!is_array($s)) { $s = array(); } $this->add('text', 'activity_subject', ts('Subject'), array_merge($s, array('maxlength' => '128')), TRUE); $tags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if (!empty($tags)) { $this->add('select', 'tag', ts('Select Tags'), $tags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'title' => ts('- select -'))); } // build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', NULL, FALSE, TRUE); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); eval("CRM_Case_Form_Activity_{$this->_activityTypeFile}::buildQuickForm( \$this );"); }
/** * Build the form object. * * @return void */ public function preProcess() { $caseIds = CRM_Utils_Request::retrieve('caseid', 'String', $this); $this->_caseId = explode(',', $caseIds); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); if (!$this->_context) { $this->_context = 'caseActivity'; } $this->_crmDir = 'Case'; $this->assign('context', $this->_context); $result = parent::preProcess(); $scheduleStatusId = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name'); $this->assign('scheduleStatusId', $scheduleStatusId); if (!$this->_caseId && $this->_activityId) { $this->_caseId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $this->_activityId, 'case_id', 'activity_id'); } if ($this->_caseId) { $this->assign('caseId', $this->_caseId); $this->assign('countId', count($this->_caseId)); $this->assign('caseID', CRM_Utils_Array::first($this->_caseId)); } if (!$this->_caseId || !$this->_activityId && !$this->_activityTypeId) { CRM_Core_Error::fatal('required params missing.'); } //check for case activity access. if (!CRM_Case_BAO_Case::accessCiviCase()) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } //validate case id. if ($this->_caseId && !CRM_Core_Permission::check('access all cases and activities')) { $session = CRM_Core_Session::singleton(); $allCases = CRM_Case_BAO_Case::getCases(TRUE, $session->get('userID'), 'any'); if (!array_key_exists($this->_caseId, $allCases)) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } } //validate case activity id. if ($this->_activityId && $this->_action & CRM_Core_Action::UPDATE) { $valid = CRM_Case_BAO_Case::checkPermission($this->_activityId, 'edit', $this->_activityTypeId); if (!$valid) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } } foreach ($this->_caseId as $casePos => $caseId) { $this->_caseType[$casePos] = CRM_Case_BAO_Case::getCaseType($caseId, 'name'); } $this->assign('caseType', $this->_caseType); $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->assign('multiClient', $isMultiClient); foreach ($this->_caseId as $casePos => $caseId) { $clients[] = CRM_Case_BAO_Case::getContactNames($caseId); } $this->assign('client_names', $clients); $caseIds = implode(',', $this->_caseId); // set context for pushUserContext and for statusBounce if ($this->_context == 'fulltext') { if ($this->_action == CRM_Core_Action::UPDATE || $this->_action == CRM_Core_Action::DELETE) { $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1&context={$this->_context}"); } else { $url = CRM_Utils_System::url('civicrm/contact/search/custom', 'force=1'); } } else { $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"); } if (!$this->_activityId) { $caseTypes = CRM_Case_PseudoConstant::caseType(); if (empty($caseTypes) && $this->_activityTypeName == 'Change Case Type' && !$this->_caseId) { $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); CRM_Core_Error::statusBounce(ts("You do not have any active Case Types")); } // check if activity count is within the limit $xmlProcessor = new CRM_Case_XMLProcessor_Process(); foreach ($this->_caseId as $casePos => $caseId) { $caseType = $this->_caseType[$casePos]; $activityInst = $xmlProcessor->getMaxInstance($caseType); // If not bounce back and also provide activity edit link if (isset($activityInst[$this->_activityTypeName])) { $activityCount = CRM_Case_BAO_Case::getCaseActivityCount($caseId, $this->_activityTypeId); if ($activityCount >= $activityInst[$this->_activityTypeName]) { if ($activityInst[$this->_activityTypeName] == 1) { $atArray = array('activity_type_id' => $this->_activityTypeId); $activities = CRM_Case_BAO_Case::getCaseActivity($caseId, $atArray, $this->_currentUserId); $activities = array_keys($activities); $activities = $activities[0]; $editUrl = CRM_Utils_System::url('civicrm/case/activity', "reset=1&cid={$this->_currentlyViewedContactId}&caseid={$caseId}&action=update&id={$activities}"); } CRM_Core_Error::statusBounce(ts("You can not add another '%1' activity to this case. %2", array(1 => $this->_activityTypeName, 2 => ts("Do you want to <a %1>edit the existing activity</a>?", array(1 => "href='{$editUrl}'")))), $url); } } } } $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); }
/** * Function to process the form * * @access public * * @return None */ static function endPostProcess(&$form, &$params) { if ($form->_context == 'caseActivity') { return; } $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); if (!$isMultiClient && !$form->_currentlyViewedContactId) { CRM_Core_Error::fatal('Required parameter missing for OpenCase - end post processing'); } if (!$form->_currentUserId || !$params['case_id'] || !$params['case_type']) { CRM_Core_Error::fatal('Required parameter missing for OpenCase - end post processing'); } // 1. create case-contact if ($isMultiClient && $form->_context != 'case') { $client = explode(',', $params['contact'][1]); foreach ($client as $key => $cliId) { if (empty($cliId)) { CRM_Core_Error::fatal('contact_id cannot be empty'); } $contactParams = array('case_id' => $params['case_id'], 'contact_id' => $cliId); CRM_Case_BAO_Case::addCaseToContact($contactParams); } } else { $contactParams = array('case_id' => $params['case_id'], 'contact_id' => $form->_currentlyViewedContactId); CRM_Case_BAO_Case::addCaseToContact($contactParams); $client = $form->_currentlyViewedContactId; } // 2. initiate xml processor $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $xmlProcessorParams = array('clientID' => $client, 'creatorID' => $form->_currentUserId, 'standardTimeline' => 1, 'activityTypeName' => 'Open Case', 'caseID' => $params['case_id'], 'subject' => $params['activity_subject'], 'location' => $params['location'], 'activity_date_time' => $params['start_date'], 'duration' => CRM_Utils_Array::value('duration', $params), 'medium_id' => $params['medium_id'], 'details' => $params['activity_details']); if (array_key_exists('custom', $params) && is_array($params['custom'])) { $xmlProcessorParams['custom'] = $params['custom']; } // Add parameters for attachments $numAttachments = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'max_attachments'); for ($i = 1; $i <= $numAttachments; $i++) { $attachName = "attachFile_{$i}"; if (isset($params[$attachName]) && !empty($params[$attachName])) { $xmlProcessorParams[$attachName] = $params[$attachName]; } } $xmlProcessor->run($params['case_type'], $xmlProcessorParams); // status msg $params['statusMsg'] = ts('Case opened successfully.'); $buttonName = $form->controller->getButtonName(); $session = CRM_Core_Session::singleton(); if ($buttonName == $form->getButtonName('upload', 'new')) { if ($form->_context == 'standalone') { $session->replaceUserContext(CRM_Utils_System::url('civicrm/case/add', 'reset=1&action=add&context=standalone')); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=add&context=case&cid={$form->_contactID}")); } } }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET); $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->assign('multiClient', $isMultiClient); //pull the related cases. $this->assign('showRelatedCases', FALSE); if ($this->_showRelatedCases) { $relatedCases = $this->get('relatedCases'); if (!isset($relatedCases)) { $cId = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject); $caseId = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject); $relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId, $cId); } $this->assign('relatedCases', $relatedCases); $this->assign('showRelatedCases', TRUE); CRM_Utils_System::setTitle(ts('Related Cases')); return; } //check for civicase access. if (!CRM_Case_BAO_Case::accessCiviCase()) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } $this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); $this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases); $this->_contactID = $this->get('cid'); $this->_caseID = $this->get('id'); $fulltext = CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject); if ($fulltext == 'fulltext') { $this->assign('fulltext', $fulltext); } $this->assign('caseID', $this->_caseID); $this->assign('contactID', $this->_contactID); //validate case id. $this->_userCases = array(); $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); if (!$this->_hasAccessToAllCases) { $this->_userCases = CRM_Case_BAO_Case::getCases(FALSE, $userID, 'any'); if (!array_key_exists($this->_caseID, $this->_userCases)) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } } $this->assign('userID', $userID); if (CRM_Case_BAO_Case::caseCount($this->_contactID) >= 2) { $this->_mergeCases = TRUE; } $this->assign('mergeCases', $this->_mergeCases); //retrieve details about case $params = array('id' => $this->_caseID); $returnProperties = array('case_type_id', 'subject', 'status_id', 'start_date'); CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties); $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE); $caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name'); $caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID); $this->_caseDetails = array('case_type' => $caseType, 'case_status' => CRM_Utils_Array::value($values['case_status_id'], $statuses), 'case_subject' => CRM_Utils_Array::value('subject', $values), 'case_start_date' => $values['case_start_date']); $this->_caseType = $caseTypeName; $this->assign('caseDetails', $this->_caseDetails); $reportUrl = CRM_Utils_System::url('civicrm/case/report', "reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=", FALSE, NULL, FALSE); $this->assign('reportUrl', $reportUrl); // add to recently viewed $url = CRM_Utils_System::url('civicrm/contact/view/case', "action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home"); $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID); $this->assign('displayName', $displayName); CRM_Utils_System::setTitle($displayName . ' - ' . $caseType); $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case', "action=delete&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home"); } // Add the recently viewed case CRM_Utils_Recent::add($displayName . ' - ' . $caseType, $url, $this->_caseID, 'Case', $this->_contactID, NULL, $recentOther); //get the related cases for given case. $relatedCases = $this->get('relatedCases'); if (!isset($relatedCases)) { $relatedCases = CRM_Case_BAO_Case::getRelatedCases($this->_caseID, $this->_contactID); $relatedCases = empty($relatedCases) ? FALSE : $relatedCases; $this->set('relatedCases', $relatedCases); } $this->assign('hasRelatedCases', (bool) $relatedCases); if ($relatedCases) { $this->assign('relatedCaseLabel', ts('%1 Related Case', array('count' => count($relatedCases), 'plural' => '%1 Related Cases'))); $this->assign('relatedCaseUrl', CRM_Utils_System::url('civicrm/contact/view/case', array('id' => $this->_caseID, 'cid' => $this->_contactID, 'relatedCases' => 1, 'action' => 'view'))); } $entitySubType = !empty($values['case_type_id']) ? $values['case_type_id'] : NULL; $this->assign('caseTypeID', $entitySubType); $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Case', $this, $this->_caseID, NULL, $entitySubType); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { $tx = 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); 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; $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 CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { 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_Core_DAO::VALUE_SEPARATOR . $caseParams['case_type_id'] . CRM_Core_DAO::VALUE_SEPARATOR; } 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'); if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $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 to set variables up before form is built * * @return void * @access public */ public function preProcess() { $this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET); require_once 'CRM/Case/XMLProcessor/Process.php'; $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->assign('multiClient', $isMultiClient); //pull the related cases. $this->assign('showRelatedCases', false); if ($this->_showRelatedCases) { $relatedCases = $this->get('relatedCases'); if (!isset($relatedCases)) { $cId = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject); $caseId = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject); $relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId, $cId); } $this->assign('relatedCases', $relatedCases); $this->assign('showRelatedCases', true); return; } //check for civicase access. if (!CRM_Case_BAO_Case::accessCiviCase()) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } $this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); $this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases); $this->_contactID = $this->get('cid'); $this->_caseID = $this->get('id'); $fulltext = CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject); if ($fulltext == 'fulltext') { $this->assign('fulltext', $fulltext); } $this->assign('caseID', $this->_caseID); $this->assign('contactID', $this->_contactID); //validate case id. $this->_userCases = array(); $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); if (!$this->_hasAccessToAllCases) { $this->_userCases = CRM_Case_BAO_Case::getCases(false, $userID); if (!array_key_exists($this->_caseID, $this->_userCases)) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } } $this->assign('userID', $userID); if (CRM_Case_BAO_Case::caseCount($this->_contactID) >= 2) { $this->_mergeCases = true; } $this->assign('mergeCases', $this->_mergeCases); //retrieve details about case $params = array('id' => $this->_caseID); $returnProperties = array('case_type_id', 'subject', 'status_id', 'start_date'); CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties); $values['case_type_id'] = explode(CRM_Case_BAO_Case::VALUE_SEPERATOR, CRM_Utils_Array::value('case_type_id', $values)); require_once 'CRM/Case/PseudoConstant.php'; $statuses = CRM_Case_PseudoConstant::caseStatus('label', false); $caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name'); $caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID); $this->_caseDetails = array('case_type' => $caseType, 'case_status' => $statuses[$values['case_status_id']], 'case_subject' => CRM_Utils_Array::value('subject', $values), 'case_start_date' => $values['case_start_date']); $this->_caseType = $caseTypeName; $this->assign('caseDetails', $this->_caseDetails); $newActivityUrl = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=", false, null, false); $this->assign('newActivityUrl', $newActivityUrl); // Send Email activity requires a different URL format from all other activities $newActivityEmailUrl = CRM_Utils_System::url('civicrm/activity/add', "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype=", false, null, false); $this->assign('newActivityEmailUrl', $newActivityEmailUrl); $reportUrl = CRM_Utils_System::url('civicrm/case/report', "reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=", false, null, false); $this->assign('reportUrl', $reportUrl); // add to recently viewed require_once 'CRM/Utils/Recent.php'; require_once 'CRM/Contact/BAO/Contact.php'; $url = CRM_Utils_System::url('civicrm/contact/view/case', "action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home"); $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID); $this->assign('displayName', $displayName); $title = $displayName . ' - ' . $caseType; $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case', "action=delete&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home"); } // add the recently created case CRM_Utils_Recent::add($displayName . ' - ' . $caseType, $url, $this->_caseID, 'Case', $this->_contactID, null, $recentOther); //get the related cases for given case. $relatedCases = $this->get('relatedCases'); if (!isset($relatedCases)) { $relatedCases = CRM_Case_BAO_Case::getRelatedCases($this->_caseID, $this->_contactID); $relatedCases = empty($relatedCases) ? false : $relatedCases; $this->set('relatedCases', $relatedCases); } $this->assign('hasRelatedCases', $relatedCases); }