/** * Internal function to retrieve a case. * * @param int $caseId * * @return array (reference) case object * */ function _civicrm_api3_case_read($caseId, $options) { $return = CRM_Utils_Array::value('return', $options, array()); $dao = new CRM_Case_BAO_Case(); $dao->id = $caseId; if ($dao->find(TRUE)) { $case = array(); _civicrm_api3_object_to_array($dao, $case); // Legacy support for client_id - TODO: in apiv4 remove 'client_id' $case['client_id'] = $case['contact_id'] = $dao->retrieveContactIdsByCaseId($caseId); //handle multi-value case type $sep = CRM_Core_DAO::VALUE_SEPARATOR; $case['case_type_id'] = trim(str_replace($sep, ',', $case['case_type_id']), ','); if (!empty($return['contacts'])) { //get case contacts $contacts = CRM_Case_BAO_Case::getcontactNames($caseId); $relations = CRM_Case_BAO_Case::getRelatedContacts($caseId); $case['contacts'] = array_merge($contacts, $relations); } if (!empty($return['activities'])) { //get case activities $case['activities'] = array(); $query = "SELECT activity_id FROM civicrm_case_activity WHERE case_id = {$caseId}"; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $case['activities'][] = $dao->activity_id; } } return $case; } }
/** * Internal function to retrieve a case. * * @param int $caseId * * @param array $options * * @param bool $checkPermission * * @return array * case object */ function _civicrm_api3_case_read($caseId, $options, $checkPermission) { $return = CRM_Utils_Array::value('return', $options, array()); $dao = new CRM_Case_BAO_Case(); $dao->id = $caseId; if ($dao->find(TRUE)) { $case = array(); _civicrm_api3_object_to_array($dao, $case); _civicrm_api3_custom_data_get($case, $checkPermission, 'Case', $caseId); // Legacy support for client_id - TODO: in apiv4 remove 'client_id' $case['client_id'] = $case['contact_id'] = $dao->retrieveContactIdsByCaseId($caseId); if (!empty($return['contacts'])) { //get case contacts $contacts = CRM_Case_BAO_Case::getcontactNames($caseId); $relations = CRM_Case_BAO_Case::getRelatedContacts($caseId); $case['contacts'] = array_merge($contacts, $relations); } if (!empty($return['activities'])) { //get case activities $case['activities'] = array(); $query = "SELECT activity_id FROM civicrm_case_activity WHERE case_id = {$caseId}"; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $case['activities'][] = $dao->activity_id; } } return $case; } }
/** * Augment a case with extra data. * * @param array $case * @param array $options */ function _civicrm_api3_case_read(&$case, $options) { if (empty($options['return']) || !empty($options['return']['contact_id'])) { // Legacy support for client_id - TODO: in apiv4 remove 'client_id' $case['client_id'] = $case['contact_id'] = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($case['id']); } if (!empty($options['return']['contacts'])) { //get case contacts $contacts = CRM_Case_BAO_Case::getcontactNames($case['id']); $relations = CRM_Case_BAO_Case::getRelatedContacts($case['id']); $case['contacts'] = array_merge($contacts, $relations); } if (!empty($options['return']['activities'])) { //get case activities $case['activities'] = array(); $query = "SELECT activity_id FROM civicrm_case_activity WHERE case_id = %1"; $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($case['id'], 'Integer'))); while ($dao->fetch()) { $case['activities'][] = $dao->activity_id; } } }
function setDefaultValues() { $defaults = array(); $contactNames = array(); require_once 'CRM/Case/BAO/Case.php'; if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Case_BAO_Case::retrieve($params, $defaults, $ids); $defaults['case_contact'] = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($this->_id, $this->_contactID); $contactNames = CRM_Case_BAO_Case::getcontactNames($this->_id); foreach ($contactNames as $key => $name) { $defaults['contact_names'] .= $defaults['contact_names'] ? ",\"{$name}\"" : "\"{$name}\""; } } $this->assign('contactNames', CRM_Utils_Array::value('contact_names', $defaults)); $defaults['case_type_id'] = explode(CRM_Case_BAO_Case::VALUE_SEPERATOR, CRM_Utils_Array::value('case_type_id', $defaults)); $config =& CRM_Core_Config::singleton(); if ($config->civiHRD) { $defaults['casetag2_id'] = explode(CRM_Case_BAO_Case::VALUE_SEPERATOR, CRM_Utils_Array::value('casetag2_id', $defaults)); $defaults['casetag3_id'] = explode(CRM_Case_BAO_Case::VALUE_SEPERATOR, CRM_Utils_Array::value('casetag3_id', $defaults)); } if ($this->_action & CRM_Core_Action::ADD || $this->_context == 'search') { $defaults['start_date'] = array(); CRM_Utils_Date::getAllDefaultValues($defaults['start_date']); } //set the assigneed contact count to template if (!empty($defaults['case_contact'])) { $this->assign('caseContactCount', count($defaults['case_contact'])); } return $defaults; }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); //adding case manager.CRM-4510. $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', true); // remove Open Case activity type since we're inside an existing case $openCaseID = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name'); unset($aTypes[$openCaseID]); asort($aTypes); $this->add('select', 'activity_type_id', ts('New Activity'), array('' => ts('- select activity type -')) + $aTypes); $this->add('select', 'report_id', ts('Run QA Audit / Redact'), array('' => ts('- select activity set -')) + $reports); $this->add('select', 'timeline_id', ts('Add Timeline'), array('' => ts('- select activity set -')) + $reports); $this->addElement('submit', $this->getButtonName('next'), ts('Go'), array('class' => 'form-submit-inline', 'onclick' => "return checkSelection( this );")); $activityStatus = CRM_Core_PseudoConstant::activityStatus(); $this->add('select', 'status_id', ts('Status'), array("" => ts(' - any status - ')) + $activityStatus); // activity dates $this->addDate('activity_date_low', ts('Activity Dates - From'), false, array('formatType' => 'searchDate')); $this->addDate('activity_date_high', ts('To'), false, array('formatType' => 'searchDate')); require_once "CRM/Core/Permission.php"; if (CRM_Core_Permission::check('administer CiviCRM')) { $this->add('checkbox', 'activity_deleted', ts('Deleted Activities')); } //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //build reporter select $reporters = array("" => ts(' - any reporter - ')); foreach ($caseRelationships as $key => &$value) { $reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )"; if ($managerRoleId == $value['relation_type']) { $value['relation'] = $caseRoles[$managerRoleId]; } //calculate roles that don't have relationships if (CRM_Utils_Array::value($value['relation_type'], $caseRoles)) { unset($caseRoles[$value['relation_type']]); } } // activity type filter for case activity search, need to add Email Sent activity type $emailSentID = CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name'); $aTypesFilter = array($emailSentID => 'Email') + $aTypes; asort($aTypesFilter); $this->add('select', 'activity_type_filter_id', ts('Activity Type'), array('' => ts('- select activity type -')) + $aTypesFilter); $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getcontactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); $this->add('select', 'reporter_id', ts('Reporter/Role'), $reporters); // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, null, null, false); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. $clientRelationships = array(); foreach ($relClient as $r) { if (!array_key_exists($r['id'], $caseRelationships)) { $clientRelationships[] = $r; } } $this->assign('clientRelationships', $clientRelationships); // Now global contact list that appears on all cases. $globalGroupInfo = array(); $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalRelationships', $relGlobal); $this->assign('globalGroupInfo', $globalGroupInfo); // List of relationship types require_once 'CRM/Contact/BAO/Relationship.php'; $baoRel =& new CRM_Contact_BAO_Relationship(); $relType = $baoRel->getRelationType('Individual'); $roleTypes = array(); foreach ($relType as $k => $v) { $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; } $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => true))); }
/** * Get details of a particular case, or search for cases, depending on params * * Please provide one (and only one) of the four get/search parameters: * * @param array( 'case_id' => if set, will get all available info about a case, including contacts and activities * * // if no case_id provided, this function will use one of the following search parameters: * 'client_id' => finds all cases with a specific client * 'activity_id' => returns the case containing a specific activity * 'contact_id' => finds all cases associated with a contact (in any role, not just client) * * {@getfields case_get} * * @return (get mode, case_id provided): Array with case details, case roles, case activity ids, (search mode, case_id not provided): Array of cases found * @access public * @todo Eileen McNaughton 13 Oct 2011 No unit test * @todo Erik Hommel 16 dec 2010 check if all DB fields are returned */ function civicrm_api3_case_get($params) { // Get mode if (!($caseId = CRM_Utils_Array::value('id', $params))) { $caseId = CRM_Utils_Array::value('case_id', $params); } if ($caseId) { // Validate param if (!is_numeric($caseId)) { return civicrm_api3_create_error('Invalid parameter: case_id. Must provide a numeric value.'); } $case = _civicrm_api3_case_read($caseId); if ($case) { //get case contacts $contacts = CRM_Case_BAO_Case::getcontactNames($caseId); $relations = CRM_Case_BAO_Case::getRelatedContacts($caseId); $case['contacts'] = array_merge($contacts, $relations); //get case activities $query = "SELECT activity_id FROM civicrm_case_activity WHERE case_id = {$caseId}"; $dao = CRM_Core_DAO::executeQuery($query); $case['activities'] = array(); while ($dao->fetch()) { $case['activities'][] = $dao->activity_id; } $cases = array($caseId => $case); return civicrm_api3_create_success($cases); } else { return civicrm_api3_create_success(array()); } } //search by client if ($client = CRM_Utils_Array::value('client_id', $params)) { $ids = array(); foreach ((array) $client as $cid) { if (is_numeric($cid)) { $ids = array_merge($ids, CRM_Case_BAO_Case::retrieveCaseIdsByContactId($cid, TRUE)); } } if (empty($ids)) { return civicrm_api3_create_success(array()); } $cases = array(); foreach ($ids as $id) { $cases[$id] = _civicrm_api3_case_read($id); } return civicrm_api3_create_success($cases); } //search by activity if ($act = CRM_Utils_Array::value('activity_id', $params)) { if (!is_numeric($act)) { return civicrm_api3_create_error('Invalid parameter: activity_id. Must provide a numeric value.'); } $caseId = CRM_Case_BAO_Case::getCaseIdByActivityId($act); if (!$caseId) { return civicrm_api3_create_success(array()); } $case = array($caseId => _civicrm_api3_case_read($caseId)); return civicrm_api3_create_success($case); } //search by contacts if ($contact = CRM_Utils_Array::value('contact_id', $params)) { if (!is_numeric($contact)) { return civicrm_api3_create_error('Invalid parameter: contact_id. Must provide a numeric value.'); } $sql = "\nSELECT DISTINCT case_id\n FROM civicrm_relationship\n WHERE (contact_id_a = {$contact}\n OR contact_id_b = {$contact})\n AND case_id IS NOT NULL"; $dao =& CRM_Core_DAO::executeQuery($sql); $cases = array(); while ($dao->fetch()) { $cases[$dao->case_id] = _civicrm_api3_case_read($dao->case_id); } return civicrm_api3_create_success($cases); } return civicrm_api3_create_error('Missing required parameter. Must provide case_id, client_id, activity_id, or contact_id.'); }
function printCaseReport() { $caseID = CRM_Utils_Request::retrieve('caseID', 'Positive', CRM_Core_DAO::$_nullObject); $clientID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject); $activitySetName = CRM_Utils_Request::retrieve('asn', 'String', CRM_Core_DAO::$_nullObject); $isRedact = CRM_Utils_Request::retrieve('redact', 'Boolean', CRM_Core_DAO::$_nullObject); $includeActivities = CRM_Utils_Request::retrieve('all', 'Positive', CRM_Core_DAO::$_nullObject); $params = $otherRelationships = $globalGroupInfo = array(); $report = new CRM_Case_XMLProcessor_Report($isRedact); if ($includeActivities) { $params['include_activities'] = 1; } if ($isRedact) { $params['is_redact'] = 1; $report->_redactionStringRules = array(); } $template = CRM_Core_Smarty::singleton(); //get case related relationships (Case Role) require_once 'CRM/Case/BAO/Case.php'; $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($clientID, $caseID); $caseType = CRM_Case_PseudoConstant::caseTypeName($caseID); require_once 'CRM/Case/XMLProcessor/Process.php'; $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($caseType['name'], 'CaseRoles'); foreach ($caseRelationships as $key => &$value) { if (CRM_Utils_Array::value($value['relation_type'], $caseRoles)) { unset($caseRoles[$value['relation_type']]); } if ($isRedact) { if (!array_key_exists($value['name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['name'] => 'name_' . rand(10000, 100000))); } $value['name'] = self::redact($value['name'], true, $report->_redactionStringRules); if (CRM_Utils_Array::value('email', $value) && !array_key_exists($value['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['email'] => 'email_' . rand(10000, 100000))); } $value['email'] = self::redact($value['email'], true, $report->_redactionStringRules); if (CRM_Utils_Array::value('phone', $value) && !array_key_exists($value['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['phone'] => 'phone_' . rand(10000, 100000))); } $value['phone'] = self::redact($value['phone'], true, $report->_redactionStringRules); } } $caseRoles['client'] = CRM_Case_BAO_Case::getcontactNames($caseID); if ($isRedact) { if (!array_key_exists($caseRoles['client']['sort_name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['sort_name'] => 'name_' . rand(10000, 100000))); } if (!array_key_exists($caseRoles['client']['display_name'], $report->_redactionStringRules)) { $report->_redactionStringRules[$caseRoles['client']['display_name']] = $report->_redactionStringRules[$caseRoles['client']['sort_name']]; } $caseRoles['client']['sort_name'] = self::redact($caseRoles['client']['sort_name'], true, $report->_redactionStringRules); if (CRM_Utils_Array::value('email', $caseRoles['client']) && !array_key_exists($caseRoles['client']['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['email'] => 'email_' . rand(10000, 100000))); } $caseRoles['client']['email'] = self::redact($caseRoles['client']['email'], true, $report->_redactionStringRules); if (CRM_Utils_Array::value('phone', $caseRoles['client']) && !array_key_exists($caseRoles['client']['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['phone'] => 'phone_' . rand(10000, 100000))); } $caseRoles['client']['phone'] = self::redact($caseRoles['client']['phone'], true, $report->_redactionStringRules); } // Retrieve ALL client relationships require_once 'CRM/Contact/BAO/Relationship.php'; $relClient = CRM_Contact_BAO_Relationship::getRelationship($clientID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, null, null, false); foreach ($relClient as $r) { if ($isRedact) { if (!array_key_exists($r['name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['name'] => 'name_' . rand(10000, 100000))); } if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) { $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['name']]; } $r['name'] = self::redact($r['name'], true, $report->_redactionStringRules); if (CRM_Utils_Array::value('phone', $r) && !array_key_exists($r['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['phone'] => 'phone_' . rand(10000, 100000))); } $r['phone'] = self::redact($r['phone'], true, $report->_redactionStringRules); if (CRM_Utils_Array::value('email', $r) && !array_key_exists($r['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['email'] => 'email_' . rand(10000, 100000))); } $r['email'] = self::redact($r['email'], true, $report->_redactionStringRules); } if (!array_key_exists($r['id'], $caseRelationships)) { $otherRelationships[] = $r; } } // Now global contact list that appears on all cases. $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); foreach ($relGlobal as &$r) { if ($isRedact) { if (!array_key_exists($r['sort_name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['sort_name'] => 'name_' . rand(10000, 100000))); } if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) { $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['sort_name']]; } $r['sort_name'] = self::redact($r['sort_name'], true, $report->_redactionStringRules); if (CRM_Utils_Array::value('phone', $r) && !array_key_exists($r['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['phone'] => 'phone_' . rand(10000, 100000))); } $r['phone'] = self::redact($r['phone'], true, $report->_redactionStringRules); if (CRM_Utils_Array::value('email', $r) && !array_key_exists($r['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['email'] => 'email_' . rand(10000, 100000))); } $r['email'] = self::redact($r['email'], true, $report->_redactionStringRules); } } $template->assign('caseRelationships', $caseRelationships); $template->assign('caseRoles', $caseRoles); $template->assign('otherRelationships', $otherRelationships); $template->assign('globalRelationships', $relGlobal); $template->assign('globalGroupInfo', $globalGroupInfo); $contents = self::getCaseReport($clientID, $caseID, $activitySetName, $params, $report); require_once 'CRM/Case/Audit/Audit.php'; $printReport = Audit::run($contents, $clientID, $caseID, true); echo $printReport; exit; }
public function buildQuickForm() { // modify core Activity fields $this->_fields['source_contact_id']['label'] = ts('Reported By'); $this->_fields['status_id']['attributes'] = array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(); if ($this->_caseType) { $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', true); // remove Open Case activity type since we're inside an existing case $openCaseID = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name'); unset($aTypes[$openCaseID]); asort($aTypes); $this->_fields['followup_activity_type_id']['attributes'] = array('' => '- select activity type -') + $aTypes; } $result = parent::buildQuickForm(); if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH | CRM_Core_Action::RENEW)) { return; } if ($this->_cdType || $this->_addAssigneeContact || $this->_addTargetContact) { return $result; } $this->assign('urlPath', 'civicrm/case/activity'); $this->add('select', 'medium_id', ts('Medium'), CRM_Core_OptionGroup::values('encounter_medium'), true); $this->_relatedContacts = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($this->_caseId); //add case client in send a copy selector.CRM-4438. $this->_relatedContacts[] = CRM_Case_BAO_Case::getcontactNames($this->_caseId); if (!empty($this->_relatedContacts)) { $checkBoxes = array(); foreach ($this->_relatedContacts as $id => $row) { $checkBoxes[$id] = $this->addElement('checkbox', $id, null, ''); } $this->addGroup($checkBoxes, 'contact_check'); $this->addElement('checkbox', 'toggleSelect', null, null, array('onclick' => "return toggleCheckboxVals('contact_check',this);")); $this->assign('searchRows', $this->_relatedContacts); } $this->addFormRule(array('CRM_Case_Form_Activity', 'formRule'), $this); }