public function translateReferenceFieldNamesToIds($entityRecords, $user)
 {
     $entityRecordList = array();
     foreach ($entityRecords as $index => $record) {
         $entityRecordList[$record['module']][$index] = $record;
     }
     foreach ($entityRecordList as $module => $records) {
         $handler = vtws_getModuleHandlerFromName($module, $user);
         $meta = $handler->getMeta();
         $referenceFieldDetails = $meta->getReferenceFieldDetails();
         foreach ($referenceFieldDetails as $referenceFieldName => $referenceModuleDetails) {
             $recordReferenceFieldNames = array();
             foreach ($records as $index => $recordDetails) {
                 if (!empty($recordDetails[$referenceFieldName])) {
                     $recordReferenceFieldNames[] = $recordDetails[$referenceFieldName];
                 }
             }
             $entityNameIds = wsapp_getRecordEntityNameIds(array_values($recordReferenceFieldNames), $referenceModuleDetails, $user);
             if (is_array($entityNameIds)) {
                 $entityNameIds = array_change_key_case($entityNameIds, CASE_LOWER);
             }
             foreach ($records as $index => $recordInfo) {
                 if (!empty($entityNameIds[strtolower($recordInfo[$referenceFieldName])])) {
                     $recordInfo[$referenceFieldName] = $entityNameIds[strtolower($recordInfo[$referenceFieldName])];
                 } else {
                     if ($referenceFieldName == 'account_id') {
                         if ($recordInfo[$referenceFieldName] != NULL) {
                             $element['accountname'] = $recordInfo[$referenceFieldName];
                             $element['assigned_user_id'] = vtws_getWebserviceEntityId('Users', $user->id);
                             $element['module'] = "Accounts";
                             $createRecord = array($element);
                             $createRecord = $this->fillNonExistingMandatoryPicklistValues($createRecord);
                             $createRecord = $this->fillMandatoryFields($createRecord, $user);
                             foreach ($createRecord as $key => $record) {
                                 vtws_create($record['module'], $record, $user);
                             }
                             $entityNameIds = wsapp_getRecordEntityNameIds(array_values($recordReferenceFieldNames), $referenceModuleDetails, $user);
                             $recordInfo[$referenceFieldName] = $entityNameIds[$recordInfo[$referenceFieldName]];
                         }
                     } else {
                         $recordInfo[$referenceFieldName] = "";
                     }
                 }
                 $records[$index] = $recordInfo;
             }
         }
         $entityRecordList[$module] = $records;
     }
     $crmRecords = array();
     foreach ($entityRecordList as $module => $entityRecords) {
         foreach ($entityRecords as $index => $record) {
             $crmRecords[$index] = $record;
         }
     }
     return $crmRecords;
 }
Beispiel #2
0
    public function translateReferenceFieldNamesToIds($entityRecords,$user){
        $entityRecordList = array();
        foreach($entityRecords as $index=>$record){
            $entityRecordList[$record['module']][$index] = $record;
        }
        foreach($entityRecordList as $module=>$records){
            $handler = vtws_getModuleHandlerFromName($module, $user);
            $meta = $handler->getMeta();
            $referenceFieldDetails = $meta->getReferenceFieldDetails();

            foreach($referenceFieldDetails as $referenceFieldName=>$referenceModuleDetails){
                $recordReferenceFieldNames = array();
                foreach($records as $index=>$recordDetails){
                    if(!empty($recordDetails[$referenceFieldName])) {
                    $recordReferenceFieldNames[$recordDetails['id']] = $recordDetails[$referenceFieldName];
                }
                }
                $entityNameIds = wsapp_getRecordEntityNameIds(array_values($recordReferenceFieldNames), $referenceModuleDetails, $user);
                foreach($records as $index=>$recordInfo){
                    if(!empty($entityNameIds[$recordInfo[$referenceFieldName]])){
                        $recordInfo[$referenceFieldName] = $entityNameIds[$recordInfo[$referenceFieldName]];
                    } else {
                        $recordInfo[$referenceFieldName] = "";
                    }
                    $records[$index] = $recordInfo;
                }
            }
            $entityRecordList[$module] = $records;
        }

        $crmRecords = array();
        foreach($entityRecordList as $module=>$entityRecords){
            foreach($entityRecords as $index=>$record){
                $crmRecords[$index] = $record;
            }
        }
        return $crmRecords;
    }