3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
35 * This class generates form components for LinkCase Activity.
37 class CRM_Case_Form_Activity_LinkCases
{
39 * @param CRM_Core_Form $form
43 public static function preProcess(&$form) {
44 if (empty($form->_caseId
)) {
45 CRM_Core_Error
::fatal(ts('Case Id not found.'));
47 if (count($form->_caseId
) != 1) {
48 CRM_Core_Resources
::fatal(ts('Expected one case-type'));
51 $caseId = CRM_Utils_Array
::first($form->_caseId
);
53 $form->assign('clientID', $form->_currentlyViewedContactId
);
54 $form->assign('sortName', CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $form->_currentlyViewedContactId
, 'sort_name'));
55 $form->assign('caseTypeLabel', CRM_Case_BAO_Case
::getCaseType($caseId));
57 // get the related cases for given case.
58 $relatedCases = $form->get('relatedCases');
59 if (!isset($relatedCases)) {
60 $relatedCases = CRM_Case_BAO_Case
::getRelatedCases($caseId);
61 $form->set('relatedCases', empty($relatedCases) ?
FALSE : $relatedCases);
66 * Set default values for the form.
68 * @param CRM_Core_Form $form
72 public static function setDefaultValues(&$form) {
74 if (!empty($_GET['link_to_case_id']) && CRM_Utils_Rule
::positiveInteger($_GET['link_to_case_id'])) {
75 $defaults['link_to_case_id'] = $_GET['link_to_case_id'];
81 * @param CRM_Core_Form $form
83 public static function buildQuickForm(&$form) {
84 $excludeCaseIds = (array) $form->_caseId
;
85 $relatedCases = $form->get('relatedCases');
86 if (is_array($relatedCases) && !empty($relatedCases)) {
87 $excludeCaseIds = array_merge($excludeCaseIds, array_keys($relatedCases));
89 $form->addEntityRef('link_to_case_id', ts('Link To Case'), array(
92 'extra' => array('case_id.case_type_id.title', 'contact_id.sort_name'),
94 'case_id' => array('NOT IN' => $excludeCaseIds),
95 'case_id.is_deleted' => 0,
102 * Global validation rules for the form.
104 * @param array $values
105 * Posted values of the form.
108 * @param CRM_Core_Form $form
111 * list of errors to be posted back to the form
113 public static function formRule($values, $files, $form) {
116 $linkCaseId = CRM_Utils_Array
::value('link_to_case_id', $values);
117 assert('is_numeric($linkCaseId)');
118 if ($linkCaseId == CRM_Utils_Array
::first($form->_caseId
)) {
119 $errors['link_to_case'] = ts('Please select some other case to link.');
122 // do check for existing related cases.
123 $relatedCases = $form->get('relatedCases');
124 if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) {
125 $errors['link_to_case'] = ts('Selected case is already linked.');
128 return empty($errors) ?
TRUE : $errors;
132 * Process the form submission.
135 * @param CRM_Core_Form $form
136 * @param array $params
138 public static function beginPostProcess(&$form, &$params) {
142 * Process the form submission.
145 * @param CRM_Core_Form $form
146 * @param array $params
147 * @param CRM_Activity_BAO_Activity $activity
149 public static function endPostProcess(&$form, &$params, &$activity) {
150 $activityId = $activity->id
;
151 $linkCaseID = CRM_Utils_Array
::value('link_to_case_id', $params);
153 //create a link between two cases.
154 if ($activityId && $linkCaseID) {
156 'case_id' => $linkCaseID,
157 'activity_id' => $activityId,
159 CRM_Case_BAO_Case
::processCaseActivity($caseParams);