Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
df371444 | 19 | * This class assigns the current case to another client. |
6a488035 TO |
20 | */ |
21 | class CRM_Case_Form_EditClient extends CRM_Core_Form { | |
22 | ||
23 | /** | |
fe482240 | 24 | * Build all the data structures needed to build the form. |
6a488035 TO |
25 | */ |
26 | public function preProcess() { | |
66adc860 CW |
27 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); |
28 | CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); | |
edc80cda | 29 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
6a488035 TO |
30 | |
31 | //get current client name. | |
66adc860 | 32 | $this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($cid)); |
6a488035 TO |
33 | |
34 | //set the context. | |
66adc860 | 35 | $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$cid}&selectedChild=case"); |
6a488035 TO |
36 | if ($context == 'search') { |
37 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); | |
38 | //validate the qfKey | |
39 | $urlParams = 'force=1'; | |
40 | if (CRM_Utils_Rule::qfKey($qfKey)) { | |
41 | $urlParams .= "&qfKey=$qfKey"; | |
42 | } | |
43 | $url = CRM_Utils_System::url('civicrm/case/search', $urlParams); | |
44 | } | |
45 | elseif ($context == 'dashboard') { | |
46 | $url = CRM_Utils_System::url('civicrm/case', 'reset=1'); | |
47 | } | |
be2fb01f | 48 | elseif (in_array($context, [ |
353ffa53 | 49 | 'dashlet', |
3bdca100 | 50 | 'dashletFullscreen', |
be2fb01f | 51 | ])) { |
6a488035 TO |
52 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); |
53 | } | |
54 | $session = CRM_Core_Session::singleton(); | |
55 | $session->pushUserContext($url); | |
56 | } | |
57 | ||
58 | /** | |
fe482240 | 59 | * Build the form object. |
6a488035 TO |
60 | */ |
61 | public function buildQuickForm() { | |
be2fb01f CW |
62 | $this->addEntityRef('reassign_contact_id', ts('Select Contact'), ['create' => TRUE], TRUE); |
63 | $this->addButtons([ | |
64 | [ | |
66adc860 CW |
65 | 'type' => 'done', |
66 | 'name' => ts('Reassign Case'), | |
be2fb01f CW |
67 | ], |
68 | [ | |
cc1bf3ed CW |
69 | 'type' => 'cancel', |
70 | 'name' => ts('Cancel'), | |
be2fb01f CW |
71 | ], |
72 | ]); | |
66adc860 CW |
73 | |
74 | // This form may change the url structure so should not submit via ajax | |
75 | $this->preventAjaxSubmit(); | |
76 | } | |
6a488035 | 77 | |
00be9182 | 78 | public function addRules() { |
be2fb01f | 79 | $this->addFormRule([get_class($this), 'formRule'], $this); |
66adc860 CW |
80 | } |
81 | ||
4c6ce474 EM |
82 | /** |
83 | * @param $vals | |
84 | * @param $rule | |
c490a46a | 85 | * @param CRM_Core_Form $form |
4c6ce474 EM |
86 | * |
87 | * @return array | |
88 | */ | |
00be9182 | 89 | public static function formRule($vals, $rule, $form) { |
be2fb01f | 90 | $errors = []; |
66adc860 CW |
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."); | |
93 | } | |
94 | return $errors; | |
6a488035 TO |
95 | } |
96 | ||
97 | /** | |
fe482240 | 98 | * Process the form. |
6a488035 TO |
99 | */ |
100 | public function postProcess() { | |
101 | $params = $this->controller->exportValues($this->_name); | |
102 | ||
103 | //assign case to another client. | |
66adc860 | 104 | $mainCaseId = CRM_Case_BAO_Case::mergeCases($params['reassign_contact_id'], $this->get('id'), $this->get('cid'), NULL, TRUE); |
6a488035 TO |
105 | |
106 | // user context | |
107 | $url = CRM_Utils_System::url('civicrm/contact/view/case', | |
66adc860 | 108 | "reset=1&action=view&cid={$params['reassign_contact_id']}&id={$mainCaseId[0]}&show=1" |
6a488035 | 109 | ); |
66adc860 | 110 | CRM_Core_Session::singleton()->pushUserContext($url); |
6a488035 | 111 | } |
96025800 | 112 | |
6a488035 | 113 | } |