Exemplo n.º 1
0
 /**
  * Create a new HRJobDetails based on array-data
  *
  * @param array $params key-value pairs
  * @return CRM_HRJob_DAO_HRJobDetails|NULL
  *
  */
 public static function create($params)
 {
     $hook = empty($params['id']) ? 'create' : 'edit';
     $previousDetailsRevisionId = null;
     if ($hook == 'create') {
         $previousRevisionResult = civicrm_api3('HRJobContractRevision', 'getcurrentrevision', array('sequential' => 1, 'jobcontract_id' => $params['jobcontract_id']));
         if (!empty($previousRevisionResult['values']['details_revision_id'])) {
             $previousDetailsRevisionId = $previousRevisionResult['values']['details_revision_id'];
         }
     }
     $instance = parent::create($params);
     // setting 'effective_date' if it's not set:
     $revision = civicrm_api3('HRJobContractRevision', 'get', array('sequential' => 1, 'jobcontract_id' => $params['jobcontract_id'], 'id' => $instance->jobcontract_revision_id));
     if (!empty($revision['values'][0])) {
         $revisionData = array_shift($revision['values']);
         if (!$revisionData['effective_date']) {
             civicrm_api3('HRJobContractRevision', 'create', array('id' => $revisionData['id'], 'effective_date' => $instance->period_start_date));
         }
     }
     $revisionResult = civicrm_api3('HRJobContractRevision', 'get', array('sequential' => 1, 'id' => $instance->jobcontract_revision_id));
     $revision = CRM_Utils_Array::first($revisionResult['values']);
     $duplicate = CRM_Utils_Array::value('action', $params, $hook);
     if ($hook == 'create' && empty($revision['role_revision_id']) && $duplicate != 'duplicate' && empty($params['import'])) {
         //civicrm_api3('HRJobRole', 'create', array('jobcontract_id' => $revision['jobcontract_id'],'title' => $instance->title, 'location'=> $instance->location, 'percent_pay_role' => 100, 'jobcontract_revision_id' => $instance->jobcontract_revision_id));
         CRM_Hrjobcontract_BAO_HRJobRole::create(array('jobcontract_id' => $revision['jobcontract_id'], 'title' => $instance->title, 'location' => $instance->location, 'percent_pay_role' => 100, 'jobcontract_revision_id' => $instance->jobcontract_revision_id));
     }
     if ($previousDetailsRevisionId) {
         CRM_Core_BAO_File::copyEntityFile('civicrm_hrjobcontract_details', $previousDetailsRevisionId, 'civicrm_hrjobcontract_details', $revision['details_revision_id']);
     }
     $contract = new CRM_Hrjobcontract_DAO_HRJobContract();
     $contract->id = $revision['jobcontract_id'];
     $contract->find(true);
     CRM_Hrjobcontract_JobContractDates::setDates($contract->contact_id, $revision['jobcontract_id'], $instance->period_start_date, $instance->period_end_date);
     return $instance;
 }
Exemplo n.º 2
0
 function upgrade_1002()
 {
     // Fill JobContract Dates custom fields with start and end dates of contracts
     $jobContracts = CRM_Core_DAO::executeQuery('SELECT id, contact_id FROM civicrm_hrjobcontract ORDER BY id ASC');
     $today = date('Y-m-d');
     while ($jobContracts->fetch()) {
         $revision = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_hrjobcontract_revision ' . 'WHERE jobcontract_id = %1 ' . 'AND effective_date <= %2 ' . 'AND deleted = 0 ' . 'ORDER BY effective_date DESC LIMIT 1', array(1 => array($jobContracts->id, 'Integer'), 2 => array($today, 'String')));
         if (!$revision->fetch()) {
             $revision = CRM_Core_DAO::executeQuery('SELECT details_revision_id FROM civicrm_hrjobcontract_revision ' . 'WHERE jobcontract_id = %1 ' . 'AND deleted = 0 ' . 'ORDER BY effective_date ASC, id DESC LIMIT 1', array(1 => array($jobContracts->id, 'Integer')));
             $revision->fetch();
         }
         if (!$revision->details_revision_id) {
             continue;
         }
         $details = CRM_Core_DAO::executeQuery('SELECT period_start_date, period_end_date FROM civicrm_hrjobcontract_details ' . 'WHERE jobcontract_revision_id = %1 ' . 'LIMIT 1', array(1 => array($revision->details_revision_id, 'Integer')));
         if ($details->fetch()) {
             CRM_Hrjobcontract_JobContractDates::setDates($jobContracts->contact_id, $jobContracts->id, $details->period_start_date, $details->period_end_date);
         }
     }
     return TRUE;
 }