diff --git a/CRM/Case/Form/CaseView.php b/CRM/Case/Form/CaseView.php index 75b35d48c8e1..0e34b65bb27c 100644 --- a/CRM/Case/Form/CaseView.php +++ b/CRM/Case/Form/CaseView.php @@ -55,6 +55,12 @@ public function preProcess() { $this->assign('contactID', $this->_contactID = (int) $this->get('cid')); $this->assign('caseID', $this->_caseID = (int) $this->get('id')); + $this->assign('primaryCaseContactID', civicrm_api3('Activity', 'get', [ + 'case_id' => $this->_caseID, + 'activity_type_id' => 'Open Case', + 'return' => ['assignee_contact_id', 'source_contact_id', 'target_contact_id'], + 'sequential' => 1, + ])['values'][0]['target_contact_id'][0]); // Access check. if (!CRM_Case_BAO_Case::accessCase($this->_caseID, FALSE)) { diff --git a/CRM/Case/Form/DeleteClient.php b/CRM/Case/Form/DeleteClient.php new file mode 100644 index 000000000000..b8f6c503539b --- /dev/null +++ b/CRM/Case/Form/DeleteClient.php @@ -0,0 +1,117 @@ +cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); + $this->id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); + $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); + + //get current client name. + $this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($this->cid)); + $this->assign('id', $this->id); + + //set the context. + $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->cid}&selectedChild=case"); + if ($context == 'search') { + $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); + //validate the qfKey + $urlParams = 'force=1'; + if (CRM_Utils_Rule::qfKey($qfKey)) { + $urlParams .= "&qfKey=$qfKey"; + } + $url = CRM_Utils_System::url('civicrm/case/search', $urlParams); + } + elseif ($context == 'dashboard') { + $url = CRM_Utils_System::url('civicrm/case', 'reset=1'); + } + elseif (in_array($context, [ + 'dashlet', + 'dashletFullscreen', + ])) { + $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); + } + $session = CRM_Core_Session::singleton(); + $session->pushUserContext($url); + } + + /** + * Build the form object. + */ + public function buildQuickForm() { + $this->add('hidden', 'id', $this->id); + $this->add('hidden', 'contact_id', $this->cid); + $this->addButtons([ + [ + 'type' => 'submit', + 'name' => ts('Remove Client from Case'), + ], + [ + 'type' => 'cancel', + 'name' => ts('Cancel'), + ], + ]); + + // This form may change the url structure so should not submit via ajax + $this->preventAjaxSubmit(); + } + + /** + * Process the form. + */ + public function postProcess() { + $params = $this->controller->exportValues($this->_name); + civicrm_api3('CaseContact', 'get', [ + 'case_id' => $params['id'], + 'contact_id' => $params['contact_id'], + 'api.case_contact.delete' => ['id' => "\$value.id"], + ]); + + $pirmaryCaseContact = civicrm_api3('Activity', 'get', [ + 'case_id' => $this->id, + 'activity_type_id' => 'Open Case', + 'return' => ['assignee_contact_id', 'source_contact_id', 'target_contact_id'], + 'sequential' => 1, + ])['values'][0]['target_contact_id'][0]; + // user context + $url = CRM_Utils_System::url('civicrm/contact/view/case', + "reset=1&action=view&cid={$pirmaryCaseContact}&id={$params['id']}&show=1" + ); + CRM_Utils_System::redirect($url); + + } + +} diff --git a/CRM/Case/xml/Menu/Case.xml b/CRM/Case/xml/Menu/Case.xml index 91348e1c9a3d..28d716afa68d 100644 --- a/CRM/Case/xml/Menu/Case.xml +++ b/CRM/Case/xml/Menu/Case.xml @@ -141,4 +141,9 @@