Ejemplo n.º 1
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     // process url params
     if ($this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive')) {
         $this->assign('contactID', $this->_contactID);
     }
     if ($this->_caseID = CRM_Utils_Request::retrieve('case_id', 'Positive')) {
         $this->assign('case_id', $this->_caseID);
         // get Vacancy ID
         $vacancyID = CRM_HRRecruitment_BAO_HRVacancy::getVacancyIDByCase($this->_caseID);
         //Get application and evaluaiton profile IDs
         foreach (array('application_profile', 'evaluation_profile') as $profileName) {
             $dao = new CRM_Core_DAO_UFJoin();
             $dao->module = 'Vacancy';
             $dao->entity_id = $vacancyID;
             $dao->module_data = $profileName;
             $dao->find(TRUE);
             $profile[$profileName] = $dao->uf_group_id;
         }
         //Check for existing Evaluation activity type and assign variables to tpl
         $this->assign('actions', 'add');
         $params = array('activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Evaluation'));
         $caseActivity = CRM_Case_BAO_Case::getCaseActivity($this->_caseID, $params, $this->_contactID);
         foreach ($caseActivity as $caseActivity) {
             $evalID = $caseActivity['id'];
             $this->assign('id', $evalID);
             $this->assign('actions', 'update');
         }
         $this->_profileID = $profile['application_profile'];
         $this->_evalProfileID = $profile['evaluation_profile'];
     }
 }
Ejemplo n.º 2
0
 public static function create(&$params)
 {
     $vacancy = new self();
     if (!empty($params['id'])) {
         CRM_Core_DAO::executeQuery("DELETE FROM civicrm_hrvacancy_stage WHERE vacancy_id = {$params['id']}");
         CRM_Core_DAO::executeQuery("DELETE FROM civicrm_hrvacancy_permission WHERE vacancy_id = {$params['id']}");
     }
     $vacancyParams = CRM_HRRecruitment_BAO_HRVacancy::formatParams($params);
     $entityName = 'HRVacancy';
     $hook = empty($params['id']) ? 'create' : 'edit';
     CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
     if (!empty($params['id'])) {
         $vacancy->find($params['id']);
         $vacancy->created_date = $vacancy->created_date ? CRM_Utils_Date::processDate($vacancy->created_date) : date('YmdHis');
         $vacancy->created_id = $vacancy->created_id ? $vacancy->created_id : CRM_Core_Session::singleton()->get('userID');
     } else {
         $vacancyParams['created_date'] = date('YmdHis');
         $vacancyParams['created_id'] = CRM_Core_Session::singleton()->get('userID');
     }
     $vacancy->copyValues($vacancyParams);
     $vacancy->save();
     if (isset($params['stages']) && count($params['stages'])) {
         foreach ($params['stages'] as $key => $stage_id) {
             $dao = new CRM_HRRecruitment_DAO_HRVacancyStage();
             $dao->case_status_id = $stage_id;
             $dao->vacancy_id = $vacancy->id;
             $dao->weight = $key + 1;
             $dao->save();
         }
     }
     foreach (array('application_profile', 'evaluation_profile') as $profileName) {
         if (!empty($params[$profileName])) {
             $dao = new CRM_Core_DAO_UFJoin();
             $dao->module = 'Vacancy';
             $dao->entity_table = 'civicrm_hrvacancy';
             $dao->entity_id = $vacancy->id;
             $dao->module_data = $profileName;
             if (!empty($params['id'])) {
                 $dao->find(TRUE);
             }
             $dao->uf_group_id = $params[$profileName];
             $dao->save();
         }
     }
     if (!empty($params['permission']) && !empty($params['permission_contact_id'])) {
         foreach ($params['permission'] as $key => $permission) {
             if ($permission && $params['permission_contact_id'][$key]) {
                 $dao = new CRM_HRRecruitment_DAO_HRVacancyPermission();
                 $dao->contact_id = $params['permission_contact_id'][$key];
                 $dao->permission = $permission;
                 $dao->vacancy_id = $vacancy->id;
                 $dao->save();
             }
         }
     }
     CRM_Utils_Hook::post($hook, $entityName, $vacancy->id, $vacancy);
     return $vacancy;
 }
Ejemplo n.º 3
0
 function run()
 {
     CRM_Core_Resources::singleton()->addStyleFile('org.civicrm.hrrecruitment', 'css/dashboard.css')->addScriptFile('org.civicrm.hrrecruitment', 'templates/CRM/HRRecruitment/Page/Dashboard.js')->addScriptFile('civicrm', 'packages/momentjs/moment.min.js');
     $vacancies = CRM_HRRecruitment_BAO_HRVacancy::getVacanciesByStatus();
     $recentActivities = CRM_HRRecruitment_BAO_HRVacancy::recentApplicationActivities();
     $this->assign('vacanciesByStatus', $vacancies);
     $this->assign('recentActivities', $recentActivities);
     parent::run();
 }
