public static function getCaseRoles() { $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles'); $hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); $managerRoleId = $xmlProcessor->getCaseManagerRoleId($caseTypeName); foreach ($caseRelationships as $key => $value) { // This role has been filled unset($caseRoles[$value['relation_type']]); // mark original case relationships record to use on setting edit links below $caseRelationships[$key]['source'] = 'caseRel'; } $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID); // move/transform caseRoles array data to caseRelationships // for sorting and display // CRM-14466 added cid to the non-client array to avoid php notice foreach ($caseRoles as $id => $value) { if ($id != "client") { $rel = array(); $rel['relation'] = $value; $rel['relation_type'] = $id; $rel['name'] = '(not assigned)'; $rel['phone'] = ''; $rel['email'] = ''; $rel['source'] = 'caseRoles'; $caseRelationships[] = $rel; } else { foreach ($value as $clientRole) { $relClient = array(); $relClient['relation'] = 'Client'; $relClient['name'] = $clientRole['sort_name']; $relClient['phone'] = $clientRole['phone']; $relClient['email'] = $clientRole['email']; $relClient['cid'] = $clientRole['contact_id']; $relClient['source'] = 'contact'; $caseRelationships[] = $relClient; } } } // sort clientRelationships array using jquery call params foreach ($caseRelationships as $key => $row) { $sortArray[$key] = $row[$params['_raw_values']['sort'][0]]; } $sort_type = "SORT_" . strtoupper($params['_raw_values']['order'][0]); array_multisort($sortArray, constant($sort_type), $caseRelationships); $relationships = array(); // set user name, email and edit columns links foreach ($caseRelationships as $key => &$row) { $typeLabel = $row['relation']; // Add "<br />(Case Manager)" to label if ($row['relation_type'] == $managerRoleId) { $row['relation'] .= '<br />' . '(' . ts('Case Manager') . ')'; } // view user links if (!empty($row['cid'])) { $row['name'] = '<a class="view-contact" title="' . ts('View Contact') . '" href=' . CRM_Utils_System::url('civicrm/contact/view', 'action=view&reset=1&cid=' . $row['cid']) . '>' . $row['name'] . '</a>'; } // email column links/icon if ($row['email']) { $row['email'] = '<a class="crm-hover-button crm-popup" href="' . CRM_Utils_System::url('civicrm/activity/email/add', 'reset=1&action=add&atype=3&cid=' . $row['cid']) . '&caseid=' . $caseID . '" title="' . ts('Send an Email') . '"><i class="crm-i fa-envelope"></i></a>'; } // edit links $row['actions'] = ''; if ($hasAccessToAllCases) { $contactType = empty($row['relation_type']) ? '' : (string) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $row['relation_type'], 'contact_type_b'); $contactType = $contactType == 'Contact' ? '' : $contactType; switch ($row['source']) { case 'caseRel': $row['actions'] = '<a href="#editCaseRoleDialog" title="' . ts('Reassign %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '_' . $row['relationship_direction'] . '" data-cid="' . $row['cid'] . '" data-rel_id="' . $row['rel_id'] . '"data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' . '<i class="crm-i fa-pencil"></i>' . '</a>' . '<a href="#deleteCaseRoleDialog" title="' . ts('Remove %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '_' . $row['relationship_direction'] . '" data-cid="' . $row['cid'] . '" data-key="' . CRM_Core_Key::get('civicrm/ajax/delcaserole') . '">' . '<span class="icon delete-icon"></span>' . '</a>'; break; case 'caseRoles': $row['actions'] = '<a href="#editCaseRoleDialog" title="' . ts('Assign %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '_b_a" data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' . '<i class="crm-i fa-pencil"></i>' . '</a>'; break; } } unset($row['cid']); unset($row['relation_type']); unset($row['rel_id']); unset($row['client_id']); unset($row['source']); array_push($relationships, $row); } $params['total'] = count($relationships); $caseRelationshipsDT = array(); $caseRelationshipsDT['data'] = $relationships; $caseRelationshipsDT['recordsTotal'] = $params['total']; $caseRelationshipsDT['recordsFiltered'] = $params['total']; CRM_Utils_JSON::output($caseRelationshipsDT); }
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) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($clientID, $caseID); $caseType = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles'); foreach ($caseRelationships as $key => &$value) { if (!empty($caseRoles[$value['relation_type']])) { 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 (!empty($value['email']) && !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 (!empty($value['phone']) && !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 (!empty($caseRoles['client']['email']) && !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 (!empty($caseRoles['client']['phone']) && !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 $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 (!empty($r['phone']) && !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 (!empty($r['email']) && !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 (!empty($r['phone']) && !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 (!empty($r['email']) && !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); $printReport = CRM_Case_Audit_Audit::run($contents, $clientID, $caseID, TRUE); echo $printReport; CRM_Utils_System::civiExit(); }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { //this call is for show related cases. if ($this->_showRelatedCases) { return; } CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js')->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js'); $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); $allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); $emailActivityType = array_search('Email', $allActTypes); $pdfActivityType = array_search('Print PDF Letter', $allActTypes); // remove Open Case activity type since we're inside an existing case if ($openActTypeId = array_search('Open Case', $allActTypes)) { unset($aTypes[$openActTypeId]); } //check for link cases. $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases(NULL, array($this->_caseID)); if (empty($unclosedCases) && ($linkActTypeId = array_search('Link Cases', $allActTypes))) { unset($aTypes[$linkActTypeId]); } if (!$xmlProcessor->getNaturalActivityTypeSort()) { asort($aTypes); } $activityLinks = array('' => ts('Add Activity')); foreach ($aTypes as $type => $label) { if ($type == $emailActivityType) { $url = CRM_Utils_System::url('civicrm/activity/email/add', "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { if ($type == $pdfActivityType) { $url = CRM_Utils_System::url('civicrm/activity/pdf/add', "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { $url = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } } $activityLinks[$url] = $label; } $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-plus twenty')); if ($this->_hasAccessToAllCases) { $this->add('select', 'report_id', '', array('' => ts('Activity Audit')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-clipboard')); $this->add('select', 'timeline_id', '', array('' => ts('Add Timeline')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu action-icon-play')); } $this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement')); if ($this->_mergeCases) { $allCases = CRM_Case_BAO_Case::getContactCases($this->_contactID); $otherCases = array(); foreach ($allCases as $caseId => $details) { //filter current and own cases. if ($caseId == $this->_caseID || !$this->_hasAccessToAllCases && !array_key_exists($caseId, $this->_userCases)) { continue; } $otherCases[$caseId] = 'Case ID: ' . $caseId . ' Type: ' . $details['case_type'] . ' Start: ' . $details['case_start_date']; } if (empty($otherCases)) { $this->_mergeCases = FALSE; $this->assign('mergeCases', $this->_mergeCases); } else { $this->add('select', 'merge_case_id', ts('Select Case for Merge'), array('' => ts('- select case -')) + $otherCases, FALSE, array('class' => 'crm-select2 huge')); $this->addElement('submit', $this->getButtonName('next', 'merge_case'), ts('Merge'), array('class' => 'crm-form-submit-inline hiddenElement')); } } //call activity form self::activityForm($this); //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //save special label because we unset it in the loop $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId]; foreach ($caseRelationships as $key => &$value) { if (!empty($managerRoleId)) { if ($managerRoleId == $value['relation_type']) { $value['relation'] = $managerLabel; } } //calculate roles that don't have relationships if (!empty($caseRoles[$value['relation_type']])) { unset($caseRoles[$value['relation_type']]); } } $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); // 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(); CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalGroupInfo', $globalGroupInfo); // List of relationship types $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, FALSE, array('class' => 'crm-select2 twenty')); $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { $this->assign('hookCaseSummary', $hookCaseSummary); } $allTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if (!empty($allTags)) { $this->add('select', 'case_tag', ts('Tags'), $allTags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2')); $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); $this->setDefaults(array('case_tag' => $tags)); foreach ($tags as $tid) { if (isset($allTags[$tid])) { $tags[$tid] = $allTags[$tid]; } else { unset($tags[$tid]); } } $this->assign('tags', implode(', ', array_filter($tags))); $this->assign('showTags', TRUE); } else { $this->assign('showTags', FALSE); } // build tagset widget // see if we have any tagsets which can be assigned to cases $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); if ($parentNames) { $this->assign('showTagsets', TRUE); } else { $this->assign('showTagsets', FALSE); } CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => TRUE))); }
public function buildQuickForm() { $this->_fields['source_contact_id']['label'] = ts('Reported By'); unset($this->_fields['status_id']['attributes']['required']); if ($this->_caseType) { $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $aTypes = array(); foreach ($this->_caseType as $key => $val) { $activityTypes = $xmlProcessor->get($val, 'ActivityTypes', TRUE); $aTypes = $aTypes + $activityTypes; } // 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; } $this->assign('urlPath', 'civicrm/case/activity'); $encounterMediums = CRM_Case_PseudoConstant::encounterMedium(); // Fixme: what's the justification for this? It seems like it is just re-adding an option in case it is the default and disabled. // Is that really a big problem? if ($this->_activityTypeFile == 'OpenCase') { $this->_encounterMedium = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'medium_id'); if (!array_key_exists($this->_encounterMedium, $encounterMediums)) { $encounterMediums[$this->_encounterMedium] = CRM_Core_OptionGroup::getLabel('encounter_medium', $this->_encounterMedium, FALSE); } } $this->add('select', 'medium_id', ts('Medium'), $encounterMediums, TRUE); $i = 0; foreach ($this->_caseId as $key => $val) { $this->_relatedContacts[] = $rgc = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($val); $contName = CRM_Case_BAO_Case::getContactNames($val); foreach ($contName as $nkey => $nval) { array_push($this->_relatedContacts[$i][0], $this->_relatedContacts[$i][0]['managerOf'] = $nval['display_name']); } $i++; } //add case client in send a copy selector.CRM-4438. foreach ($this->_caseId as $key => $val) { $relatedContacts[] = $relCon = CRM_Case_BAO_Case::getContactNames($val); } if (!empty($relatedContacts)) { foreach ($relatedContacts as $relatedContact) { $this->_relatedContacts[] = $relatedContact; } } if (!empty($this->_relatedContacts)) { $checkBoxes = array(); foreach ($this->_relatedContacts as $id => $row) { $checkBoxes[$id] = $this->addElement('checkbox', $id, NULL, NULL, array('class' => 'select-row')); } $this->addGroup($checkBoxes, 'contact_check'); $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows')); $this->assign('searchRows', $this->_relatedContacts); } $this->_relatedContacts = $rgc + $relCon; $this->addFormRule(array('CRM_Case_Form_Activity', 'formRule'), $this); }
public function buildQuickForm() { // modify core Activity fields $this->add('text', 'target_contact_id', ts('target')); //FIXME : ideally hidden element should work. $this->addElement('advcheckbox', "hidden_target_contact"); $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'); $encounterMediums = CRM_Case_PseudoConstant::encounterMedium(); if ($this->_activityTypeFile == 'OpenCase') { $this->_encounterMedium = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'medium_id'); if (!array_key_exists($this->_encounterMedium, $encounterMediums)) { $encounterMediums[$this->_encounterMedium] = CRM_Core_OptionGroup::getLabel('encounter_medium', $this->_encounterMedium, FALSE); } } $this->add('select', 'medium_id', ts('Medium'), $encounterMediums, TRUE); $this->_relatedContacts = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($this->_caseId); //add case client in send a copy selector.CRM-4438. $relatedContacts = CRM_Case_BAO_Case::getContactNames($this->_caseId); if (!empty($relatedContacts)) { foreach ($relatedContacts as $relatedContact) { $this->_relatedContacts[] = $relatedContact; } } 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); }
public static function getCaseRoles() { $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); $sortMapper = array(0 => 'relation', 1 => 'name', 2 => 'phone', 3 => 'email', 4 => 'actions'); $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation'; $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; $params = $_POST; if ($sort && $sortOrder) { $sortSQL = $sort . ' ' . $sortOrder; } $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles'); $hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); $managerRoleId = $xmlProcessor->getCaseManagerRoleId($caseTypeName); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } foreach ($caseRelationships as $key => $value) { //calculate roles that don't have relationships if (!empty($caseRoles[$value['relation_type']])) { //keep naming from careRoles array $caseRelationships[$key]['relation'] = $caseRoles[$value['relation_type']]; unset($caseRoles[$value['relation_type']]); } // mark orginal case relationships record to use on setting edit links below $caseRelationships[$key]['source'] = 'caseRel'; } $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID); // move/transform caseRoles array data to caseRelationships // for sorting and display // CRM-14466 added cid to the non-client array to avoid php notice foreach ($caseRoles as $id => $value) { if ($id != "client") { $rel = array(); $rel['relation'] = $value; $rel['relation_type'] = $id; $rel['name'] = '(not assigned)'; $rel['phone'] = ''; $rel['email'] = ''; $rel['source'] = 'caseRoles'; $caseRelationships[] = $rel; } else { foreach ($value as $clientRole) { $relClient = array(); $relClient['relation'] = 'Client'; $relClient['name'] = $clientRole['sort_name']; $relClient['phone'] = $clientRole['phone']; $relClient['email'] = $clientRole['email']; $relClient['cid'] = $clientRole['contact_id']; $relClient['source'] = 'contact'; $caseRelationships[] = $relClient; } } } // sort clientRelationships array using jquery call params foreach ($caseRelationships as $key => $row) { $sortArray[$key] = $row[$sort]; } $sort_type = "SORT_" . strtoupper($sortOrder); array_multisort($sortArray, constant($sort_type), $caseRelationships); //limit rows display $allCaseRelationships = $caseRelationships; $caseRelationships = array_slice($allCaseRelationships, $offset, $rowCount, TRUE); // set user name, email and edit columns links // idx will count number of current row / needed by edit links $idx = 1; foreach ($caseRelationships as &$row) { // Get rid of the "<br />(Case Manager)" from label list($typeLabel) = explode('<', $row['relation']); // view user links if (!empty($row['cid'])) { $row['name'] = '<a class="view-contact" title="' . ts('View Contact') . '" href=' . CRM_Utils_System::url('civicrm/contact/view', 'action=view&reset=1&cid=' . $row['cid']) . '>' . $row['name'] . '</a>'; } // email column links/icon if ($row['email']) { $row['email'] = '<a class="crm-hover-button crm-popup" href="' . CRM_Utils_System::url('civicrm/activity/email/add', 'reset=1&action=add&atype=3&cid=' . $row['cid']) . '&caseid=' . $caseID . '" title="' . ts('Send an Email') . '"><span class="icon ui-icon-mail-closed"></span></a>'; } // edit links $row['actions'] = ''; if ($hasAccessToAllCases) { $contactType = empty($row['relation_type']) ? '' : (string) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $row['relation_type'], 'contact_type_b'); $contactType = $contactType == 'Contact' ? '' : $contactType; switch ($row['source']) { case 'caseRel': $row['actions'] = '<a href="#editCaseRoleDialog" title="' . ts('Reassign %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '" data-rel_id="' . $row['rel_id'] . '"data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' . '<span class="icon ui-icon-pencil"></span>' . '</a>' . '<a href="#deleteCaseRoleDialog" title="' . ts('Remove %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '" data-key="' . CRM_Core_Key::get('civicrm/ajax/delcaserole') . '">' . '<span class="icon delete-icon"></span>' . '</a>'; break; case 'caseRoles': $row['actions'] = '<a href="#editCaseRoleDialog" title="' . ts('Assign %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '" data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' . '<span class="icon ui-icon-pencil"></span>' . '</a>'; break; } } $idx++; } $iFilteredTotal = $iTotal = $params['total'] = count($allCaseRelationships); $selectorElements = array('relation', 'name', 'phone', 'email', 'actions'); header('Content-Type: application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($caseRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); }
static function getCaseRoles() { $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); $sortMapper = array(0 => 'relation', 1 => 'name', 2 => 'phone', 3 => 'email', 4 => 'actions'); $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation'; $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; $params = $_POST; if ($sort && $sortOrder) { $sortSQL = $sort . ' ' . $sortOrder; } $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles'); $hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); $managerRoleId = $xmlProcessor->getCaseManagerRoleId($caseTypeName); if (!empty($managerRoleId)) { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; } foreach ($caseRelationships as $key => $value) { //calculate roles that don't have relationships if (CRM_Utils_Array::value($value['relation_type'], $caseRoles)) { //keep naming from careRoles array $caseRelationships[$key]['relation'] = $caseRoles[$value['relation_type']]; unset($caseRoles[$value['relation_type']]); } // mark orginal case relationships record to use on setting edit links below $caseRelationships[$key]['source'] = 'caseRel'; } $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID); // move/transform caseRoles array data to caseRelationships // for sorting and display foreach ($caseRoles as $id => $value) { if ($id != "client") { $rel = array(); $rel['relation'] = $value; $rel['relation_type'] = $id; $rel['name'] = '(not assigned)'; $rel['phone'] = ''; $rel['email'] = ''; $rel['source'] = 'caseRoles'; $caseRelationships[] = $rel; } else { foreach ($value as $clientRole) { $relClient = array(); $relClient['relation'] = 'Client'; $relClient['name'] = $clientRole['sort_name']; $relClient['phone'] = $clientRole['phone']; $relClient['email'] = $clientRole['email']; $relClient['cid'] = $clientRole['contact_id']; $relClient['source'] = 'contact'; $caseRelationships[] = $relClient; } } } // sort clientRelationships array using jquery call params foreach ($caseRelationships as $key => $row) { $sortArray[$key] = $row[$sort]; } $sort_type = "SORT_" . strtoupper($sortOrder); array_multisort($sortArray, constant($sort_type), $caseRelationships); //limit rows display $allCaseRelationships = $caseRelationships; $caseRelationships = array_slice($allCaseRelationships, $offset, $rowCount, TRUE); // set user name, email and edit columns links // idx will count number of current row / needed by edit links $idx = 1; foreach ($caseRelationships as $key => $row) { // view user links if ($caseRelationships[$key]['cid']) { $caseRelationships[$key]['name'] = '<a href=' . CRM_Utils_System::url('civicrm/contact/view', 'action=view&reset=1&cid=' . $caseRelationships[$key]['cid']) . '>' . $caseRelationships[$key]['name'] . '</a>'; } // email column links/icon if ($caseRelationships[$key]['email']) { $caseRelationships[$key]['email'] = '<a href="' . CRM_Utils_System::url('civicrm/contact/view/activity', 'action=reset=1&action=add&atype=3&cid=' . $caseRelationships[$key]['cid']) . '&caseid=' . $caseID . '" title="compose and send an email"><div class="icon email-icon" title="compose and send an email"></div> </a>'; } // edit links if ($hasAccessToAllCases) { switch ($caseRelationships[$key]['source']) { case 'caseRel': $caseRelationships[$key]['actions'] = '<a href="#" title="edit case role" onclick="createRelationship( ' . $caseRelationships[$key]['relation_type'] . ', ' . $caseRelationships[$key]['cid'] . ', ' . $caseRelationships[$key]['rel_id'] . ', ' . $idx . ', \'' . $caseRelationships[$key]['relation'] . '\' );return false;"><div class="icon edit-icon" ></div></a> <a href="#" class="case-role-delete" case_id="' . $caseID . '" rel_type="' . $caseRelationships[$key]['relation_type'] . '"><div class="icon delete-icon" title="remove contact from case role"></div></a>'; break; case 'caseRoles': $caseRelationships[$key]['actions'] = '<a href="#" title="edit case role" onclick="createRelationship(' . $caseRelationships[$key]['relation_type'] . ', null, null, ' . $idx . ', \'' . $caseRelationships[$key]['relation'] . '\');return false;"><div class="icon edit-icon"></div></a>'; break; } } else { $caseRelationships[$key]['actions'] = ''; } $idx++; } $iFilteredTotal = $iTotal = $params['total'] = count($allCaseRelationships); $selectorElements = array('relation', 'name', 'phone', 'email', 'actions'); echo CRM_Utils_JSON::encodeDataTableSelector($caseRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { //this call is for show related cases. if ($this->_showRelatedCases) { return; } $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); require_once 'CRM/Core/PseudoConstant.php'; $allActTypes = CRM_Core_PseudoConstant::activityType(true, true, false, 'name'); // remove Open Case activity type since we're inside an existing case if (($openActTypeId = array_search('Open Case', $allActTypes)) && array_key_exists($openActTypeId, $aTypes)) { unset($aTypes[$openActTypeId]); } //check for link cases. $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases(null, array($this->_caseID)); if (empty($unclosedCases) && ($linkActTypeId = array_search('Link Cases', $allActTypes)) && array_key_exists($linkActTypeId, $aTypes)) { unset($aTypes[$linkActTypeId]); } asort($aTypes); $this->add('select', 'activity_type_id', ts('New Activity'), array('' => ts('- select activity type -')) + $aTypes); if ($this->_hasAccessToAllCases) { $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 );")); if ($this->_mergeCases) { $allCases = CRM_Case_BAO_Case::getContactCases($this->_contactID); $otherCases = array(); foreach ($allCases as $caseId => $details) { //filter current and own cases. if ($caseId == $this->_caseID || !$this->_hasAccessToAllCases && !array_key_exists($caseId, $this->_userCases)) { continue; } $otherCases[$caseId] = 'Case ID: ' . $caseId . ' Type: ' . $details['case_type'] . ' Start: ' . $details['case_start_date']; } if (empty($otherCases)) { $this->_mergeCases = false; $this->assign('mergeCases', $this->_mergeCases); } else { $this->add('select', 'merge_case_id', ts('Select Case for Merge'), array('' => ts('- select case -')) + $otherCases); $this->addElement('submit', $this->getButtonName('next', 'merge_case'), ts('Merge'), array('class' => 'form-submit-inline', 'onclick' => "return checkSelection( this );")); } } $this->add('text', 'change_client_id', ts('Assign to another Client')); $this->add('hidden', 'contact_id', '', array('id' => 'contact_id')); $this->addElement('submit', $this->getButtonName('next', 'edit_client'), ts('Reassign Case'), 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']]); } } // take all case activity types for search filter, CRM-7187 $aTypesFilter = array(); $allCaseActTypes = CRM_Case_PseudoConstant::activityType(); foreach ($allCaseActTypes as $typeDetails) { if (!in_array($typeDetails['name'], array('Open Case'))) { $aTypesFilter[$typeDetails['id']] = CRM_Utils_Array::value('label', $typeDetails); } } 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); require_once 'CRM/Utils/Hook.php'; $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { $this->assign('hookCaseSummary', $hookCaseSummary); } require_once 'CRM/Core/BAO/EntityTag.php'; require_once 'CRM/Core/BAO/Tag.php'; $allTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if (!empty($allTags)) { $this->add('select', 'case_tag', ts('Tags'), $allTags, false, array('id' => 'tags', 'multiple' => 'multiple', 'title' => ts('- select -'))); $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); $this->setDefaults(array('case_tag' => $tags)); foreach ($tags as $tid) { $tags[$tid] = $allTags[$tid]; } $this->assign('tags', implode(', ', array_filter($tags))); $this->assign('showTags', true); } else { $this->assign('showTags', false); } // build tagset widget require_once 'CRM/Core/Form/Tag.php'; // see if we have any tagsets which can be assigned to cases $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); if ($parentNames) { $this->assign('showTagsets', true); } else { $this->assign('showTagsets', false); } CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, false, true); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => true))); }
/** * Build the form object. */ public function buildQuickForm() { //this call is for show related cases. if ($this->_showRelatedCases) { return; } $allowedRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactID); CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header')->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js', 2, 'html-header')->addVars('relationshipTypes', CRM_Contact_Form_Relationship::getRelationshipTypeMetadata($allowedRelationshipTypes)); $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); $allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); $emailActivityType = array_search('Email', $allActTypes); $pdfActivityType = array_search('Print PDF Letter', $allActTypes); if ($pdfActivityType) { $this->assign('exportDoc', CRM_Utils_System::url('civicrm/activity/pdf/add', "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$pdfActivityType}")); } // remove Open Case activity type since we're inside an existing case if ($openActTypeId = array_search('Open Case', $allActTypes)) { unset($aTypes[$openActTypeId]); } // Only show "link cases" activity if other cases exist. $linkActTypeId = array_search('Link Cases', $allActTypes); if ($linkActTypeId) { $count = civicrm_api3('Case', 'getcount', array('check_permissions' => TRUE, 'id' => array('!=' => $this->_caseID), 'is_deleted' => 0)); if (!$count) { unset($aTypes[$linkActTypeId]); } } if (!$xmlProcessor->getNaturalActivityTypeSort()) { asort($aTypes); } $activityLinks = array('' => ts('Add Activity')); foreach ($aTypes as $type => $label) { if ($type == $emailActivityType) { $url = CRM_Utils_System::url('civicrm/activity/email/add', "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } elseif ($type == $pdfActivityType) { $url = CRM_Utils_System::url('civicrm/activity/pdf/add', "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } else { $url = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype={$type}", FALSE, NULL, FALSE); } $activityLinks[$url] = $label; } $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu fa-calendar-check-o twenty')); if ($this->_hasAccessToAllCases) { $this->add('select', 'report_id', '', array('' => ts('Activity Audit')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu fa-list-alt')); $this->add('select', 'timeline_id', '', array('' => ts('Add Timeline')) + $reports, FALSE, array('class' => 'crm-select2 crm-action-menu fa-list-ol')); } $this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement')); $this->buildMergeCaseForm(); //call activity form self::activityForm($this, $aTypes); //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); //save special label because we unset it in the loop $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId]; foreach ($caseRelationships as $key => &$value) { if (!empty($managerRoleId)) { if ($managerRoleId == $value['relation_type']) { $value['relation'] = $managerLabel; } } //calculate roles that don't have relationships if (!empty($caseRoles[$value['relation_type']])) { unset($caseRoles[$value['relation_type']]); } } $this->assign('caseRelationships', $caseRelationships); //also add client as role. CRM-4438 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); $this->assign('caseRoles', $caseRoles); // 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(); CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); $this->assign('globalGroupInfo', $globalGroupInfo); // List relationship types for adding an arbitrary new role to the case $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $allowedRelationshipTypes, FALSE, array('class' => 'crm-select2 twenty', 'data-select-params' => '{"allowClear": false}')); $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { $this->assign('hookCaseSummary', $hookCaseSummary); } CRM_Core_BAO_Tag::getTags('civicrm_case', $allTags, NULL, ' ', TRUE); if (!empty($allTags)) { $this->add('select', 'case_tag', ts('Tags'), $allTags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2')); $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); $this->setDefaults(array('case_tag' => $tags)); foreach ($tags as $tid) { if (isset($allTags[$tid])) { $tags[$tid] = $allTags[$tid]; } else { unset($tags[$tid]); } } $this->assign('tags', implode(', ', array_filter($tags))); $this->assign('showTags', TRUE); } else { $this->assign('showTags', FALSE); } // build tagset widget // see if we have any tagsets which can be assigned to cases $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); $tagSetTags = array(); if ($parentNames) { $this->assign('showTags', TRUE); $tagSetItems = civicrm_api3('entityTag', 'get', array('entity_id' => $this->_caseID, 'entity_table' => 'civicrm_case', 'tag_id.parent_id.is_tagset' => 1, 'options' => array('limit' => 0), 'return' => array("tag_id.parent_id", "tag_id.parent_id.name", "tag_id.name"))); foreach ($tagSetItems['values'] as $tag) { $tagSetTags += array($tag['tag_id.parent_id'] => array('name' => $tag['tag_id.parent_id.name'], 'items' => array())); $tagSetTags[$tag['tag_id.parent_id']]['items'][] = $tag['tag_id.name']; } } $this->assign('tagSetTags', $tagSetTags); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE); $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'spacing' => ' ', 'isDefault' => TRUE))); }