Exemple #1
0
 /**
  * Function to process the form
  *
  * @access public
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_HRAbsence_BAO_HRAbsenceType::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected absence type has been deleted.'), 'Success', 'success');
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         foreach (array('allow_debits', 'allow_credits', 'is_active') as $key => $index) {
             if (!array_key_exists($index, $params)) {
                 $params[$index] = 0;
             }
         }
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $params['id'] = $this->_id;
         }
         $absenceType = CRM_HRAbsence_BAO_HRAbsenceType::create($params);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             CRM_Core_Session::setStatus(ts('The absence type \'%1\' has been updated.', array(1 => $absenceType->title)), 'Success', 'success');
         } else {
             CRM_Core_Session::setStatus(ts('The absence type \'%1\' has been added.', array(1 => $absenceType->title)), 'Success', 'success');
         }
         $url = CRM_Utils_System::url('civicrm/absence/type', 'reset=1&action=browse');
         $session = CRM_Core_Session::singleton();
         $session->replaceUserContext($url);
     }
 }
Exemple #2
0
 public function installAbsenceTypes()
 {
     $leaves = TRUE;
     $weight = 0;
     $values = '';
     $options = CRM_Core_OptionGroup::values('hrjob_leave_type', TRUE, FALSE);
     if (empty($options)) {
         $leaves = FALSE;
         $options = array('Sick' => 'Sick', 'Vacation' => 'Vacation', 'Maternity' => 'Maternity', 'Paternity' => 'Paternity', 'TOIL' => 'TOIL', 'Other' => 'Other');
     }
     $seperator = CRM_Core_DAO::VALUE_SEPARATOR;
     foreach ($options as $orgKey => $orgValue) {
         $params = array('title' => $orgValue, 'is_active' => 1, 'allow_debits' => 1);
         if ($orgKey == 'TOIL') {
             $params['allow_credits'] = 1;
         }
         $absenceTypes = CRM_HRAbsence_BAO_HRAbsenceType::create($params);
         $values .= " WHEN '{$orgValue}' THEN '{$absenceTypes->id}'";
         if ($absenceTypes->debit_activity_type_id) {
             $absenceTypeID[] = $absenceTypes->debit_activity_type_id;
             if ($orgKey == 'Sick') {
                 $sickTypeID = $absenceTypes->debit_activity_type_id;
             }
         }
         if ($absenceTypes->credit_activity_type_id) {
             $absenceTypeID[] = $absenceTypes->credit_activity_type_id;
             if ($orgKey == 'Sick') {
                 $sickTypeID = $absenceTypes->debit_activity_type_id;
             }
         }
     }
     if (CRM_Core_DAO::checkTableExists('civicrm_hrjobcontract_leave') && $leaves) {
         $query = "UPDATE civicrm_hrjobcontract_leave\n        SET leave_type = CASE leave_type\n        {$values}\n        END;";
         CRM_Core_DAO::executeQuery($query);
     }
     CRM_Core_OptionGroup::deleteAssoc('hrjob_leave_type');
     $absenceTypeIDs = implode($seperator, $absenceTypeID);
     $paramsCGroup = array('title' => 'Absence Comment', 'extends' => array('0' => 'Activity'), 'style' => 'Inline', 'extends_entity_column_value' => array('0' => $absenceTypeIDs), 'is_active' => 1);
     $customGroup = civicrm_api3('CustomGroup', 'get', array('sequential' => 1, 'title' => $paramsCGroup['title']));
     $resultCGroup = CRM_Utils_Array::first($customGroup['values']);
     if (empty($resultCGroup['id'])) {
         $resultCGroup = civicrm_api3('custom_group', 'create', $paramsCGroup);
     }
     $paramsCField = array('custom_group_id' => $resultCGroup['id'], 'label' => 'Comment', 'html_type' => 'TextArea', 'data_type' => 'Memo', 'is_active' => 1);
     $resultCField = civicrm_api3('custom_field', 'get', $paramsCField);
     if ($resultCField['count'] == 0) {
         $resultCField = civicrm_api3('custom_field', 'create', $paramsCField);
     }
     $paramsSGroup = array('title' => 'Type of Sickness', 'extends' => array('0' => 'Activity'), 'style' => 'Inline', 'extends_entity_column_value' => array('0' => $sickTypeID), 'is_active' => 1);
     $sickGroup = civicrm_api3('CustomGroup', 'get', array('sequential' => 1, 'title' => $paramsSGroup['title']));
     $resultSGroup = CRM_Utils_Array::first($sickGroup['values']);
     if (empty($resultSGroup['id'])) {
         $resultSGroup = civicrm_api3('custom_group', 'create', $paramsSGroup);
     }
     $paramsSField = array('custom_group_id' => $resultSGroup['id'], 'label' => 'Sick Type', 'html_type' => 'Select', 'data_type' => 'String', 'is_active' => 1);
     $resultSField = civicrm_api3('custom_field', 'get', $paramsSField);
     if ($resultSField['count'] == 0) {
         $resultSField = civicrm_api3('custom_field', 'create', $paramsSField);
     }
     $sickType = array('Cold', 'Cough', 'Fever');
     foreach ($sickType as $Key => $val) {
         $paramsOVal = array('sequential' => 1, 'name' => $val, 'option_group_id' => $resultSField['values'][$resultSField['id']]['option_group_id']);
         $optionValue = civicrm_api3('OptionValue', 'get', array('sequential' => 1, 'option_group_id' => $paramsOVal['option_group_id'], 'name' => $paramsOVal['name']));
         if ($optionValue['count'] == 0) {
             civicrm_api3('OptionValue', 'create', $paramsOVal);
         }
     }
 }