/** * @throws \CiviCRM_API3_Exception */ public static function relationship() { $relType = CRM_Utils_Request::retrieve('rel_type', 'String', CRM_Core_DAO::$_nullObject, TRUE); $relContactID = CRM_Utils_Request::retrieve('rel_contact', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); $originalCid = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject); $relationshipID = CRM_Utils_Request::retrieve('rel_id', 'Positive', CRM_Core_DAO::$_nullObject); $caseID = CRM_Utils_Request::retrieve('case_id', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); if (!CRM_Case_BAO_Case::accessCase($caseID)) { CRM_Utils_System::permissionDenied(); } $ret = array('is_error' => 0); list($relTypeId, $b, $a) = explode('_', $relType); if ($relationshipID && $originalCid) { CRM_Case_BAO_Case::endCaseRole($caseID, $a, $originalCid, $relTypeId); } $clientList = CRM_Case_BAO_Case::getCaseClients($caseID); // Loop through multiple case clients foreach ($clientList as $i => $sourceContactID) { $result = civicrm_api3('relationship', 'create', array('case_id' => $caseID, 'relationship_type_id' => $relTypeId, "contact_id_{$a}" => $relContactID, "contact_id_{$b}" => $sourceContactID, 'start_date' => 'now')); // Save activity only for the primary (first) client if ($i == 0 && empty($result['is_error'])) { CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $result['id'], $relContactID); } } CRM_Utils_JSON::output($ret); }
/** * Delete relationships specific to case and relationship type. */ public static function deleteCaseRoles() { $caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Positive'); $relType = CRM_Utils_Type::escape($_POST['rel_type'], 'Positive'); if (!$relType || !CRM_Case_BAO_Case::accessCase($caseId)) { CRM_Utils_System::permissionDenied(); } $sql = "DELETE FROM civicrm_relationship WHERE case_id={$caseId} AND relationship_type_id={$relType}"; CRM_Core_DAO::executeQuery($sql); CRM_Utils_System::civiExit(); }
/** * Delete relationships specific to case and relationship type. */ public static function deleteCaseRoles() { $caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Positive'); $cid = CRM_Utils_Type::escape($_POST['cid'], 'Positive'); $relType = CRM_Utils_Request::retrieve('rel_type', 'String', CRM_Core_DAO::$_nullObject, TRUE); if (!$cid || !CRM_Case_BAO_Case::accessCase($caseId)) { CRM_Utils_System::permissionDenied(); } list($relTypeId, $a, $b) = explode('_', $relType); CRM_Case_BAO_Case::endCaseRole($caseId, $b, $cid, $relTypeId); CRM_Utils_System::civiExit(); }
/** * Set variables up before form is built. */ 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; } $this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); $this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases); $this->assign('contactID', $this->_contactID = (int) $this->get('cid')); $this->assign('caseID', $this->_caseID = (int) $this->get('id')); // Access check. if (!CRM_Case_BAO_Case::accessCase($this->_caseID, FALSE)) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } $fulltext = CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject); if ($fulltext == 'fulltext') { $this->assign('fulltext', $fulltext); } $this->assign('contactType', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type')); $this->assign('userID', CRM_Core_Session::getLoggedInContactID()); //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, FALSE, NULL, NULL, NULL, $this->_caseID); }