Esempio n. 1
0
 /**
  * Function to get mapping details
  * @return <Array> list of mapping details
  */
 public function getMapping()
 {
     $log = vglobal('log');
     $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__ . '() method ...');
     if (!$this->mapping) {
         $db = PearDatabase::getInstance();
         $query = 'SELECT * FROM ' . self::$mappingTable . ' WHERE ' . self::$mappingIndex . ' = ?;';
         $result = $db->pquery($query, [$this->getId()]);
         $mapping = $db->getArray($result);
         $finalMapping = [];
         if ($mapping) {
             foreach ($mapping as $mappingId => $mappingDetails) {
                 $finalMapping[$mappingId] = ['type' => $mappingDetails['type'], 'default' => $mappingDetails['default'], 'source' => Settings_MappedFields_Field_Model::getInstance($mappingDetails['source'], $this->getModule(), $mappingDetails['type']), 'target' => Settings_MappedFields_Field_Model::getInstance($mappingDetails['target'], $this->getRelatedModule(), $mappingDetails['type'])];
             }
         }
         $this->mapping = $finalMapping;
     }
     $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__ . ' method ...');
     return $this->mapping;
 }
Esempio n. 2
0
 public function import(Vtiger_Request $request)
 {
     $qualifiedModuleName = $request->getModule(false);
     $id = '';
     if (is_array($_FILES) && $_FILES['imported_xml']['name'] != '') {
         $xmlName = $_FILES['imported_xml']['name'];
         $uploadedXml = $_FILES['imported_xml']['tmp_name'];
         $xmlError = $_FILES['imported_xml']['error'];
         $extension = end(explode('.', $xmlName));
         $message = false;
         $moduleInstance = Settings_MappedFields_Module_Model::getCleanInstance();
         $mapping = [];
         $combine = ['tabid' => 'source', 'reltabid' => 'target'];
         if ($xmlError == UPLOAD_ERR_OK && $extension === 'xml') {
             $xml = simplexml_load_file($uploadedXml);
             $i = 0;
             $instances = [];
             foreach ($xml as $fieldsKey => $fieldsValue) {
                 if (array_key_exists($fieldsKey, $combine)) {
                     $value = (int) Vtiger_Functions::getModuleId((string) $fieldsValue);
                     if (empty($value)) {
                         break;
                     }
                     $instances[$combine[$fieldsKey]] = Vtiger_Module_Model::getInstance((string) $fieldsValue);
                 } elseif ($fieldsKey == 'fields') {
                     foreach ($fieldsValue as $fieldKey => $fieldValue) {
                         foreach ($fieldValue as $columnKey => $columnValue) {
                             settype($columnKey, 'string');
                             settype($columnValue, 'string');
                             if (in_array($columnKey, ['default', 'type'])) {
                                 $mapping[$i][$columnKey] = $columnValue;
                                 continue;
                             }
                             $fieldObject = Settings_MappedFields_Field_Model::getInstance($columnValue, $instances[$columnKey], $mapping[$i]['type']);
                             if (!$fieldObject) {
                                 continue;
                             }
                             $mapping[$i][$columnKey] = $fieldObject->getId();
                         }
                         $i++;
                     }
                     continue;
                 } else {
                     $value = (string) $fieldsValue;
                 }
                 $moduleInstance->getRecord()->set($fieldsKey, $value);
             }
             $tabid = $moduleInstance->getRecord()->get('tabid');
             $reltabid = $moduleInstance->getRecord()->get('reltabid');
             if (empty($tabid) || empty($reltabid)) {
                 $message = 'LBL_MODULE_NOT_EXIST';
             } elseif (!$moduleInstance->importsAllowed()) {
                 $moduleInstance->setMapping($mapping);
                 $moduleInstance->save(true);
                 $message = 'LBL_IMPORT_OK';
                 $id = $moduleInstance->getRecordId();
             } else {
                 $message = 'LBL_NO_PERMISSION_TO_IMPORT';
             }
         } else {
             $message = 'LBL_UPLOAD_ERROR';
         }
     }
     $response = new Vtiger_Response();
     $response->setResult(['id' => $id, 'message' => vtranslate($message, $qualifiedModuleName)]);
     $response->emit();
 }
Esempio n. 3
0
 /**
  * Function returns fields of module
  * @return <Array of Vtiger_Field>
  */
 public function getFields($source = false)
 {
     $log = vglobal('log');
     $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__ . '() method ...');
     $moduleModel = Vtiger_Module_Model::getInstance($this->getName());
     $moduleMeta = $moduleModel->getModuleMeta();
     $moduleFields = $moduleMeta->getAccessibleFields($this->getName());
     $fields = [];
     foreach ($moduleFields as $fieldName => $fieldInstance) {
         if ($moduleMeta->isEditableField($fieldInstance) && !in_array($fieldInstance->getUIType(), $this->getRestrictedUitypes())) {
             $blockName = $fieldInstance->getBlockName();
             if (!$blockName) {
                 $blockName = 'LBL_NOT_ASSIGNET_TO_BLOCK';
             }
             $fields[$blockName][$fieldInstance->getFieldId()] = Settings_MappedFields_Field_Model::getInstanceFromWebserviceFieldObject($fieldInstance);
         }
     }
     if ($source) {
         foreach ($this->getSpecialFields() as $fieldName => $fieldInstance) {
             $fields['LBL_NOT_ASSIGNET_TO_BLOCK'][$fieldName] = $fieldInstance;
         }
     }
     $isInventory = $moduleModel->isInventory();
     if ($isInventory) {
         $inventoryFieldModel = Vtiger_InventoryField_Model::getInstance($this->getName());
         $inventoryFields = $inventoryFieldModel->getFields();
         $blockName = 'LBL_ADVANCED_BLOCK';
         foreach ($inventoryFields as $field) {
             $fields[$blockName][$field->get('columnname')] = Settings_MappedFields_Field_Model::getInstanceFromInventoryFieldObject($field);
         }
     }
     $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__ . ' method ...');
     return $fields;
 }