Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for OpenCase Activity | |
38 | * | |
39 | */ | |
40 | class CRM_Case_Form_Activity_LinkCases { | |
41 | static function preProcess(&$form) { | |
42 | if (!isset($form->_caseId)) { | |
43 | CRM_Core_Error::fatal(ts('Case Id not found.')); | |
44 | } | |
45 | ||
46 | $form->assign('clientID', $form->_currentlyViewedContactId); | |
47 | $form->assign('caseTypeLabel', CRM_Case_BAO_Case::getCaseType($form->_caseId)); | |
48 | ||
49 | // get the related cases for given case. | |
50 | $relatedCases = $form->get('relatedCases'); | |
51 | if (!isset($relatedCases)) { | |
52 | $relatedCases = CRM_Case_BAO_Case::getRelatedCases($form->_caseId, $form->_currentlyViewedContactId); | |
53 | $form->set('relatedCases', empty($relatedCases) ? FALSE : $relatedCases); | |
54 | } | |
55 | $excludeCaseIds = array($form->_caseId); | |
56 | if (is_array($relatedCases) && !empty($relatedCases)) { | |
57 | $excludeCaseIds = array_merge($excludeCaseIds, array_keys($relatedCases)); | |
58 | } | |
59 | $form->assign('excludeCaseIds', implode(',', $excludeCaseIds)); | |
60 | } | |
61 | ||
62 | /** | |
63 | * This function sets the default values for the form. For edit/view mode | |
64 | * the default values are retrieved from the database | |
65 | * | |
66 | * @access public | |
67 | * | |
77b97be7 EM |
68 | * @param $form |
69 | * | |
355ba699 | 70 | * @return void |
6a488035 TO |
71 | */ |
72 | static function setDefaultValues(&$form) { | |
73 | return $defaults = array(); | |
74 | } | |
75 | ||
76 | static function buildQuickForm(&$form) { | |
f72119d9 | 77 | $form->add('text', 'link_to_case_id', ts('Link To Case'), array('class' => 'huge'), TRUE); |
6a488035 TO |
78 | } |
79 | ||
80 | /** | |
81 | * global validation rules for the form | |
82 | * | |
83 | * @param array $values posted values of the form | |
84 | * | |
77b97be7 EM |
85 | * @param $files |
86 | * @param $form | |
87 | * | |
6a488035 TO |
88 | * @return array list of errors to be posted back to the form |
89 | * @static | |
90 | * @access public | |
91 | */ | |
92 | static function formRule($values, $files, $form) { | |
93 | $errors = array(); | |
94 | ||
95 | $linkCaseId = CRM_Utils_Array::value('link_to_case_id', $values); | |
f72119d9 | 96 | if ($linkCaseId == $form->_caseId) { |
6a488035 TO |
97 | $errors['link_to_case'] = ts('Please select some other case to link.'); |
98 | } | |
99 | ||
100 | // do check for existing related cases. | |
101 | $relatedCases = $form->get('relatedCases'); | |
102 | if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) { | |
f72119d9 | 103 | $errors['link_to_case'] = ts('Selected case is already linked.'); |
6a488035 TO |
104 | } |
105 | ||
106 | return empty($errors) ? TRUE : $errors; | |
107 | } | |
108 | ||
109 | /** | |
110 | * Function to process the form | |
111 | * | |
112 | * @access public | |
113 | * | |
355ba699 | 114 | * @return void |
6a488035 | 115 | */ |
3c624c17 | 116 | static function beginPostProcess(&$form, &$params) {} |
6a488035 TO |
117 | |
118 | /** | |
119 | * Function to process the form | |
120 | * | |
121 | * @access public | |
122 | * | |
355ba699 | 123 | * @return void |
6a488035 TO |
124 | */ |
125 | static function endPostProcess(&$form, &$params, &$activity) { | |
126 | $activityId = $activity->id; | |
127 | $linkCaseID = CRM_Utils_Array::value('link_to_case_id', $params); | |
128 | ||
129 | //create a link between two cases. | |
130 | if ($activityId && $linkCaseID) { | |
131 | $caseParams = array( | |
132 | 'case_id' => $linkCaseID, | |
133 | 'activity_id' => $activityId, | |
134 | ); | |
135 | CRM_Case_BAO_Case::processCaseActivity($caseParams); | |
136 | } | |
137 | } | |
138 | } | |
139 |