3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class assigns the current case to another client.
37 class CRM_Case_Form_EditClient
extends CRM_Core_Form
{
40 * Build all the data structures needed to build the form.
42 public function preProcess() {
43 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
44 CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
45 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
47 //get current client name.
48 $this->assign('currentClientName', CRM_Contact_BAO_Contact
::displayName($cid));
51 $url = CRM_Utils_System
::url('civicrm/contact/view', "reset=1&force=1&cid={$cid}&selectedChild=case");
52 if ($context == 'search') {
53 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
55 $urlParams = 'force=1';
56 if (CRM_Utils_Rule
::qfKey($qfKey)) {
57 $urlParams .= "&qfKey=$qfKey";
59 $url = CRM_Utils_System
::url('civicrm/case/search', $urlParams);
61 elseif ($context == 'dashboard') {
62 $url = CRM_Utils_System
::url('civicrm/case', 'reset=1');
64 elseif (in_array($context, [
68 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
70 $session = CRM_Core_Session
::singleton();
71 $session->pushUserContext($url);
75 * Build the form object.
77 public function buildQuickForm() {
78 $this->addEntityRef('reassign_contact_id', ts('Select Contact'), ['create' => TRUE], TRUE);
82 'name' => ts('Reassign Case'),
86 'name' => ts('Cancel'),
90 // This form may change the url structure so should not submit via ajax
91 $this->preventAjaxSubmit();
94 public function addRules() {
95 $this->addFormRule([get_class($this), 'formRule'], $this);
101 * @param CRM_Core_Form $form
105 public static function formRule($vals, $rule, $form) {
107 if (empty($vals['reassign_contact_id']) ||
$vals['reassign_contact_id'] == $form->get('cid')) {
108 $errors['reassign_contact_id'] = ts("Please select a different contact.");
116 public function postProcess() {
117 $params = $this->controller
->exportValues($this->_name
);
119 //assign case to another client.
120 $mainCaseId = CRM_Case_BAO_Case
::mergeCases($params['reassign_contact_id'], $this->get('id'), $this->get('cid'), NULL, TRUE);
123 $url = CRM_Utils_System
::url('civicrm/contact/view/case',
124 "reset=1&action=view&cid={$params['reassign_contact_id']}&id={$mainCaseId[0]}&show=1"
126 CRM_Core_Session
::singleton()->pushUserContext($url);