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 | * | |
355ba699 | 68 | * @return void |
6a488035 TO |
69 | */ |
70 | static function setDefaultValues(&$form) { | |
71 | return $defaults = array(); | |
72 | } | |
73 | ||
74 | static function buildQuickForm(&$form) { | |
f72119d9 | 75 | $form->add('text', 'link_to_case_id', ts('Link To Case'), array('class' => 'huge'), TRUE); |
6a488035 TO |
76 | } |
77 | ||
78 | /** | |
79 | * global validation rules for the form | |
80 | * | |
81 | * @param array $values posted values of the form | |
82 | * | |
83 | * @return array list of errors to be posted back to the form | |
84 | * @static | |
85 | * @access public | |
86 | */ | |
87 | static function formRule($values, $files, $form) { | |
88 | $errors = array(); | |
89 | ||
90 | $linkCaseId = CRM_Utils_Array::value('link_to_case_id', $values); | |
f72119d9 | 91 | if ($linkCaseId == $form->_caseId) { |
6a488035 TO |
92 | $errors['link_to_case'] = ts('Please select some other case to link.'); |
93 | } | |
94 | ||
95 | // do check for existing related cases. | |
96 | $relatedCases = $form->get('relatedCases'); | |
97 | if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) { | |
f72119d9 | 98 | $errors['link_to_case'] = ts('Selected case is already linked.'); |
6a488035 TO |
99 | } |
100 | ||
101 | return empty($errors) ? TRUE : $errors; | |
102 | } | |
103 | ||
104 | /** | |
105 | * Function to process the form | |
106 | * | |
107 | * @access public | |
108 | * | |
355ba699 | 109 | * @return void |
6a488035 | 110 | */ |
3c624c17 | 111 | static function beginPostProcess(&$form, &$params) {} |
6a488035 TO |
112 | |
113 | /** | |
114 | * Function to process the form | |
115 | * | |
116 | * @access public | |
117 | * | |
355ba699 | 118 | * @return void |
6a488035 TO |
119 | */ |
120 | static function endPostProcess(&$form, &$params, &$activity) { | |
121 | $activityId = $activity->id; | |
122 | $linkCaseID = CRM_Utils_Array::value('link_to_case_id', $params); | |
123 | ||
124 | //create a link between two cases. | |
125 | if ($activityId && $linkCaseID) { | |
126 | $caseParams = array( | |
127 | 'case_id' => $linkCaseID, | |
128 | 'activity_id' => $activityId, | |
129 | ); | |
130 | CRM_Case_BAO_Case::processCaseActivity($caseParams); | |
131 | } | |
132 | } | |
133 | } | |
134 |