3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class generates form components for OpenCase Activity
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.'));
46 $form->assign('clientID', $form->_currentlyViewedContactId
);
47 $form->assign('caseTypeLabel', CRM_Case_BAO_Case
::getCaseType($form->_caseId
));
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);
55 $excludeCaseIds = array($form->_caseId
);
56 if (is_array($relatedCases) && !empty($relatedCases)) {
57 $excludeCaseIds = array_merge($excludeCaseIds, array_keys($relatedCases));
59 $form->assign('excludeCaseIds', implode(',', $excludeCaseIds));
63 * This function sets the default values for the form. For edit/view mode
64 * the default values are retrieved from the database
70 static function setDefaultValues(&$form) {
71 return $defaults = array();
74 static function buildQuickForm(&$form) {
75 $form->add('text', 'link_to_case_id', ts('Link To Case'), array('class' => 'huge'), TRUE);
79 * global validation rules for the form
81 * @param array $values posted values of the form
83 * @return array list of errors to be posted back to the form
87 static function formRule($values, $files, $form) {
90 $linkCaseId = CRM_Utils_Array
::value('link_to_case_id', $values);
91 if ($linkCaseId == $form->_caseId
) {
92 $errors['link_to_case'] = ts('Please select some other case to link.');
95 // do check for existing related cases.
96 $relatedCases = $form->get('relatedCases');
97 if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) {
98 $errors['link_to_case'] = ts('Selected case is already linked.');
101 return empty($errors) ?
TRUE : $errors;
105 * Function to process the form
111 static function beginPostProcess(&$form, &$params) {}
114 * Function to process the form
120 static function endPostProcess(&$form, &$params, &$activity) {
121 $activityId = $activity->id
;
122 $linkCaseID = CRM_Utils_Array
::value('link_to_case_id', $params);
124 //create a link between two cases.
125 if ($activityId && $linkCaseID) {
127 'case_id' => $linkCaseID,
128 'activity_id' => $activityId,
130 CRM_Case_BAO_Case
::processCaseActivity($caseParams);