public static function registerResources($contactID, $absenceTypes = NULL, $activityTypes = NULL, $periods = NULL) { static $loaded = FALSE; if ($loaded) { return; } $loaded = TRUE; CRM_Core_Resources::singleton()->addSettingsFactory(function () use($contactID, $absenceTypes, $activityTypes, $periods) { if ($periods === NULL) { $res = civicrm_api3('HRAbsencePeriod', 'get', array('options' => array('sort' => "start_date DESC"))); $periods = $res['values']; } if ($absenceTypes === NULL) { $res = civicrm_api3('HRAbsenceType', 'get', array()); $absenceTypes = $res['values']; } if ($activityTypes === NULL) { $activityTypes = CRM_HRAbsence_BAO_HRAbsenceType::getActivityTypes(); } $legend = new CRM_HRAbsence_TypeLegend(9, $absenceTypes, $activityTypes); $i = 1; foreach ($periods as $key => $val) { $sortPeriods[$i] = $val; $i++; } return array('PseudoConstant' => array('locationType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), 'absenceStatus' => CRM_HRAbsence_BAO_HRAbsenceType::getActivityStatus()), 'Permissions' => array('viewWidget' => CRM_HRAbsence_Page_EmployeeAbsencePage::checkPermissions($contactID, 'viewWidget'), 'newAbsences' => CRM_HRAbsence_Page_EmployeeAbsencePage::checkPermissions($contactID, 'enableNewAbsence'), 'enableEntitlement' => CRM_HRAbsence_Page_EmployeeAbsencePage::checkPermissions($contactID, 'enableEntitlements'), 'getJobInfo' => CRM_HRAbsence_Page_EmployeeAbsencePage::checkPermissions($contactID, 'getJobInfo'), 'getOwnJobInfo' => CRM_HRAbsence_Page_EmployeeAbsencePage::checkPermissions($contactID, 'getOwnJobInfo')), 'FieldOptions' => CRM_HRAbsence_Page_EmployeeAbsencePage::getFieldOptions(), 'absenceApp' => array('contactId' => $contactID, 'activityTypes' => $activityTypes, 'absenceTypes' => $absenceTypes, 'legend' => $legend->getMap(), 'periods' => $periods, 'sortPeriods' => $sortPeriods, 'standardDay' => 8 * 60, 'apiTsFmt' => 'YYYY-MM-DD HH:mm:ss')); })->addScriptFile('civicrm', 'packages/momentjs/moment.min.js', 100, 'html-header', FALSE)->addScriptFile('civicrm', 'packages/backbone/json2.js', 100, 'html-header', FALSE)->addScriptFile('civicrm', 'packages/backbone/backbone.js', 120, 'html-header')->addScriptFile('civicrm', 'packages/backbone/backbone.marionette.js', 125, 'html-header', FALSE)->addScriptFile('civicrm', 'packages/backbone/backbone.modelbinder.js', 125, 'html-header', FALSE)->addScriptFile('civicrm', 'js/crm.backbone.js', 130, 'html-header', FALSE)->addStyleFile('org.civicrm.hrabsence', 'css/hrabsence.css', 140, 'html-header')->addStyleFile('org.civicrm.hrabsence', 'css/jquery.multiselect.css', 140, 'html-header')->addScriptFile('org.civicrm.hrabsence', 'js/jquery.multiselect.js', 140, 'html-header'); self::addScriptFiles('org.civicrm.hrabsence', 'js/*.js', 200, 'html-header'); self::addScriptFiles('org.civicrm.hrabsence', 'js/*/*.js', 300, 'html-header'); self::addScriptFiles('org.civicrm.hrabsence', 'js/*/*/*.js', 400, 'html-header'); self::addTemplateFiles('org.civicrm.hrabsence', 'CRM/HRAbsence/Underscore/*.tpl', 'page-header'); // self::addTemplates('civicrm', 'CRM/Form/validate.tpl', 'page-header'); }
/** * Implementation of hook_civicrm_tabs */ function hrabsence_civicrm_tabs(&$tabs, $contactID) { $contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type', 'id'); if (!($contactType == 'Individual' && CRM_HRAbsence_Page_EmployeeAbsencePage::checkPermissions($contactID, 'viewWidget'))) { return; } $absence = civicrm_api3('Activity', 'getabsences', array('target_contact_id' => $contactID)); $absenceDuration = 0; foreach ($absence['values'] as $k => $v) { $absenceDuration += CRM_HRAbsence_BAO_HRAbsenceType::getAbsenceDuration($v['id']); } CRM_HRAbsence_Page_EmployeeAbsencePage::registerResources($contactID); $tabs[] = array('id' => 'absenceTab', 'url' => CRM_Utils_System::url('civicrm/absences', array('cid' => $contactID, 'snippet' => 1)), 'count' => $absenceDuration / (8 * 60), 'title' => ts('Absences'), 'weight' => 300); }