_caseId)) { CRM_Core_Error::fatal(ts('Case Id not found.')); } $form->assign('clientID', $form->_currentlyViewedContactId); $form->assign('caseTypeLabel', CRM_Case_BAO_Case::getCaseType($form->_caseId)); // get the related cases for given case. $relatedCases = $form->get('relatedCases'); if (!isset($relatedCases)) { $relatedCases = CRM_Case_BAO_Case::getRelatedCases($form->_caseId, $form->_currentlyViewedContactId); $form->set('relatedCases', empty($relatedCases) ? FALSE : $relatedCases); } $excludeCaseIds = array($form->_caseId); if (is_array($relatedCases) && !empty($relatedCases)) { $excludeCaseIds = array_merge($excludeCaseIds, array_keys($relatedCases)); } $form->assign('excludeCaseIds', implode(',', $excludeCaseIds)); } /** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database * * @access public * * @return void */ static function setDefaultValues(&$form) { return $defaults = array(); } static function buildQuickForm(&$form) { $form->add('text', 'link_to_case_id', ts('Link To Case'), array('class' => 'huge'), TRUE); } /** * global validation rules for the form * * @param array $values posted values of the form * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule($values, $files, $form) { $errors = array(); $linkCaseId = CRM_Utils_Array::value('link_to_case_id', $values); if ($linkCaseId == $form->_caseId) { $errors['link_to_case'] = ts('Please select some other case to link.'); } // do check for existing related cases. $relatedCases = $form->get('relatedCases'); if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) { $errors['link_to_case'] = ts('Selected case is already linked.'); } return empty($errors) ? TRUE : $errors; } /** * Function to process the form * * @access public * * @return void */ static function beginPostProcess(&$form, &$params) {} /** * Function to process the form * * @access public * * @return void */ static function endPostProcess(&$form, &$params, &$activity) { $activityId = $activity->id; $linkCaseID = CRM_Utils_Array::value('link_to_case_id', $params); //create a link between two cases. if ($activityId && $linkCaseID) { $caseParams = array( 'case_id' => $linkCaseID, 'activity_id' => $activityId, ); CRM_Case_BAO_Case::processCaseActivity($caseParams); } } }