Esempio n. 1
0
 function process(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $records = $request->get('records');
     $template = $request->get('template');
     $targetModuleName = $request->get('target');
     $method = $request->get('method');
     $success = [];
     if (!empty($template)) {
         $templateRecord = Vtiger_MappedFields_Model::getInstanceById($template);
         foreach ($records as $recordId) {
             if ($templateRecord->checkFiltersForRecord(intval($recordId))) {
                 if ($method == 0) {
                     $recordModel = Vtiger_Record_Model::getCleanInstance($targetModuleName);
                     $parentRecordModel = Vtiger_Record_Model::getInstanceById($recordId);
                     $recordModel->setRecordFieldValues($parentRecordModel);
                     if ($this->checkMandatoryFields($recordModel)) {
                         continue;
                     }
                     // TODO Add saving fields that exist in  advanced module
                     $recordModel->save();
                     if (isRecordExists($recordModel->getId())) {
                         $success[] = $recordId;
                     }
                 } else {
                     $success[] = $recordId;
                 }
             }
         }
     }
     $output = ['all' => count($records), 'ok' => $success, 'fail' => array_diff($records, $success)];
     $response = new Vtiger_Response();
     $response->setResult($output);
     $response->emit();
 }
Esempio n. 2
0
 /**
  * Function to set record module field values
  * @param parent record model
  */
 function setRecordFieldValues($parentRecordModel)
 {
     $currentUser = Users_Record_Model::getCurrentUserModel();
     $mfInstance = Vtiger_MappedFields_Model::getInstanceByModules($parentRecordModel->getModule()->getId(), $this->getModule()->getId());
     if ($mfInstance) {
         $moduleFields = $this->getModule()->getFields();
         $fieldsList = array_keys($moduleFields);
         $parentFieldsList = array_keys($parentRecordModel->getModule()->getFields());
         $params = $mfInstance->get('params');
         if ($params['autofill']) {
             $commonFields = array_intersect($fieldsList, $parentFieldsList);
             foreach ($commonFields as $fieldName) {
                 if (getFieldVisibilityPermission($parentRecordModel->getModuleName(), $currentUser->getId(), $fieldName) == 0) {
                     $this->set($fieldName, $parentRecordModel->get($fieldName));
                 }
             }
         }
         if ($parentRecordModel->getModule()->isInventory() && $this->getModule()->isInventory()) {
             $sourceInv = $parentRecordModel->getInventoryData();
             $newInvData = [];
         }
         foreach ($mfInstance->getMapping() as $mapp) {
             // TODO Validation that specifies whether a value is included in the list of values for a given module field should be added
             if ($mapp['type'] == 'SELF' && is_object($mapp['target'])) {
                 $referenceList = $mapp['target']->getReferenceList();
                 if (in_array($parentRecordModel->getModuleName(), $referenceList)) {
                     $this->set($mapp['target']->getName(), $parentRecordModel->get($mapp['source']->getName()));
                 }
             } elseif ($mapp['type'] == 'INVENTORY' && is_array($sourceInv)) {
                 foreach ($sourceInv as $key => $base) {
                     $newInvData[$key][$mapp['target']->getName()] = $base[$mapp['source']->getName()];
                 }
             } elseif (is_object($mapp['target']) && is_object($mapp['source']) && getFieldVisibilityPermission($parentRecordModel->getModuleName(), $currentUser->getId(), $mapp['source']->getName()) == 0 && in_array($mapp['source']->getName(), $parentFieldsList)) {
                 $value = $parentRecordModel->get($mapp['source']->getName());
                 if (!$value) {
                     $value = $mapp['default'];
                 }
                 $this->set($mapp['target']->getName(), $value);
             }
         }
         if ($newInvData) {
             $this->inventoryData = $newInvData;
         }
     }
 }
Esempio n. 3
0
 public static function getInstanceById($recordId, $moduleName = 'Vtiger')
 {
     $log = vglobal('log');
     $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__ . '(' . $recordId . ',' . $moduleName . ') method ...');
     $instance = new self();
     $instance->record = Vtiger_MappedFields_Model::getInstanceById($recordId, $moduleName);
     $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__ . ' method ...');
     return $instance;
 }