/**
  * singleton function used to manage this object
  *
  * @return CRM_Appraisals_ExportImportValuesConverter
  * @static
  */
 static function &singleton()
 {
     if (self::$_singleton === NULL) {
         self::$_singleton = new self();
     }
     return self::$_singleton;
 }
예제 #2
0
파일: Api.php 프로젝트: JoeMurray/civihr
 /**
  * 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)
 {
     $ei = CRM_Appraisals_ExportImportValuesConverter::singleton();
     $response = $this->summary($values);
     $this->formatDateParams();
     $this->_params['skipRecentView'] = TRUE;
     $this->_params['check_permissions'] = TRUE;
     $params = $this->getActiveFieldParams();
     $rowParams = array();
     $formatValues = array();
     foreach ($params as $key => $field) {
         if ($field == NULL || $field === '') {
             continue;
         }
         $formatValues[$key] = $field;
     }
     $importedAppraisalCycleId = null;
     if (!empty($params['appraisal_cycle_id'])) {
         $importedAppraisalCycleId = (int) $params['appraisal_cycle_id'];
     }
     if (!$importedAppraisalCycleId) {
         $importedAppraisalCycleId = $this->_appraisalCycleIdIncremental++;
     }
     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']) && (int) $params['status_id']) {
         $error = 'Missing "contact_id" / "email" / "external_identifier" value.';
         array_unshift($values, $error);
         return CRM_Import_Parser::ERROR;
     }
     foreach ($this->_entity as $tableName => $entity) {
         $rowParams[$entity] = $this->getEntityParams($entity);
         if ($entity === 'AppraisalCycle' && $importedAppraisalCycleId) {
             $rowParams[$entity]['id'] = $importedAppraisalCycleId;
         }
         foreach ($rowParams[$entity] as $key => $value) {
             $rowParams[$entity][$key] = $ei->import($tableName, $key, $value);
         }
     }
     if (empty($this->_appraisalCycleIds[$importedAppraisalCycleId])) {
         try {
             unset($rowParams['AppraisalCycle']['id']);
             $appraisalCycleCreateResponse = civicrm_api3('AppraisalCycle', 'create', $rowParams['AppraisalCycle']);
         } catch (CiviCRM_API3_Exception $e) {
             $error = $e->getMessage();
             array_unshift($values, $error);
             return CRM_Import_Parser::ERROR;
         }
         $this->_appraisalCycleIds[$importedAppraisalCycleId] = (int) $appraisalCycleCreateResponse['id'];
     }
     $localAppraisalCycleId = $this->_appraisalCycleIds[$importedAppraisalCycleId];
     if (!empty($params['contact_id']) && (int) $params['contact_id']) {
         try {
             unset($rowParams['Appraisal']['id']);
             unset($rowParams['Appraisal']['external_identifier']);
             unset($rowParams['Appraisal']['email']);
             $rowParams['Appraisal']['appraisal_cycle_id'] = $localAppraisalCycleId;
             civicrm_api3('Appraisal', 'create', $rowParams['Appraisal']);
         } catch (CiviCRM_API3_Exception $e) {
             $error = $e->getMessage();
             array_unshift($values, $error);
             return CRM_Import_Parser::ERROR;
         }
     }
 }
예제 #3
0
파일: Report.php 프로젝트: JoeMurray/civihr
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $entryFound = FALSE;
     $checkList = array();
     $convertTables = array('civicrm_appraisal_cycle', 'civicrm_appraisal');
     $ei = CRM_Appraisals_ExportImportValuesConverter::singleton();
     foreach ($rows as $rowNum => $row) {
         if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') {
             // not repeat contact display names if it matches with the one
             // in previous row
             $repeatFound = FALSE;
             foreach ($row as $colName => $colVal) {
                 if (CRM_Utils_Array::value($colName, $checkList) && is_array($checkList[$colName]) && in_array($colVal, $checkList[$colName])) {
                     $rows[$rowNum][$colName] = "";
                     $repeatFound = TRUE;
                 }
                 if (in_array($colName, $this->_noRepeats)) {
                     $checkList[$colName][] = $colVal;
                 }
             }
         }
         if (array_key_exists('civicrm_membership_membership_type_id', $row)) {
             if ($value = $row['civicrm_membership_membership_type_id']) {
                 $rows[$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant::membershipType($value, FALSE);
             }
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_address_state_province_id', $row)) {
             if ($value = $row['civicrm_address_state_province_id']) {
                 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
             }
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_address_country_id', $row)) {
             if ($value = $row['civicrm_address_country_id']) {
                 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE);
             }
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_contact_sort_name', $row) && $rows[$rowNum]['civicrm_contact_sort_name'] && array_key_exists('civicrm_contact_id', $row)) {
             $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
             $entryFound = TRUE;
         }
         if (!$entryFound) {
             //break;
         }
         // Convert values for export
         foreach ($convertTables as $tableName) {
             $fields = $this->_columns[$tableName]['fields'];
             //TODO: remove: var_dump($fields);
             foreach ($fields as $key => $value) {
                 $rowKey = $tableName . '_' . $key;
                 if (isset($row[$rowKey])) {
                     $rows[$rowNum][$rowKey] = $ei->export($tableName, $key, $row[$rowKey]);
                 }
             }
         }
         //TODO: remove: die;
     }
 }