Esempio n. 1
0
/**
 * HRJobPension.get API
 *
 * @param array $params
 * @return array API result descriptor
 * @throws API_Exception
 */
function civicrm_api3_h_r_job_pension_get($params)
{
    _civicrm_hrjobcontract_api3_set_current_revision($params, _civicrm_get_table_name(_civicrm_api3_get_BAO(__FUNCTION__)));
    return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
Esempio n. 2
0
/**
 * HRJobContract implementation of the "delete" contract action.
 *
 * Deletes whole contract with its all revisions and entities.
 *
 * @param string $entity entity name
 * @param array $params params from civicrm_api, including 'jobcontract_id'
 * @return array|int
 */
function _civicrm_hrjobcontract_api3_deletecontractpermanently($params)
{
    $entityNames = array('HRJobDetails', 'HRJobHealth', 'HRJobHour', 'HRJobLeave', 'HRJobPay', 'HRJobPension', 'HRJobRole');
    $transaction = new CRM_Core_Transaction();
    try {
        if (empty($params['id'])) {
            throw new Exception("Cannot permanently delete Job Contract: please specify id value.");
        }
        $contract = civicrm_api('HRJobContract', 'get', $params);
        if (empty($contract['id'])) {
            throw new Exception("Cannot find Job Contract with given id (" . $params['id'] . ").");
        }
        $revisions = civicrm_api('HRJobContractRevision', 'get', array('sequential' => 1, 'options' => array('limit' => 0), 'version' => 3, 'jobcontract_id' => $params['id']));
        foreach ($revisions['values'] as $revision) {
            foreach ($entityNames as $entityName) {
                $tableName = _civicrm_get_table_name($entityName);
                $entities = civicrm_api3($entityName, 'get', array('sequential' => 1, 'options' => array('limit' => 0), 'version' => 3, 'jobcontract_revision_id' => (int) $revision[$tableName . '_revision_id']));
                if (!empty($entities['values'])) {
                    foreach ($entities['values'] as $entity) {
                        civicrm_api3($entityName, 'delete', array('version' => 3, 'id' => $entity['id']));
                    }
                }
            }
            civicrm_api3('HRJobContractRevision', 'delete', array('version' => 3, 'id' => $revision['id']));
        }
        civicrm_api3('HRJobContract', 'delete', array('version' => 3, 'id' => $contract['id']));
        return 1;
    } catch (PEAR_Exception $e) {
        $transaction->rollback();
        return civicrm_api3_create_error($e->getMessage());
    } catch (Exception $e) {
        $transaction->rollback();
        return civicrm_api3_create_error($e->getMessage());
    }
}
Esempio n. 3
0
 /**
  * handle the values in import mode
  *
  * @param int $onDuplicate the code for what action to take on duplicates
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function import($onDuplicate, &$values)
 {
     $entityNames = array('details', 'hour', 'health', 'leave', 'pay', 'pension', 'role');
     $ei = CRM_Hrjobcontract_ExportImportValuesConverter::singleton();
     $response = $this->summary($values);
     $this->formatDateParams();
     $this->_params['skipRecentView'] = TRUE;
     $this->_params['check_permissions'] = TRUE;
     $params = $this->getActiveFieldParams();
     $formatValues = array();
     foreach ($params as $key => $field) {
         if ($field == NULL || $field === '') {
             continue;
         }
         $formatValues[$key] = $field;
     }
     $importedJobContractId = null;
     if (!empty($params['jobcontract_id'])) {
         $importedJobContractId = (int) $params['jobcontract_id'];
     }
     if (!$importedJobContractId) {
         $importedJobContractId = $this->_jobcontractIdIncremental++;
     }
     if (empty($params['contact_id']) && !empty($params['email'])) {
         $checkEmail = new CRM_Core_BAO_Email();
         $checkEmail->email = $params['email'];
         $checkEmail->find(TRUE);
         if (!empty($checkEmail->contact_id)) {
             $params['contact_id'] = $checkEmail->contact_id;
         }
     }
     if (!empty($formatValues['external_identifier'])) {
         $checkCid = new CRM_Contact_DAO_Contact();
         $checkCid->external_identifier = $formatValues['external_identifier'];
         $checkCid->find(TRUE);
         if (!empty($params['contact_id']) && $params['contact_id'] != $checkCid->id) {
             array_unshift($values, 'Mismatch of External identifier :' . $formatValues['external_identifier'] . ' and Contact Id:' . $params['contact_id']);
             return CRM_Import_Parser::ERROR;
         }
         if (!empty($checkCid->id)) {
             $params['contact_id'] = $checkCid->id;
         }
     }
     if (empty($params['contact_id'])) {
         $error = 'Missing "contact_id" / "email" / "external_identifier" value.';
         array_unshift($values, $error);
         return CRM_Import_Parser::ERROR;
     }
     $revisionParams = $this->getEntityParams('HRJobContractRevision');
     $revisionData = array();
     foreach ($entityNames as $value) {
         if (empty($revisionParams[$value . '_revision_id'])) {
             $revisionParams[$value . '_revision_id'] = $this->_revisionIdIncremental;
         }
         $revisionData[$value] = $revisionParams[$value . '_revision_id'];
     }
     $this->_revisionIdIncremental++;
     if (empty($revisionData)) {
         $error = 'Missing Revision data.';
         array_unshift($values, $error);
         return CRM_Import_Parser::ERROR;
     }
     $revisionId = max($revisionData);
     if (empty($this->_jobContractIds[$importedJobContractId])) {
         try {
             $jobContractCreateResponse = civicrm_api3('HRJobContract', 'create', array('contact_id' => $params['contact_id']));
         } catch (CiviCRM_API3_Exception $e) {
             $error = $e->getMessage();
             array_unshift($values, $error);
             return CRM_Import_Parser::ERROR;
         }
         $this->_jobContractIds[$importedJobContractId] = (int) $jobContractCreateResponse['id'];
         $this->_previousRevision = array();
         foreach ($entityNames as $value) {
             $this->_previousRevision['imported'][$value] = null;
             $this->_previousRevision['local'][$value] = null;
         }
         $this->_previousRevision['imported']['id'] = null;
         $this->_previousRevision['local']['id'] = null;
         $this->_revisionIds = array();
         $this->_revisionEntityMap = array();
     }
     $localJobContractId = $this->_jobContractIds[$importedJobContractId];
     $newRevisionInstance = null;
     if ($this->_previousRevision['imported']['id'] !== $revisionId) {
         // create new Revision:
         $newRevisionParams = $revisionParams;
         unset($newRevisionParams['id']);
         foreach ($entityNames as $value) {
             unset($newRevisionParams[$value . '_revision_id']);
         }
         $newRevisionParams['jobcontract_id'] = $localJobContractId;
         $newRevisionParams = $this->validateFields('HRJobContractRevision', $newRevisionParams);
         $newRevisionInstance = CRM_Hrjobcontract_BAO_HRJobContractRevision::create($newRevisionParams);
         if (!empty($this->_previousRevision['imported']['id'])) {
             foreach ($entityNames as $value) {
                 $field = $value . '_revision_id';
                 $newRevisionInstance->{$field} = $this->_previousRevision['local'][$value];
             }
             $newRevisionInstance->save();
         }
     }
     try {
         foreach ($this->_entity as $entity) {
             if (in_array($entity, array('HRJobContract', 'HRJobContractRevision'))) {
                 continue;
             }
             $entityClass = 'CRM_Hrjobcontract_BAO_' . $entity;
             $tableName = _civicrm_get_table_name($entity);
             if (empty($revisionParams[$tableName . '_revision_id'])) {
                 continue;
             }
             $params = $this->getEntityParams($entity);
             $params['jobcontract_id'] = $localJobContractId;
             foreach ($params as $key => $value) {
                 $params[$key] = $ei->import($tableName, $key, $value);
             }
             $params = $this->validateFields($entity, $params);
             $params['import'] = 1;
             if ($revisionParams[$tableName . '_revision_id'] === $revisionId) {
                 if ($tableName === 'leave' || $this->_previousRevision['imported'][$tableName] !== $revisionId) {
                     if (!empty($newRevisionInstance)) {
                         $params['jobcontract_revision_id'] = $newRevisionInstance->id;
                     } else {
                         $params['jobcontract_revision_id'] = $this->_previousRevision['local'][$tableName];
                     }
                     if ($tableName === 'leave') {
                         foreach ($params['leave_amount'] as $leaveTypeId => $leaveAmount) {
                             $params['leave_type'] = $leaveTypeId;
                             $params['leave_amount'] = $leaveAmount;
                             $entityInstance = $entityClass::create($params);
                         }
                     } else {
                         $entityInstance = $entityClass::create($params);
                     }
                     $this->_previousRevision['local'][$tableName] = $entityInstance->jobcontract_revision_id;
                 }
             }
             $this->_previousRevision['imported'][$tableName] = $revisionParams[$tableName . '_revision_id'];
         }
     } catch (CiviCRM_API3_Exception $e) {
         $error = $e->getMessage();
         array_unshift($values, $error);
         return CRM_Import_Parser::ERROR;
     }
     if (!empty($newRevisionInstance)) {
         foreach ($entityNames as $value) {
             $field = $value . '_revision_id';
             $newRevisionInstance->{$field} = $this->_previousRevision['local'][$value];
         }
         $newRevisionInstance->save();
     }
     $this->_previousRevision['imported']['id'] = $revisionId;
 }
Esempio n. 4
0
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $entryFound = FALSE;
     $entities = array('HRJobContract', 'HRJobDetails', 'HRJobHour', 'HRJobHealth', 'HRJobLeave', 'HRJobPay', 'HRJobPension', 'HRJobRole');
     $ei = CRM_Hrjobcontract_ExportImportValuesConverter::singleton();
     $changeReasonOptions = array();
     CRM_Core_OptionGroup::getAssoc('hrjc_revision_change_reason', $changeReasonOptions);
     foreach ($rows as $rowNum => $row) {
         // make count columns point to detail report
         // convert sort name to links
         if (!empty($row['civicrm_contact_sort_name']) && !empty($row['civicrm_hrjobcontract_contact_id'])) {
             $url = CRM_Report_Utils_Report::getNextUrl('contact/detail', 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_hrjobcontract_contact_id'], $this->_absoluteUrl, $this->_id, $this->_drilldownReport);
             $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Constituent Detail Report for this contact.");
             $entryFound = TRUE;
         }
         // Convert revisionable HRJobContract Entities values for export
         foreach ($entities as $entity) {
             $tableName = _civicrm_get_table_name($entity);
             $fields = $this->_columns['civicrm_hrjobcontract_' . $tableName]['fields'];
             foreach ($fields as $key => $value) {
                 $fieldName = substr($key, strlen($tableName) + 1);
                 $rowKey = 'civicrm_hrjobcontract_' . $tableName . '_' . $tableName . '_' . $fieldName;
                 if (isset($row[$rowKey])) {
                     $rows[$rowNum][$rowKey] = $ei->export($tableName, $fieldName, $row[$rowKey]);
                 }
             }
         }
         // Convert non-revisionable HRJobContract Entities values for export
         if (!empty($row['civicrm_hrjobcontract_revision_change_reason'])) {
             $rows[$rowNum]['civicrm_hrjobcontract_revision_change_reason'] = $changeReasonOptions['label'][$rows[$rowNum]['civicrm_hrjobcontract_revision_change_reason']];
             $entryFound = TRUE;
         }
     }
 }
Esempio n. 5
0
 public static function create($params)
 {
     $className = get_called_class();
     $entityName = _civicrm_get_entity_name($className);
     $baoName = 'CRM_Hrjobcontract_BAO_' . $entityName;
     $daoName = 'CRM_Hrjobcontract_DAO_' . $entityName;
     $tableName = _civicrm_get_table_name($className);
     $hook = empty($params['id']) ? 'create' : 'edit';
     if ($hook === 'create') {
         if (empty($params['jobcontract_id'])) {
             throw new API_Exception("Cannot create entity: please specify jobcontract_id value.");
         }
         $jobContractId = (int) $params['jobcontract_id'];
         $previousEntityParams = array('jobcontract_id' => $jobContractId, 'sequential' => 1);
         _civicrm_hrjobcontract_api3_set_current_revision($previousEntityParams, $tableName);
         $previousEntityResult = civicrm_api3($entityName, 'get', $previousEntityParams);
         $previousEntity = CRM_Utils_Array::first($previousEntityResult['values']);
         if (!empty($previousEntity)) {
             $classInstance = new $daoName();
             $previousInstance = $classInstance->create($previousEntity);
             /*$previousInstance = new $baoName();
               if (!empty($previousEntity))
               {
                   $previousInstance->id = $previousEntity['id'];
                   $previousInstance->find(true);
               }*/
         }
         if (empty($params['jobcontract_revision_id'])) {
             // Creating new revision:
             $newRevision = _civicrm_hrjobcontract_api3_create_revision($jobContractId);
             $params['jobcontract_revision_id'] = $newRevision['id'];
             // Updating currently saved revision with its 'id' as {table}_revision_id:
             $updatedRevision = civicrm_api3('HRJobContractRevision', 'create', array('sequential' => 1, 'id' => $newRevision['id'], $tableName . '_revision_id' => $newRevision['id']));
         } else {
             $updatedRevision = civicrm_api3('HRJobContractRevision', 'create', array('sequential' => 1, 'id' => $params['jobcontract_revision_id'], $tableName . '_revision_id' => $params['jobcontract_revision_id']));
         }
         if (!empty($previousEntity)) {
             unset($previousEntity['id']);
             unset($previousEntity['jobcontract_revision_id']);
             $previousEntityData = array();
             foreach ($previousEntity as $key => $value) {
                 $previousEntityData[$key] = $previousInstance->{$key};
             }
             $params = array_merge($previousEntityData, $params);
         }
     }
     foreach ($params as $key => $value) {
         if (is_array($value)) {
             $params[$key] = json_encode($value);
         }
     }
     CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
     $instance = new $className();
     if (!empty($params['id'])) {
         $instance->id = $params['id'];
         $instance->find(true);
     }
     $instance->copyValues($params);
     if (module_exists('rules')) {
         rules_invoke_event('hrjobcontract_' . $tableName . '_presave', $instance);
     }
     $instance->save();
     CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
     if (module_exists('rules')) {
         if ($hook == 'create') {
             rules_invoke_event('hrjobcontract_' . $tableName . '_insert', $instance);
         } else {
             rules_invoke_event('hrjobcontract_' . $tableName . '_update', $instance);
         }
     }
     return $instance;
 }