Ejemplo n.º 4
0
 function setUp()
 {
     parent::setUp();
     $permissionIndividual1Id = Contact::createIndividual();
     $permissionIndividual2Id = Contact::createIndividual();
     $juniorposition = 'Junior Support Specialist ' . substr(sha1(rand()), 0, 7);
     $this->juniorParams = array('position' => $juniorposition, 'location' => 'Headquaters', 'salary' => '$110-$130k/yr', 'description' => 'Answer phone calls and emails from irate customers.', 'benefits' => 'Have a place to park', 'requirements' => 'Pro-actively looks to build cross discipline experience and increase knowledge.', 'application_profile' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'application_profile', 'id', 'name'), 'evaluation_profile' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'evaluation_profile', 'id', 'name'), 'status_id' => '1', 'start_date' => '20140425151100', 'end_date' => '20140426231100', 'permission' => array('manage Applicants', 'administer Vacancy'), 'permission_contact_id' => array($permissionIndividual1Id, $permissionIndividual2Id));
     $this->juniorPosition = CRM_HRRecruitment_BAO_HRVacancy::create($this->juniorParams);
     $juniorposition2 = 'Junior Support Specialist ' . substr(sha1(rand()), 0, 7);
     $this->juniorParams2 = array('position' => $juniorposition2, 'location' => 'Home or Home-Office', 'salary' => '$110-$130k/yr', 'status_id' => '1', 'start_date' => '20140425151100', 'end_date' => '20140426231100');
     $this->juniorPosition2 = CRM_HRRecruitment_BAO_HRVacancy::create($this->juniorParams2);
     $seniorposition = 'Senior Support Specialist ' . substr(sha1(rand()), 0, 7);
     $this->seniorParams = array('position' => $seniorposition, 'location' => 'Headquaters', 'salary' => '$110-$130k/yr', 'description' => 'Answer phone calls and emails from irate customers.', 'benefits' => 'Have a place to park', 'requirements' => 'Pro-actively looks to build cross discipline experience and increase knowledge.', 'application_profile' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'application_profile', 'id', 'name'), 'evaluation_profile' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'evaluation_profile', 'id', 'name'), 'status_id' => '2', 'start_date' => '20140425151100', 'end_date' => '20140426231100', 'permission' => array('manage Applicants', 'administer Vacancy'), 'permission_contact_id' => array($permissionIndividual1Id, $permissionIndividual2Id));
     $this->seniorPosition = CRM_HRRecruitment_BAO_HRVacancy::create($this->seniorParams);
 }
Ejemplo n.º 5
0
 /**
  * create() method (create and update modes)
  */
 function testCreateGet()
 {
     $permissionIndividual1Id = Contact::createIndividual();
     $permissionIndividual2Id = Contact::createIndividual();
     $stages = array_keys(CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND grouping = 'Vacancy'"));
     $params = array('position' => 'Senior Support Specialist', 'location' => 'Headquaters', 'salary' => '$110-$130k/yr', 'description' => 'Answer phone calls and emails from irate customers.', 'benefits' => 'Have a place to park', 'requirements' => 'Pro-actively looks to build cross discipline experience and increase knowledge.', 'stages' => $stages, 'application_profile' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'application_profile', 'id', 'name'), 'evaluation_profile' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'evaluation_profile', 'id', 'name'), 'status_id' => '4', 'start_date' => '20140425151100', 'end_date' => '20140426231100', 'permission' => array('manage Applicants', 'administer Vacancy'), 'permission_contact_id' => array($permissionIndividual1Id, $permissionIndividual2Id));
     $vacancy = CRM_HRRecruitment_BAO_HRVacancy::create($params);
     $getValues = array();
     $getParams = array('id' => $vacancy->id);
     CRM_HRRecruitment_BAO_HRVacancy::retrieve($getParams, $getValues);
     //stage array index always starts with 1 so in order to make changes in
     //$getValues['stages'] in order to just match the value
     $getValues['stages'] = array_values($getValues['stages']);
     $getValues['permission'] = array_values($getValues['permission']);
     $getValues['permission_contact_id'] = array_values($getValues['permission_contact_id']);
     //process date back to mysql format
     $getValues['start_date'] = CRM_Utils_Date::isoToMysql($getValues['start_date']);
     $getValues['end_date'] = CRM_Utils_Date::isoToMysql($getValues['end_date']);
     foreach ($params as $column => $value) {
         $this->assertEquals($params[$column], $getValues[$column], "Check for Job {$column}.");
     }
 }
