public function put($recordDetails, $user)
 {
     $this->user = $user;
     $recordDetails = $this->syncToNativeFormat($recordDetails);
     $createdRecords = $recordDetails['created'];
     $updatedRecords = $recordDetails['updated'];
     $deletedRecords = $recordDetails['deleted'];
     if (count($createdRecords) > 0) {
         $createdRecords = $this->translateReferenceFieldNamesToIds($createdRecords, $user);
         $createdRecords = $this->fillNonExistingMandatoryPicklistValues($createdRecords);
     }
     foreach ($createdRecords as $index => $record) {
         $createdRecords[$index] = vtws_create($record['module'], $record, $this->user);
     }
     if (count($updatedRecords) > 0) {
         $updatedRecords = $this->translateReferenceFieldNamesToIds($updatedRecords, $user);
     }
     $crmIds = array();
     foreach ($updatedRecords as $index => $record) {
         $webserviceRecordId = $record["id"];
         $recordIdComp = vtws_getIdComponents($webserviceRecordId);
         $crmIds[] = $recordIdComp[1];
     }
     $assignedRecordIds = wsapp_checkIfRecordsAssignToUser($crmIds, $this->user->id);
     foreach ($updatedRecords as $index => $record) {
         $webserviceRecordId = $record["id"];
         $recordIdComp = vtws_getIdComponents($webserviceRecordId);
         if (in_array($recordIdComp[1], $assignedRecordIds)) {
             $updatedRecords[$index] = vtws_revise($record, $this->user);
         } else {
             $this->assignToChangedRecords[$index] = $record;
         }
     }
     $hasDeleteAccess = null;
     $deletedCrmIds = array();
     foreach ($deletedRecords as $index => $record) {
         $webserviceRecordId = $record;
         $recordIdComp = vtws_getIdComponents($webserviceRecordId);
         $deletedCrmIds[] = $recordIdComp[1];
     }
     $assignedDeletedRecordIds = wsapp_checkIfRecordsAssignToUser($deletedCrmIds, $this->user->id);
     foreach ($deletedRecords as $index => $record) {
         $idComp = vtws_getIdComponents($record);
         if (empty($hasDeleteAccess)) {
             $handler = vtws_getModuleHandlerFromId($idComp[0], $this->user);
             $meta = $handler->getMeta();
             $hasDeleteAccess = $meta->hasDeleteAccess();
         }
         if ($hasDeleteAccess) {
             if (in_array($idComp[1], $assignedDeletedRecordIds)) {
                 vtws_delete($record, $this->user);
             }
         }
     }
     $recordDetails['created'] = $createdRecords;
     $recordDetails['updated'] = $updatedRecords;
     $recordDetails['deleted'] = $deletedRecords;
     return $this->nativeToSyncFormat($recordDetails);
 }
 public function put($recordDetails, $user)
 {
     $log = vglobal('log');
     $this->user = $user;
     $recordDetails = $this->syncToNativeFormat($recordDetails);
     $createdRecords = $recordDetails['created'];
     $updatedRecords = $recordDetails['updated'];
     $deletedRecords = $recordDetails['deleted'];
     if (count($createdRecords) > 0) {
         $createdRecords = $this->translateReferenceFieldNamesToIds($createdRecords, $user);
         $createdRecords = $this->fillNonExistingMandatoryPicklistValues($createdRecords);
         $createdRecords = $this->fillMandatoryFields($createdRecords, $user);
     }
     foreach ($createdRecords as $index => $record) {
         $createdRecords[$index] = vtws_create($record['module'], $record, $this->user);
     }
     if (count($updatedRecords) > 0) {
         $updatedRecords = $this->translateReferenceFieldNamesToIds($updatedRecords, $user);
     }
     $crmIds = array();
     foreach ($updatedRecords as $index => $record) {
         $webserviceRecordId = $record["id"];
         $recordIdComp = vtws_getIdComponents($webserviceRecordId);
         $crmIds[] = $recordIdComp[1];
     }
     $assignedRecordIds = array();
     if ($this->isClientUserSyncType()) {
         $assignedRecordIds = wsapp_checkIfRecordsAssignToUser($crmIds, $this->user->id);
         // To check if the record assigned to group
         if ($this->isClientUserAndGroupSyncType()) {
             $getUserGroups = new GetUserGroups();
             $getUserGroups->getAllUserGroups($this->user->id);
             $groupIds = $getUserGroups->user_groups;
             if (!empty($groupIds)) {
                 $groupRecordId = wsapp_checkIfRecordsAssignToUser($crmIds, $groupIds);
                 $assignedRecordIds = array_merge($assignedRecordIds, $groupRecordId);
             }
         }
         // End
     }
     foreach ($updatedRecords as $index => $record) {
         $webserviceRecordId = $record["id"];
         $recordIdComp = vtws_getIdComponents($webserviceRecordId);
         try {
             if (in_array($recordIdComp[1], $assignedRecordIds)) {
                 $updatedRecords[$index] = vtws_revise($record, $this->user);
             } else {
                 if (!$this->isClientUserSyncType()) {
                     $updatedRecords[$index] = vtws_revise($record, $this->user);
                 } else {
                     $this->assignToChangedRecords[$index] = $record;
                 }
             }
         } catch (Exception $e) {
             continue;
         }
         // Added to handle duplication
         if ($record['duplicate']) {
             $updatedRecords[$index]['duplicate'] = true;
         }
         // End
     }
     $hasDeleteAccess = null;
     $deletedCrmIds = array();
     foreach ($deletedRecords as $index => $record) {
         $webserviceRecordId = $record;
         $recordIdComp = vtws_getIdComponents($webserviceRecordId);
         $deletedCrmIds[] = $recordIdComp[1];
     }
     $assignedDeletedRecordIds = wsapp_checkIfRecordsAssignToUser($deletedCrmIds, $this->user->id);
     // To get record id's assigned to group of the current user
     if ($this->isClientUserAndGroupSyncType()) {
         if (!empty($groupIds)) {
             foreach ($groupIds as $group) {
                 $groupRecordId = wsapp_checkIfRecordsAssignToUser($deletedCrmIds, $group);
                 $assignedDeletedRecordIds = array_merge($assignedDeletedRecordIds, $groupRecordId);
             }
         }
     }
     // End
     foreach ($deletedRecords as $index => $record) {
         $idComp = vtws_getIdComponents($record);
         if (empty($hasDeleteAccess)) {
             $handler = vtws_getModuleHandlerFromId($idComp[0], $this->user);
             $meta = $handler->getMeta();
             $hasDeleteAccess = $meta->hasDeleteAccess();
         }
         if ($hasDeleteAccess) {
             if (in_array($idComp[1], $assignedDeletedRecordIds)) {
                 try {
                     vtws_delete($record, $this->user);
                 } catch (Exception $e) {
                     continue;
                 }
             }
         }
     }
     $recordDetails['created'] = $createdRecords;
     $recordDetails['updated'] = $updatedRecords;
     $recordDetails['deleted'] = $deletedRecords;
     return $this->nativeToSyncFormat($recordDetails);
 }