3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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', ts('Link To Case'));
76 $form->add('hidden', 'link_to_case_id', '', array('id' => 'link_to_case_id'));
80 * global validation rules for the form
82 * @param array $values posted values of the form
84 * @return array list of errors to be posted back to the form
88 static function formRule($values, $files, $form) {
91 $linkCaseId = CRM_Utils_Array
::value('link_to_case_id', $values);
93 $errors['link_to_case'] = ts('Please select a case to link.');
95 elseif ($linkCaseId == $form->_caseId
) {
96 $errors['link_to_case'] = ts('Please select some other case to link.');
99 // do check for existing related cases.
100 $relatedCases = $form->get('relatedCases');
101 if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) {
102 $errors['link_to_case'] = ts('It looks like selected case is already linked.');
105 return empty($errors) ?
TRUE : $errors;
109 * Function to process the form
115 static function beginPostProcess(&$form, &$params) {
116 $params['id'] = $params['case_id'];
120 * Function to process the form
126 static function endPostProcess(&$form, &$params, &$activity) {
127 $activityId = $activity->id
;
128 $linkCaseID = CRM_Utils_Array
::value('link_to_case_id', $params);
130 //create a link between two cases.
131 if ($activityId && $linkCaseID) {
133 'case_id' => $linkCaseID,
134 'activity_id' => $activityId,
136 CRM_Case_BAO_Case
::processCaseActivity($caseParams);