Ejemplo n.º 6
0
 /**
  * This function is to make a copy of a Vacancy, including
  * all the fields in the Vacancy wizard
  *
  * @return void
  * @access public
  */
 function copy()
 {
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE, 0, 'GET');
     $urlString = 'civicrm/vacancy/find';
     $copyVacancy = CRM_HRRecruitment_BAO_HRVacancy::copy($id);
     $urlParams = 'reset=1';
     // Redirect to Copied HRVacancy Configuration
     if ($copyVacancy->id) {
         $urlString = 'civicrm/vacancy/add';
         $urlParams .= '&action=update&id=' . $copyVacancy->id;
     }
     return CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams));
 }
Ejemplo n.º 7
0
 /**
  * Function to process the form
  *
  * @access public
  * @return void
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     if ($this->_id) {
         $params['id'] = $this->_id;
     }
     $params['is_template'] = $this->_isTemplate;
     CRM_HRRecruitment_BAO_HRVacancy::create($params);
     if ($this->controller->getButtonName('submit') == "_qf_HRVacancy_next") {
         $urlParams = "reset=1";
         if ($this->_isTemplate) {
             $urlParams .= "&template={$this->_isTemplate}";
         }
         CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/vacancy/find', $urlParams));
     }
 }
Ejemplo n.º 8
0
 /**
  * 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'));
     }
 }
Ejemplo n.º 9
0
/**
 * Implementation of hook_civicrm_buildForm
 *
 * @params string $formName - the name of the form
 *         object $form - reference to the form object
 * @return void
 */
function hrrecruitment_civicrm_buildForm($formName, &$form)
{
    $caseTypes = CRM_Case_PseudoConstant::caseType('name');
    $appValue = array_search('Application', $caseTypes);
    //To hide application case type from add assignment form
    if ($formName == 'CRM_Case_Form_Case') {
        if ($form->_action & CRM_Core_Action::DELETE || $form->_action & CRM_Core_Action::RENEW) {
            return;
        }
        $form->_caseType = CRM_Case_PseudoConstant::caseType();
        unset($form->_caseType[$appValue]);
        $form->add('select', 'case_type_id', ts('Assignment Type'), $form->_caseType, TRUE);
    }
    //report change
    if ($formName == 'CRM_Report_Form_Case_Summary' || $formName == 'CRM_Report_Form_Case_Detail') {
        $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE, 'AND filter = 1', TRUE);
        $form->case_statuses = $form->case_statuses + $statuses;
    }
    if ($formName == 'CRM_Activity_Form_Search') {
        $actId = CRM_Utils_Request::retrieve('type', 'Positive', $form);
        $form->_formValues['activity_type_id'][$actId] = $defaults['activity_type_id'][$actId] = 1;
        $form->setDefaults($defaults);
        $form->set('formValues', $form->_formValues);
        $form->preProcess();
    }
    if ($formName == 'CRM_Case_Form_CaseView') {
        $params = array('id' => $form->_caseID);
        CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, array('status_id'));
        $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE, 'AND (filter IN (0,1) OR filter IS NULL)', TRUE);
        $form->_caseDetails['case_status'] = $statuses[$values['case_status_id']];
        $form->assign('caseDetails', $form->_caseDetails);
    }
    if ($formName == 'CRM_Case_Form_Activity' || $formName == 'CRM_Contact_Form_Task_Email') {
        $caseId = CRM_Utils_Request::retrieve('caseid', 'String', $form);
        $vacancyID = CRM_HRRecruitment_BAO_HRVacancy::getVacancyIDByCase($caseId);
        $caseId = explode(',', $caseId);
        $aType = CRM_Utils_Request::retrieve('atype', 'Positive') ? CRM_Utils_Request::retrieve('atype', 'Positive') : CRM_Utils_Array::value('activity_type_id', $form->_defaultValues);
        $evalID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Evaluation');
        /* Check for proper permissions */
        if ($vacancyID && $aType) {
            $administerper = CRM_HRRecruitment_BAO_HRVacancyPermission::checkVacancyPermission($vacancyID, array("administer Vacancy", "administer CiviCRM", "manage Applicants"));
            $evaluateper = CRM_HRRecruitment_BAO_HRVacancyPermission::checkVacancyPermission($vacancyID, array("administer Vacancy", "administer CiviCRM", "evaluate Applicants"));
            if ($aType != $evalID && !$administerper || $aType == $evalID && !$evaluateper) {
                CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm'));
                CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to perform this action.'));
                return;
            }
        }
        /* TO set vacancy stages as case status for 'Change Case Status' activity */
        if ($aType == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Change Case Status')) {
            $allcase = TRUE;
            foreach ($caseId as $key => $val) {
                $caseType = CRM_Case_BAO_Case::getCaseType($val, 'id');
                if ($caseType != $appValue) {
                    $allcase = FALSE;
                }
            }
            if ($allcase) {
                $form->removeElement('case_status_id');
                $form->_caseStatus = CRM_Case_PseudoConstant::caseStatus('label', TRUE, 'AND filter = 1', TRUE);
                $form->add('select', 'case_status_id', ts('Case Status'), $form->_caseStatus, TRUE);
                if ($caseStatusId = CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form)) {
                    $form->freeze('case_status_id');
                    $form->setDefaults(array('case_status_id' => $caseStatusId));
                }
            }
        }
        /* build the evaluation profile on the evaluation activity */
        //check for evaluation activity type
        if ($aType == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Evaluation')) {
            //rename label and status name for Activity Status
            $activityStatus = $form->getElement('status_id');
            $activityStatus->_options = array();
            $scheduleStatus = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled');
            $completeStatus = CRM_Core_OptionGroup::getValue('activity_status', 'Completed');
            $activityStatus->addOption('Scheduled', $scheduleStatus);
            $activityStatus->addOption('Complete Evaluation', $completeStatus);
            $activityStatus->_label = 'Evaluation Status';
            //retriev Case ID, Activity ID, Contact ID
            $caseID = CRM_Utils_Request::retrieve('caseid', 'Positive', $form);
            $activityID = CRM_Utils_Request::retrieve('id', 'Positive', $form);
            $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $form);
            //get Evaluation profile ID
            $dao = new CRM_Core_DAO_UFJoin();
            $dao->module = 'Vacancy';
            $dao->entity_id = CRM_HRRecruitment_BAO_HRVacancy::getVacancyIDByCase($caseID);
            $dao->module_data = 'evaluation_profile';
            $dao->find(TRUE);
            $profileID = $dao->uf_group_id;
            $profileFields = CRM_Core_BAO_UFGroup::getFields($profileID);
            $form->assign('fields', $profileFields);
            CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $profileFields, $def);
            $form->setDefaults($def);
            //auto populate assignee contact name with vacancy related permission
            if ($form->_action & CRM_Core_Action::ADD) {
                $evaluateContactID = CRM_HRRecruitment_BAO_HRVacancyPermission::getPermissionContact($vacancyID, 'evaluate Applicants');
                $defaults['assignee_contact_id'] = $evaluateContactID;
                $form->setDefaults($defaults);
            }
            //build evaluaiton profile fields
            foreach ($profileFields as $profileFieldKey => $profileFieldVal) {
                CRM_Core_BAO_UFGroup::buildProfile($form, $profileFieldVal, CRM_Profile_Form::MODE_EDIT, $contactID, TRUE, FALSE, NULL);
                $form->_fields[$profileFieldKey] = $profileFields[$profileFieldKey];
                $params[$profileFieldKey] = $profileFieldVal;
            }
            if (!empty($activityID)) {
                $params['entityID'] = $activityID;
                $form->addElement('hidden', 'evaluationProfile', $profileID);
                $defVal = CRM_Core_BAO_CustomValueTable::getValues($params);
                $form->setDefaults($defVal);
            }
            CRM_Core_Region::instance('case-activity-form')->add(array('template' => 'CRM/UF/Form/Block.tpl'));
        }
        //HR-373 -- set Completed status for Comment activity by default
        if ($aType == CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Comment')) {
            $defaults['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed');
            $form->setDefaults($defaults);
        }
    }
    /* HR-401 Changes to Edit Evaluation and Application popups */
    if ($formName == 'CRM_Custom_Form_Field' || $formName == 'CRM_HRRecruitment_Form_HRVacancy') {
        $uncolapseAppl = $uncolapseEval = array();
        $applicationCG = civicrm_api3('CustomGroup', 'get', array('extends' => "Case", 'extends_entity_column_value' => $appValue, 'name' => 'Application'));
        foreach ($applicationCG['values'] as $k => $v) {
            $uncolapseAppl[] = $v['id'];
        }
        $evalCG = civicrm_api3('CustomGroup', 'get', array('extends' => "Activity", 'extends_entity_column_value' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Evaluation')));
        foreach ($evalCG['values'] as $k => $v) {
            $uncolapseEval[$k] = $v['id'];
        }
        CRM_Core_Resources::singleton()->addSetting(array('profileSelectorSet' => array('application' => $uncolapseAppl, 'evaluation' => $uncolapseEval)));
        $gID = CRM_Utils_Array::value('gid', $_GET);
        /* HR-401 set default for 'Is field searchable' */
        if (!empty($gID) && (in_array($gID, $uncolapseEval) || in_array($gID, $uncolapseAppl)) && $formName == 'CRM_Custom_Form_Field') {
            $default['is_searchable'] = 1;
            $form->setDefaults($default);
        }
    }
}