/** * @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'); $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(); }