3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class assigns the current case to another client.
21 class CRM_Case_Form_EditClient
extends CRM_Core_Form
{
24 * Build all the data structures needed to build the form.
26 public function preProcess() {
27 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
28 CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
29 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
31 //get current client name.
32 $this->assign('currentClientName', CRM_Contact_BAO_Contact
::displayName($cid));
35 $url = CRM_Utils_System
::url('civicrm/contact/view', "reset=1&force=1&cid={$cid}&selectedChild=case");
36 if ($context == 'search') {
37 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
39 $urlParams = 'force=1';
40 if (CRM_Utils_Rule
::qfKey($qfKey)) {
41 $urlParams .= "&qfKey=$qfKey";
43 $url = CRM_Utils_System
::url('civicrm/case/search', $urlParams);
45 elseif ($context == 'dashboard') {
46 $url = CRM_Utils_System
::url('civicrm/case', 'reset=1');
48 elseif (in_array($context, [
52 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
54 $session = CRM_Core_Session
::singleton();
55 $session->pushUserContext($url);
59 * Build the form object.
61 public function buildQuickForm() {
62 $this->addEntityRef('reassign_contact_id', ts('Select Contact'), ['create' => TRUE], TRUE);
66 'name' => ts('Reassign Case'),
70 'name' => ts('Cancel'),
74 // This form may change the url structure so should not submit via ajax
75 $this->preventAjaxSubmit();
78 public function addRules() {
79 $this->addFormRule([get_class($this), 'formRule'], $this);
85 * @param CRM_Core_Form $form
89 public static function formRule($vals, $rule, $form) {
91 if (empty($vals['reassign_contact_id']) ||
$vals['reassign_contact_id'] == $form->get('cid')) {
92 $errors['reassign_contact_id'] = ts("Please select a different contact.");
100 public function postProcess() {
101 $params = $this->controller
->exportValues($this->_name
);
103 //assign case to another client.
104 $mainCaseId = CRM_Case_BAO_Case
::mergeCases($params['reassign_contact_id'], $this->get('id'), $this->get('cid'), NULL, TRUE);
107 $url = CRM_Utils_System
::url('civicrm/contact/view/case',
108 "reset=1&action=view&cid={$params['reassign_contact_id']}&id={$mainCaseId[0]}&show=1"
110 CRM_Core_Session
::singleton()->pushUserContext($url);