/** * Function to process the form * * @access public * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //Check the contact provided in Application form is existing or new $profileContactType = CRM_Core_BAO_UFGroup::getContactType($this->_profileID); $dedupeParams = CRM_Dedupe_Finder::formatParams($params, $profileContactType); $dedupeParams['check_permission'] = FALSE; $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $profileContactType); $applicantID = $this->_contactID; if (count($ids) && !$applicantID) { $applicantID = CRM_Utils_Array::value(0, $ids); } $applicantID = CRM_Contact_BAO_Contact::createProfileContact($params, CRM_Core_DAO::$_nullArray, $applicantID, NULL, $this->_profileID); if ($applicantID) { $params['start_date'] = date("YmdHis"); $dao = new CRM_HRRecruitment_DAO_HRVacancyStage(); $dao->vacancy_id = $this->_id; $dao->find(); while ($dao->fetch()) { $params['case_status_id'] = $dao->case_status_id; break; } //Create case of type Application against creator applicant and assignee as Vacancy creator $caseTypes = array_flip(CRM_Case_PseudoConstant::caseType('name', TRUE, 'AND filter = 1')); $cases = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($applicantID, FALSE, 'Application'); foreach ($cases as $case) { $oldAppl = CRM_HRRecruitment_BAO_HRVacancy::getVacancyIDByCase($case); if ($oldAppl == $this->_id) { $params['id'] = $case; break; } } $params['case_type_id'] = $caseTypes['Application']; $caseObj = CRM_Case_BAO_Case::create($params); if (empty($params['id'])) { $contactParams = array('case_id' => $caseObj->id, 'contact_id' => $applicantID); CRM_Case_BAO_Case::addCaseToContact($contactParams); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $xmlProcessorParams = array('clientID' => $applicantID, 'creatorID' => $this->_creatorID, 'standardTimeline' => 1, 'activityTypeName' => 'Open Case', 'caseID' => $caseObj->id, 'activity_date_time' => $params['start_date']); $xmlProcessor->run('Application', $xmlProcessorParams); } //process Custom data CRM_Core_BAO_CustomValueTable::postprocess($params, CRM_Core_DAO::$_nullArray, 'civicrm_case', $caseObj->id, 'Case'); //Process case to vacancy one-to-one mapping in custom table 'application_case' $cgID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', 'application_case', 'id', 'name'); $result = civicrm_api3('CustomField', 'get', array('custom_group_id' => $cgID, 'name' => 'vacancy_id')); civicrm_api3('custom_value', 'create', array("custom_{$result['id']}" => $this->_id, 'entity_id' => $caseObj->id)); } if ($this->controller->getButtonName('submit') == "_qf_Application_upload") { CRM_Core_Session::setStatus(ts("Application has been successfully submitted.")); CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/vacancy/publiclisting', 'reset=1')); } }
/** * Given the list of params in the params array, fetch the object * and store the values in the values array * * @param array $params input parameters to find object * @param array $values output values of the object * * @return CRM_HRRecruitment_DAO_HRVacancy|null the found object or null * @access public * @static */ static function retrieve(&$params, &$defaults) { $vacancy = new self(); $vacancy->copyValues($params); if ($vacancy->find(TRUE)) { CRM_Core_DAO::storeValues($vacancy, $defaults); $stage = new CRM_HRRecruitment_DAO_HRVacancyStage(); $stage->vacancy_id = $vacancy->id; $stage->find(); while ($stage->fetch()) { $defaults['stages'][$stage->weight] = $stage->case_status_id; } $permission = new CRM_HRRecruitment_DAO_HRVacancyPermission(); $permission->vacancy_id = $vacancy->id; $permission->find(); $count = 1; while ($permission->fetch()) { $defaults['permission'][$count] = $permission->permission; $defaults['permission_contact_id'][$count] = $permission->contact_id; $count++; } foreach (array('application_profile', 'evaluation_profile') as $profileName) { $ufJoin = new CRM_Core_DAO_UFJoin(); $ufJoin->module = 'Vacancy'; $ufJoin->entity_id = $vacancy->id; $ufJoin->module_data = $profileName; $ufJoin->find(TRUE); $defaults[$profileName] = $ufJoin->uf_group_id; } } }
/** * returns the list of fields that can be exported * * @access public * return array * @static */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['hrvacancy_stage'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }