/** * Implementation of hook_civicrm_install */ function hrrecruitment_civicrm_install() { $activityTypesResult = civicrm_api3('activity_type', 'get', array()); $weight = count($activityTypesResult["values"]); foreach (array('Evaluation', 'Comment') as $activityType) { if (!in_array($activityType, $activityTypesResult["values"])) { civicrm_api3('activity_type', 'create', array('weight' => $weight++, 'name' => $activityType, 'label' => $activityType, 'is_active' => 1)); } } $result = civicrm_api3('OptionGroup', 'create', array('name' => 'vacancy_status', 'title' => ts('Vacancy Status'), 'is_reserved' => 1, 'is_active' => 1)); $vacancyStatus = array('Draft' => ts('Draft'), 'Open' => ts('Open'), 'Closed' => ts('Closed'), 'Cancelled' => ts('Cancelled'), 'Rejected' => ts('Rejected')); $weight = 1; foreach ($vacancyStatus as $name => $label) { $statusParam = array('option_group_id' => $result['id'], 'label' => $label, 'name' => $name, 'value' => $weight++, 'is_active' => 1); if ($name == 'Draft') { $statusParam['is_default'] = 1; } elseif ($name == 'Open') { $statusParam['is_reserved'] = 1; } civicrm_api3('OptionValue', 'create', $statusParam); } $stages = array('Apply' => ts('Apply'), 'Ongoing_Vacancy' => ts('Ongoing'), 'Phone_Interview' => ts('Phone Interview'), 'Manager_Interview' => ts('Manager Interview'), 'Board_Interview' => ts('Board Interview'), 'Group_Interview' => ts('Group Interview'), 'Psych_Exam' => ts('Psych Exam'), 'Offer' => ts('Offer'), 'Hired' => ts('Hired')); $count = count(CRM_Core_OptionGroup::values('case_status')); foreach ($stages as $name => $label) { $count++; $caseStatusParam = array('option_group_id' => 'case_status', 'label' => $label, 'name' => $name, 'value' => $count, 'grouping' => 'Vacancy', 'filter' => 1); civicrm_api3('OptionValue', 'create', $caseStatusParam); } $reportWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Reports', 'weight', 'name'); $vacancyNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => ts('Vacancies'), 'name' => 'Vacancies', 'url' => null, 'operator' => null, 'weight' => $reportWeight - 1, 'is_active' => 1); $vacancyNavigation->copyValues($params); $vacancyNavigation->save(); $evalID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Evaluation'); $vacancyMenuTree = array(array('label' => ts('Dashboard'), 'name' => 'dashboard', 'url' => 'civicrm/vacancy/dashboard?reset=1', 'permission' => 'view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM', 'permission_operator' => 'OR'), array('label' => ts('Public Vacancy List'), 'name' => 'public_list', 'url' => 'civicrm/vacancy/publiclisting?reset=1', 'permission' => NULL, 'has_separator' => 1), array('label' => ts('New Vacancy'), 'name' => 'new_vacancy', 'url' => 'civicrm/vacancy/add?reset=1', 'permission' => 'administer Vacancy, administer CiviCRM', 'permission_operator' => 'OR'), array('label' => ts('New Template'), 'name' => 'new_template', 'url' => 'civicrm/vacancy/add?reset=1&template=1', 'permission' => 'administer Vacancy, administer CiviCRM', 'permission_operator' => 'OR'), array('label' => ts('New Applicant'), 'name' => 'new_applicant', 'has_separator' => 1), array('label' => ts('Find Vacancies'), 'name' => 'find_vacancies', 'url' => 'civicrm/vacancy/find?reset=1', 'permission' => 'view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM', 'permission_operator' => 'OR'), array('label' => ts('Find Templates'), 'name' => 'find_templates', 'url' => 'civicrm/vacancy/find?reset=1&template=1', 'permission' => 'view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM', 'permission_operator' => 'OR'), array('label' => ts('Search by Application Form Fields'), 'name' => 'find_application', 'url' => 'civicrm/case/search?reset=1', 'permission' => 'view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM', 'permission_operator' => 'OR'), array('label' => ts('Search by Evaluation Criteria'), 'name' => 'find_evaluation', 'url' => "civicrm/activity/search?force=1&type={$evalID}&reset=1", 'permission' => 'view Applicants, manage Applicants, evaluate Applicants, administer Vacancy, administer CiviCRM', 'permission_operator' => 'OR')); foreach ($vacancyMenuTree as $key => $menuItems) { $menuItems['is_active'] = 1; $menuItems['parent_id'] = $vacancyNavigation->id; $menuItems['weight'] = $key; CRM_Core_BAO_Navigation::add($menuItems); } CRM_Core_BAO_Navigation::resetNavigation(); return _hrrecruitment_civix_civicrm_install(); }
/** * Implementation of hook_civicrm_install * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install */ function hrjobcontract_civicrm_install() { $cType = CRM_Contact_BAO_ContactType::basicTypePairs(false, 'id'); $org_id = array_search('Organization', $cType); $sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider'); $orgSubType = CRM_Contact_BAO_ContactType::subTypes('Organization', true); $orgSubType = CRM_Contact_BAO_ContactType::subTypeInfo('Organization'); $params['parent_id'] = $org_id; $params['is_active'] = 1; if ($org_id) { foreach ($sub_type_name as $sub_type_name) { $subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name)); $subID = array_key_exists($subTypeName, $orgSubType); if (!$subID) { $params['name'] = $subTypeName; $params['label'] = $sub_type_name; CRM_Contact_BAO_ContactType::add($params); } elseif ($subID && $orgSubType[$subTypeName]['is_active'] == 0) { CRM_Contact_BAO_ContactType::setIsActive($orgSubType[$subTypeName]['id'], 1); } } } // Add Job Contract top menu $jobContractNavigation = new CRM_Core_DAO_Navigation(); $jobContractNavigation->name = 'job_contracts'; $jobContractNavigationResult = $jobContractNavigation->find(); if (!$jobContractNavigationResult) { $contactsWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contacts', 'weight', 'name'); $jobContractNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => ts('Job Contracts'), 'name' => 'job_contracts', 'url' => null, 'operator' => null, 'weight' => $contactsWeight + 1, 'is_active' => 1); $jobContractNavigation->copyValues($params); $jobContractNavigation->save(); $jobContractMenuTree = array(array('label' => ts('Import / Export'), 'name' => 'import_export_job_contracts')); foreach ($jobContractMenuTree as $key => $menuItems) { $menuItems['is_active'] = 1; $menuItems['parent_id'] = $jobContractNavigation->id; $menuItems['weight'] = $key; CRM_Core_BAO_Navigation::add($menuItems); } } return _hrjobcontract_civix_civicrm_install(); }
/** * Implementation of hook_civicrm_install */ function simpledonate_civicrm_install() { //Add menu for donation page link under Contribution parent navigation //And Configuration link under Admin navigation $civiContributeParentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'CiviContribute', 'id', 'name'); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => 'Simple Donate Configuration', 'name' => 'Simple Donate Configuration', 'url' => 'civicrm/simple/donation/configuration?reset=1', 'permission' => 'access CiviContribute', 'parent_id' => $civiContributeParentId, 'has_separator' => 1, 'is_active' => 1); CRM_Core_BAO_Navigation::add($params); $contributionsParentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contributions', 'id', 'name'); $donationNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => 'Simple Donate', 'name' => 'Simple Donate', 'url' => NULL, 'permission' => 'access CiviContribute', 'parent_id' => $contributionsParentId, 'has_separator' => 1, 'is_active' => 1, 'weight' => 100); $donationNavigation->copyValues($params); $donationNavigation->save(); $donationMenuTree = array(array('label' => ts('Test mode'), 'name' => 'Test Donation', 'url' => 'civicrm/simple?test=1#/donation', 'permission' => 'access CiviContribute'), array('label' => ts('Live mode'), 'name' => 'Live Donation', 'url' => 'civicrm/simple/#/donation', 'permission' => 'access CiviContribute')); foreach ($donationMenuTree as $key => $menuItems) { $menuItems['is_active'] = 1; $menuItems['parent_id'] = $donationNavigation->id; $menuItems['weight'] = $key; CRM_Core_BAO_Navigation::add($menuItems); } return _simpledonate_civix_civicrm_install(); }
/** * Implementation of hook_civicrm_install */ function hrjob_civicrm_install() { $cType = CRM_Contact_BAO_ContactType::basicTypePairs(false, 'id'); $org_id = array_search('Organization', $cType); $sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider'); $orgSubType = CRM_Contact_BAO_ContactType::subTypes('Organization', true); $orgSubType = CRM_Contact_BAO_ContactType::subTypeInfo('Organization'); $params['parent_id'] = $org_id; $params['is_active'] = 1; if ($org_id) { foreach ($sub_type_name as $sub_type_name) { $subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name)); $subID = array_key_exists($subTypeName, $orgSubType); if (!$subID) { $params['name'] = $subTypeName; $params['label'] = $sub_type_name; CRM_Contact_BAO_ContactType::add($params); } elseif ($subID && $orgSubType[$subTypeName]['is_active'] == 0) { CRM_Contact_BAO_ContactType::setIsActive($orgSubType[$subTypeName]['id'], 1); } } } //Add job import navigation menu $weight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Import Contacts', 'weight', 'name'); $contactNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contacts', 'id', 'name'); $administerNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Dropdown Options', 'id', 'name'); $importJobNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => ts('Import Jobs'), 'name' => 'jobImport', 'url' => null, 'parent_id' => $contactNavId, 'weight' => $weight + 1, 'permission' => 'access HRJobs', 'separator' => 1, 'is_active' => 1); $importJobNavigation->copyValues($params); $importJobNavigation->save(); $importJobMenuTree = array(array('label' => ts('Hours Types'), 'name' => 'hoursType', 'url' => 'civicrm/hour/editoption', 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId)); foreach ($importJobMenuTree as $key => $menuItems) { $menuItems['is_active'] = 1; CRM_Core_BAO_Navigation::add($menuItems); } CRM_Core_BAO_Navigation::resetNavigation(); return _hrjob_civix_civicrm_install(); }
/** * Function to update menu * * @param array $params * @param array $newParams new value of params * @static */ static function processUpdate($params, $newParams) { $dao = new CRM_Core_DAO_Navigation(); $dao->copyValues($params); if ($dao->find(true)) { $dao->copyValues($newParams); $dao->save(); } }
/** * Implementation of hook_civicrm_install */ function hrabsence_civicrm_install() { $reportWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Reports', 'weight', 'name'); $absenceNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => 'Absences', 'name' => 'Absences', 'url' => null, 'operator' => null, 'weight' => $reportWeight - 1, 'is_active' => 1); $absenceNavigation->copyValues($params); $absenceNavigation->save(); $absenceMenuTree = array(array('label' => ts('My Absences'), 'name' => 'my_absences', 'url' => 'civicrm/absences', 'permission' => 'view HRAbsences, edit HRAbsences, administer CiviCRM, manage own HRAbsences'), array('label' => ts('Calendar'), 'name' => 'calendar', 'url' => null, 'permission' => 'access HRReport'), array('label' => ts('New Absence'), 'name' => 'new_absence', 'url' => null, 'permission' => 'edit HRAbsences,administer CiviCRM,manage own HRAbsences', 'permission_operator' => 'OR', 'has_separator' => 1), array('label' => ts('Public Holidays'), 'name' => 'publicHolidays', 'url' => 'civicrm/absence/holidays?reset=1', 'permission' => 'administer CiviCRM'), array('label' => ts('Absence Periods'), 'name' => 'absencePeriods', 'url' => 'civicrm/absence/period?reset=1', 'permission' => 'administer CiviCRM'), array('label' => ts('Absence Types'), 'name' => 'absenceTypes', 'url' => 'civicrm/absence/type?reset=1', 'permission' => 'administer CiviCRM', 'has_separator' => 1), array('label' => ts('Absence Report'), 'name' => 'absence_report', 'url' => 'civicrm/report/list?grp=absence&reset=1', 'permission' => 'access HRReport')); foreach ($absenceMenuTree as $key => $menuItems) { $menuItems['is_active'] = 1; $menuItems['parent_id'] = $absenceNavigation->id; $menuItems['weight'] = $key; CRM_Core_BAO_Navigation::add($menuItems); } $isEnabled = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Extension', 'org.civicrm.hrreport', 'is_active', 'full_name'); $reportParentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Reports', 'id', 'name'); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => 'Absence Report', 'name' => 'absenceReport', 'url' => 'civicrm/report/list?grp=absence&reset=1', 'permission' => 'access HRReport', 'parent_id' => $reportParentId, 'is_active' => $isEnabled); CRM_Core_BAO_Navigation::add($params); CRM_Core_BAO_Navigation::resetNavigation(); $params = array('sequential' => 1, 'option_group_id' => 'activity_status', 'name' => 'Rejected', 'is_reserved' => 1, 'is_active' => 1); civicrm_api3('OptionValue', 'create', $params); /* Create message template for absence leave application */ $msg_text = '{ts}Dear{/ts} {$displayName}, {ts}Employee:{/ts} {$empName} {ts}Position:{/ts} {$empPosition} {ts}Absence Type:{/ts} {$absenceType} {ts}Dates:{/ts} {$startDate} - {$endDate} {if $cancel} {ts}Leave has been cancelled.{/ts} {elseif $reject} {ts}Leave has been rejected.{/ts} {elseif $approval} Leave has been approved for {$appDays}. {/if} {ts}Date{/ts} | {ts}Absence{/ts} | {if $approval and $totDays neq $appDays} {ts}Approve{/ts} {/if} {foreach from=$absentDateDurations item=value key=label} {if $value.duration != 0} {$label|date_format} | {if $value.duration == $jobHoursTime.Full_Time*60} {ts}Full Day{/ts} {elseif $value.duration == $jobHoursTime.Part_Time*60} {ts}Half Day{/ts} {/if} | {if $approval and $totDays neq $appDays} {if $value.approval == 2}{ts}Approved{/ts} {elseif $value.approval == 9} {ts}Unapproved{/ts} {/if} {/if} {/if} {/foreach} {ts}Total{/ts} | {$totDays} {if $customGroup} {foreach from=$customGroup item=value key=customName} {foreach from=$value item=v key=n} {$customName} : {$v} {/foreach} {/foreach} {/if}'; $msg_html = '<p>{ts}Dear{/ts} {$displayName},</p> <table> <tbody> <tr> <td>{ts}Employee:{/ts}</td> <td>{$empName}</td> </tr> <tr> <td>{ts}Position:{/ts}</td> <td>{$empPosition}</td> </tr> <tr> <td>{ts}Absence Type:{/ts}</td> <td>{$absenceType}</td> </tr> <tr> <td>{ts}Dates:{/ts}</td> <td>{$startDate|date_format} - {$endDate|date_format}</td> </tr> </tbody> </table> {if $cancel} <p> {ts}Leave has been cancelled.{/ts} </p> {elseif $reject} <p> {ts}Leave has been rejected.{/ts} </p> {elseif $approval} <p> Leave has been approved for {$appDays}.</p> {/if} <br/> <table border="1" border-spacing="0"> <tbody> <tr> <th> {ts}Date{/ts} </th> <th> {ts}Absence{/ts} </th> {if $approval and $totDays neq $appDays} <th> {ts}Status{/ts} </th> {/if} </tr> {foreach from=$absentDateDurations item=value key=label} {if $value.duration != 0} <tr> <td>{$label|date_format}</td> <td>{if $value.duration == $jobHoursTime.Full_Time*60} {ts}Full Day{/ts} {elseif $value.duration == $jobHoursTime.Part_Time*60} {ts}Half Day{/ts} {else} {/if}</td> {if $approval and $totDays neq $appDays} <td>{if $value.approval == 2} {ts}Approved{/ts} {elseif $value.approval == 9} {ts}Unapproved{/ts} {else}{/if}</td> {/if} </tr> {/if} {/foreach} <tr> <td>{ts}Total{/ts}</td> <td>{$totDays}</td> {if $approval and $totDays neq $appDays} <td> </td> {/if} </tr> </tbody> </table> <br/> {if $customGroup} <table> <tbody> {foreach from=$customGroup item=value key=customName} {foreach from=$value item=v key=n} <tr> <td> {$customName} : </td> <td> {$v} </td> </tr> {/foreach} {/foreach} </tbody> </table> {/if}'; $subject = '{if $approval}Absences Approved{elseif $cancel}Absences Cancelled{elseif $reject}Absences Rejected{else}Absences Application{/if}'; $msg_params = array('msg_title' => 'Absence Email', 'msg_subject' => $subject, 'msg_text' => $msg_text, 'msg_html' => $msg_html, 'workflow_id' => NULL, 'is_default' => '1', 'is_reserved' => '0'); civicrm_api3('message_template', 'create', $msg_params); return _hrabsence_civix_civicrm_install(); }
/** * Install Appraisals top navigation * * @return boolean */ public function upgrade_0007() { // Add Appraisals to the Top Navigation menu CRM_Core_DAO::executeQuery("DELETE FROM `civicrm_navigation` WHERE name = 'appraisals' and parent_id IS NULL"); $weight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contacts', 'weight', 'name'); //$contactNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contacts', 'id', 'name'); $appraisalsNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => ts('Appraisals'), 'name' => 'appraisals', 'url' => null, 'parent_id' => null, 'weight' => $weight + 1, 'separator' => 1, 'is_active' => 1); $appraisalsNavigation->copyValues($params); $appraisalsNavigation->save(); if ($appraisalsNavigation->id) { $submenu = array(array('label' => ts('Appraisals Dashboard'), 'name' => 'appraisals_dashboard', 'url' => 'civicrm/appraisals/dashboard'), array('label' => ts('Search Appraisals'), 'name' => 'search_appraisals', 'url' => 'civicrm/appraisals/search'), array('label' => ts('Import Appraisals'), 'name' => 'import_appraisals', 'url' => 'civicrm/appraisals/import')); foreach ($submenu as $key => $item) { $item['parent_id'] = $appraisalsNavigation->id; $item['weight'] = $key; $item['is_active'] = 1; CRM_Core_BAO_Navigation::add($item); } } $administerNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Administer', 'id', 'name'); $aministerAppraisalMenu = array('label' => ts('Appraisal grade labels'), 'name' => 'appraisal_grade_labels', 'url' => 'civicrm/appraisal_criteria', 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId, 'is_active' => 1); CRM_Core_BAO_Navigation::add($aministerAppraisalMenu); CRM_Core_BAO_Navigation::resetNavigation(); return TRUE; }
public function upgradeBundle() { //$this->ctx->log->info('Applying update 0999'); $this->executeCustomDataFile('xml/option_group_install.xml'); //$this->ctx->log->info('Applying update 1101'); $this->executeCustomDataFile('xml/1101_departments.xml'); //$this->ctx->log->info('Applying update 1105'); if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_pension_type', 'name')) { $this->executeCustomDataFile('xml/1105_pension_type.xml'); } /* DEPRECATED: //$this->ctx->log->info('Applying update 1201'); //get all fields of Custom Group "HRJobContract_Summary" $params = array( 'custom_group_id' => 'HRJobContract_Summary', ); $results = civicrm_api3('CustomField', 'get', $params); foreach ($results['values'] as $result) { $result['is_view'] = 0; // make the field editable civicrm_api3('CustomField', 'create', $result); } //disable trigger CRM_Core_DAO::triggerRebuild();*/ //$this->ctx->log->info('Applying update 1202'); //Add job import navigation menu $weight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Import Contacts', 'weight', 'name'); $contactNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contacts', 'id', 'name'); $importJobNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => ts('Import Jobs'), 'name' => 'jobImport', 'url' => null, 'parent_id' => $contactNavId, 'weight' => $weight + 1, 'permission' => 'access HRJobs', 'separator' => 1, 'is_active' => 1); $importJobNavigation->copyValues($params); $importJobNavigation->save(); //$this->ctx->log->info('Applying update 1400'); $i = 4; $params = array('option_group_id' => 'hrjc_contract_type', 'name' => 'Employee_Permanent', 'weight' => $i, 'label' => 'Employee - Permanent', 'value' => 'Employee - Permanent'); civicrm_api3('OptionValue', 'create', $params); /* DEPRECATED: $empoption_id = civicrm_api3('OptionValue', 'getsingle', array('return' => "id",'option_group_id' => 'hrjc_contract_type', 'name' => "Employee")); civicrm_api3('OptionValue', 'create',array('id' => $empoption_id['id'],'name' => "Employee_Temporary",'label' => 'Employee - Temporary', 'value' => 'Employee - Temporary')); */ $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_contract_type', 'id', 'name'); foreach (array('Intern', 'Trustee', 'Volunteer') as $opName) { $i++; CRM_Core_DAO::executeQuery("UPDATE civicrm_option_value SET weight = {$i} WHERE name = '{$opName}' and option_group_id = {$optionGroupID}"); } $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_hours_type', 'id', 'name'); //change value of stored hours type CRM_Core_DAO::executeQuery("UPDATE civicrm_hrjobcontract_hour SET hours_type = CASE hours_type WHEN 'full' THEN 8 WHEN 'part' THEN 4 WHEN 'casual' THEN 0 ELSE hours_type END"); //$this->ctx->log->info('Applying update 1402'); //Upgrade for HR-394 and HR-395 $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_region', 'id', 'name'); if (!$optionGroupID) { $params = array('name' => 'hrjc_region', 'title' => 'Region', 'is_active' => 1); $newRegionGroupResult = civicrm_api3('OptionGroup', 'create', $params); } // Migrate old 'hrjob_region' option values into new 'hrjc_region': if (!empty($newRegionGroupResult['id'])) { $oldRegionGroup = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjob_region")); if (!empty($oldRegionGroup['id'])) { $oldRegionsResult = civicrm_api3('OptionValue', 'get', array('sequential' => 1, 'option_group_id' => $oldRegionGroup['id'])); foreach ($oldRegionsResult['values'] as $oldRegion) { $newRegion = $oldRegion; unset($newRegion['id']); $newRegion['option_group_id'] = $newRegionGroupResult['id']; civicrm_api3('OptionValue', 'create', $newRegion); } } } $result = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_hrjobcontract_hour ORDER BY id ASC'); while ($result->fetch()) { $fteFraction = CRM_Hrjobcontract_Upgrader::decToFraction($result->hours_fte); CRM_Core_DAO::executeQuery("UPDATE civicrm_hrjobcontract_hour SET fte_num={$fteFraction[0]} , fte_denom={$fteFraction[1]} WHERE id = {$result->id}"); } //$this->ctx->log->info('Applying update 1404'); $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_pay_grade', 'id', 'name'); $sql = "UPDATE civicrm_option_value SET civicrm_option_value.value = CASE civicrm_option_value.label WHEN 'Paid' THEN 1 WHEN 'Unpaid' THEN 0 END WHERE option_group_id = {$optionGroupId}"; CRM_Core_DAO::executeQuery($sql); CRM_Core_DAO::triggerRebuild(); $reportTemplateOptionGroup = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_option_group WHERE name='report_template' AND is_active = 1 LIMIT 1"); if ($reportTemplateOptionGroup->fetch()) { $hrjobcontractReportTemplateQuery = "INSERT INTO `civicrm_option_value` (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `domain_id`, `visibility_id`) VALUES\n (%1, 'JobContract Revision Report', 'hrjobcontract/summary', 'CRM_Hrjobcontract_Report_Form_Summary', NULL, 0, 0, 54, 'JobContract Revision Report', 0, 0, 1, NULL, NULL, NULL)"; $hrjobcontractReportTemplateParams = array(1 => array($reportTemplateOptionGroup->id, 'Integer')); CRM_Core_DAO::executeQuery($hrjobcontractReportTemplateQuery, $hrjobcontractReportTemplateParams); } CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_hrjobcontract_hour` ADD `location_type` INT(3) NULL DEFAULT NULL AFTER `id`"); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_hrjobcontract_hour` CHANGE `location_type` `location_standard_hours` INT(3) NULL DEFAULT NULL"); CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS civicrm_hrhours_location"); CRM_Core_DAO::executeQuery("\n CREATE TABLE IF NOT EXISTS `civicrm_hrhours_location` (\n `id` int(10) unsigned NOT NULL,\n `location` varchar(63) DEFAULT NULL,\n `standard_hours` int(4) DEFAULT NULL,\n `periodicity` varchar(63) DEFAULT NULL,\n `is_active` tinyint(4) DEFAULT '1'\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1\n "); CRM_Core_DAO::executeQuery("\n INSERT INTO `civicrm_hrhours_location` (`id`, `location`, `standard_hours`, `periodicity`, `is_active`) VALUES\n (1, 'Head office', 40, 'Week', 1),\n (2, 'Other office', 8, 'Day', 1),\n (3, 'Small office', 36, 'Week', 1)\n "); $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_revision_change_reason', 'id', 'name'); if (!$optionGroupID) { $params = array('name' => 'hrjc_revision_change_reason', 'title' => 'Job Contract Revision Change Reason', 'is_active' => 1, 'is_reserved' => 1); civicrm_api3('OptionGroup', 'create', $params); $optionsValue = array(1 => 'Reason 1', 2 => 'Reason 2', 3 => 'Reason 3'); foreach ($optionsValue as $key => $value) { $opValueParams = array('option_group_id' => 'hrjc_revision_change_reason', 'name' => $value, 'label' => $value, 'value' => $key); civicrm_api3('OptionValue', 'create', $opValueParams); } } CRM_Core_DAO::executeQuery("\n ALTER TABLE `civicrm_hrjobcontract_pay` ADD `annual_benefits` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `pay_is_auto_est`, ADD `annual_deductions` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `annual_benefits`\n "); CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS civicrm_hrhours_location"); CRM_Core_DAO::executeQuery("\n CREATE TABLE IF NOT EXISTS `civicrm_hrhours_location` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `location` varchar(63) DEFAULT NULL,\n `standard_hours` int(4) DEFAULT NULL,\n `periodicity` varchar(63) DEFAULT NULL,\n `is_active` tinyint(4) DEFAULT '1',\n PRIMARY KEY(id)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1\n "); CRM_Core_DAO::executeQuery("\n INSERT INTO `civicrm_hrhours_location` (`id`, `location`, `standard_hours`, `periodicity`, `is_active`) VALUES\n (1, 'Head office', 40, 'Week', 1),\n (2, 'Other office', 8, 'Day', 1),\n (3, 'Small office', 36, 'Week', 1)\n "); // pay_cycle: $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_pay_cycle', 'id', 'name'); if (!$optionGroupID) { $params = array('name' => 'hrjc_pay_cycle', 'title' => 'Job Contract Pay Cycle', 'is_active' => 1, 'is_reserved' => 1); civicrm_api3('OptionGroup', 'create', $params); $optionsValue = array(1 => 'Weekly', 2 => 'Monthly'); foreach ($optionsValue as $key => $value) { $opValueParams = array('option_group_id' => 'hrjc_pay_cycle', 'name' => $value, 'label' => $value, 'value' => $key); civicrm_api3('OptionValue', 'create', $opValueParams); } } // benefit_name: $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_benefit_name', 'id', 'name'); if (!$optionGroupID) { $params = array('name' => 'hrjc_benefit_name', 'title' => 'Job Contract Benefit Name', 'is_active' => 1, 'is_reserved' => 1); civicrm_api3('OptionGroup', 'create', $params); $optionsValue = array(1 => 'Bike', 2 => 'Medical'); foreach ($optionsValue as $key => $value) { $opValueParams = array('option_group_id' => 'hrjc_benefit_name', 'name' => $value, 'label' => $value, 'value' => $key); civicrm_api3('OptionValue', 'create', $opValueParams); } } // benefit_type: $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_benefit_type', 'id', 'name'); if (!$optionGroupID) { $params = array('name' => 'hrjc_benefit_type', 'title' => 'Job Contract Benefit Type', 'is_active' => 1, 'is_reserved' => 1); civicrm_api3('OptionGroup', 'create', $params); $optionsValue = array(1 => 'Fixed', 2 => '%'); foreach ($optionsValue as $key => $value) { $opValueParams = array('option_group_id' => 'hrjc_benefit_type', 'name' => $value, 'label' => $value, 'value' => $key); civicrm_api3('OptionValue', 'create', $opValueParams); } } // deduction_name: $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_deduction_name', 'id', 'name'); if (!$optionGroupID) { $params = array('name' => 'hrjc_deduction_name', 'title' => 'Job Contract Deduction Name', 'is_active' => 1, 'is_reserved' => 1); civicrm_api3('OptionGroup', 'create', $params); $optionsValue = array(1 => 'Bike', 2 => 'Medical'); foreach ($optionsValue as $key => $value) { $opValueParams = array('option_group_id' => 'hrjc_deduction_name', 'name' => $value, 'label' => $value, 'value' => $key); civicrm_api3('OptionValue', 'create', $opValueParams); } } // deduction_type: $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_deduction_type', 'id', 'name'); if (!$optionGroupID) { $params = array('name' => 'hrjc_deduction_type', 'title' => 'Job Contract Deduction Type', 'is_active' => 1, 'is_reserved' => 1); civicrm_api3('OptionGroup', 'create', $params); $optionsValue = array(1 => 'Fixed', 2 => '%'); foreach ($optionsValue as $key => $value) { $opValueParams = array('option_group_id' => 'hrjc_deduction_type', 'name' => $value, 'label' => $value, 'value' => $key); civicrm_api3('OptionValue', 'create', $opValueParams); } } CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_hrjobcontract_pay` ADD `pay_cycle` INT(4) DEFAULT NULL AFTER `annual_deductions`, ADD `pay_per_cycle_gross` DECIMAL(10,2) DEFAULT NULL AFTER `pay_cycle`, ADD `pay_per_cycle_net` DECIMAL(10,2) DEFAULT NULL AFTER `pay_per_cycle_gross`"); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_hrjobcontract_revision` ADD `editor_uid` INT(10) NULL DEFAULT NULL AFTER `jobcontract_id`"); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_hrjobcontract` ADD `deleted` INT(2) UNSIGNED NOT NULL DEFAULT '0'"); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_hrjobcontract_revision` ADD `deleted` INT(2) UNSIGNED NOT NULL DEFAULT '0'"); // Navigation items: CRM_Core_DAO::executeQuery("DELETE FROM `civicrm_navigation` WHERE name IN ('hoursType', 'pay_scale', 'hours_location', 'hrjc_contract_type', 'hrjc_location', 'hrjc_pay_cycle', 'hrjc_benefit_name', 'hrjc_benefit_type', 'hrjc_deduction_name', 'hrjc_deduction_type', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_pension_type', 'hrjc_revision_change_reason')"); // Add administer options $administerNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Dropdown Options', 'id', 'name'); $jobContractOptionsMenuTree = array(array('label' => ts('Hours Types'), 'name' => 'hoursType', 'url' => 'civicrm/hour/editoption', 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId), array('label' => ts('Job Contract Pay Scale'), 'name' => 'pay_scale', 'url' => 'civicrm/pay_scale', 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId), array('label' => ts('Job Contract Hours/Location'), 'name' => 'hours_location', 'url' => 'civicrm/hours_location', 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId)); // hrjc_contract_type: $result = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjc_contract_type")); if (!empty($result['id'])) { $jobContractOptionsMenuTree[] = array('label' => ts('Contract Type'), 'name' => 'hrjc_contract_type', 'url' => 'civicrm/admin/options?gid=' . $result['id'], 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId); } // hrjc_location: $result = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjc_location")); if (!empty($result['id'])) { $jobContractOptionsMenuTree[] = array('label' => ts('Normal place of work'), 'name' => 'hrjc_location', 'url' => 'civicrm/admin/options?gid=' . $result['id'], 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId); // Migrating old 'hrjob_location' option values into new 'hrjc_location': $oldLocationGroup = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjob_location")); if (!empty($oldLocationGroup['id'])) { $oldLocationsResult = civicrm_api3('OptionValue', 'get', array('sequential' => 1, 'option_group_id' => $oldLocationGroup['id'])); foreach ($oldLocationsResult['values'] as $oldLocation) { $newLocationResult = civicrm_api3('OptionValue', 'get', array('sequential' => 1, 'option_group_id' => $result['id'], 'value' => $oldLocation['value'])); if (!empty($newLocationResult['id'])) { continue; } $newLocation = $oldLocation; unset($newLocation['id']); $newLocation['option_group_id'] = $result['id']; civicrm_api3('OptionValue', 'create', $newLocation); } } } // hrjc_pay_cycle: $result = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjc_pay_cycle")); if (!empty($result['id'])) { $jobContractOptionsMenuTree[] = array('label' => ts('Pay cycle'), 'name' => 'hrjc_pay_cycle', 'url' => 'civicrm/admin/options?gid=' . $result['id'], 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId); } // hrjc_benefit_name: $result = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjc_benefit_name")); if (!empty($result['id'])) { $jobContractOptionsMenuTree[] = array('label' => ts('Benefits'), 'name' => 'hrjc_benefit_name', 'url' => 'civicrm/admin/options?gid=' . $result['id'], 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId); } // hrjc_benefit_type: $result = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjc_benefit_type")); if (!empty($result['id'])) { $jobContractOptionsMenuTree[] = array('label' => ts('Benefit type'), 'name' => 'hrjc_benefit_type', 'url' => 'civicrm/admin/options?gid=' . $result['id'], 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId); } // hrjc_deduction_name: $result = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjc_deduction_name")); if (!empty($result['id'])) { $jobContractOptionsMenuTree[] = array('label' => ts('Deductions'), 'name' => 'hrjc_deduction_name', 'url' => 'civicrm/admin/options?gid=' . $result['id'], 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId); } // hrjc_deduction_type: $result = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjc_deduction_type")); if (!empty($result['id'])) { $jobContractOptionsMenuTree[] = array('label' => ts('Deduction type'), 'name' => 'hrjc_deduction_type', 'url' => 'civicrm/admin/options?gid=' . $result['id'], 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId); } // hrjc_pension_type: $result = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjc_pension_type")); if (!empty($result['id'])) { $jobContractOptionsMenuTree[] = array('label' => ts('Pension provider type'), 'name' => 'hrjc_pension_type', 'url' => 'civicrm/admin/options?gid=' . $result['id'], 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId); } // hrjc_revision_change_reason: $result = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'name' => "hrjc_revision_change_reason")); if (!empty($result['id'])) { $jobContractOptionsMenuTree[] = array('label' => ts('Reason for change'), 'name' => 'hrjc_revision_change_reason', 'url' => 'civicrm/admin/options?gid=' . $result['id'], 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId); } foreach ($jobContractOptionsMenuTree as $key => $menuItems) { $menuItems['is_active'] = 1; CRM_Core_BAO_Navigation::add($menuItems); } CRM_Core_BAO_Navigation::resetNavigation(); // Delete old HRJob Option Groups: CRM_Core_DAO::executeQuery("DELETE FROM civicrm_option_group WHERE name IN ('hrjob_contract_type',\n 'hrjob_department',\n 'hrjob_health_provider',\n 'hrjob_hours_type',\n 'hrjob_level_type',\n 'hrjob_life_provider',\n 'hrjob_pay_grade',\n 'hrjob_pay_scale',\n 'hrjob_pension_type',\n 'hrjob_region',\n 'hrjob_location')"); $this->upgrade_1001(); $this->upgrade_1002(); $this->upgrade_1003(); $this->upgrade_1004(); $this->upgrade_1005(); $this->upgrade_1006(); $this->upgrade_1008(); $this->upgrade_1009(); }
public function upgrade_1202() { $this->ctx->log->info('Applying update 1202'); if (!CRM_Core_DAO::checkFieldExists('civicrm_hrjob_pay', 'pay_annualized_est')) { CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_hrjob_pay ADD COLUMN pay_annualized_est decimal(40,2) DEFAULT NULL COMMENT "Estimated Annual Pay" AFTER pay_currency'); } if (!CRM_Core_DAO::checkFieldExists('civicrm_hrjob_pay', 'pay_is_auto_est')) { CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_hrjob_pay ADD COLUMN pay_is_auto_est tinyint DEFAULT 1 COMMENT "Is the estimate automatically calculated" AFTER pay_annualized_est'); } $defaults = array('Year' => 1, 'Month' => 12, 'Week' => 50, 'Day' => 50 * 5, 'Hour' => 50 * 5 * 8); foreach ($defaults as $unit => $multiple) { // See also: CRM_HRJob_Estimator::updateEstimate* // After HR-1.2.0 ships, don't make changes to the logic of upgrade_1202. CRM_Core_DAO::executeQuery(' UPDATE civicrm_hrjob_pay p, civicrm_hrjob_hour h SET p.pay_annualized_est = %1 * h.hours_fte * p.pay_amount WHERE p.job_id = h.job_id AND p.pay_unit = %2 AND p.pay_is_auto_est = 1 ', array(1 => array($multiple, 'Float'), 2 => array($unit, 'String'))); } //Add job import navigation menu $weight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Import Contacts', 'weight', 'name'); $contactNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contacts', 'id', 'name'); $importJobNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => ts('Import Jobs'), 'name' => 'jobImport', 'url' => null, 'parent_id' => $contactNavId, 'weight' => $weight + 1, 'permission' => 'access HRJobs', 'separator' => 1, 'is_active' => 1); $importJobNavigation->copyValues($params); $importJobNavigation->save(); return TRUE; }