/** * Import field from given array datas * * @param array $data The module datas to import * @param array $params The import parameters. * array( * create => false|true : create missing objects (default : true) * update => false|true : update existing objects (default : true) * files => false|true : use files from PATH_TMP_FS (default : true) * ) * @param CMS_language $cms_language The CMS_langage to use * @param array $idsRelation : Reference : The relations between import datas ids and real imported ids * @param string $infos : Reference : The import infos returned * @return boolean : true on success, false on failure * @access public */ function fromArray($data, $params, $cms_language, &$idsRelation, &$infos) { if (isset($data['labels'])) { $label = new CMS_object_i18nm($this->getValue("labelID")); $label->setValues($data['labels']); $label->writeToPersistence(); $this->setValue("labelID", $label->getID()); } if (isset($data['descriptions'])) { $description = new CMS_object_i18nm($this->getValue("descriptionID")); $description->setValues($data['descriptions']); $description->writeToPersistence(); $this->setValue("descriptionID", $description->getID()); } if (isset($data['type']) && $data['type']) { $type = !io::isPositiveInteger($data['type']) ? $data['type'] : (isset($data['multi']) && $data['multi'] ? 'multi|' . $data['type'] : $data['type']); if (!io::isPositiveInteger($data['type'])) { $type = $data['type']; } else { if (isset($idsRelation['objects'][$data['type']])) { $objectId = $idsRelation['objects'][$data['type']]; $type = isset($data['multi']) && $data['multi'] ? 'multi|' . $objectId : $objectId; } else { // Use UUID to look for the linked object if (isset($data['params']['linkedObjectUuid'])) { //$this->setValue("order", $data['params']['order']); $linkedObjectDef = CMS_poly_object_catalog::getDefinitionFromUuid($data['params']['linkedObjectUuid']); if ($linkedObjectDef) { $objectId = $linkedObjectDef->getID(); $type = isset($data['multi']) && $data['multi'] ? 'multi|' . $objectId : $objectId; } else { $type = 'Unknown imported type ' . $data['type']; } } else { $type = 'Unknown imported type ' . $data['type']; } } } $this->setValue("type", $type); } else { $infos .= 'Error : missing or invalid type for field importation ...' . "\n"; return false; } if (!$this->getID() && CMS_poly_object_catalog::fieldUuidExists($data['uuid'])) { //check imported uuid. If objects does not have an Id, the uuid must be unique or must be regenerated $uuid = io::uuid(); //store old uuid relation $idsRelation['fields-uuid'][$data['uuid']] = $uuid; $data['uuid'] = $uuid; } //set object uuid if not exists if (!$this->_objectFieldValues["uuid"]) { $this->_objectFieldValues["uuid"] = $data['uuid']; } //if current object id has changed from imported id, set relation if (isset($idsRelation['objects'][$data['objectID']]) && $idsRelation['objects'][$data['objectID']]) { $this->setValue("objectID", $idsRelation['objects'][$data['objectID']]); } else { $this->setValue("objectID", $data['objectID']); } if (isset($data['params']['order'])) { $this->setValue("order", $data['params']['order']); } if (isset($data['params']['required'])) { $this->setValue("required", $data['params']['required']); } if (isset($data['params']['indexable'])) { $this->setValue("indexable", $data['params']['indexable']); } if (isset($data['params']['searchlist'])) { $this->setValue("searchlist", $data['params']['searchlist']); } if (isset($data['params']['searchable'])) { $this->setValue("searchable", $data['params']['searchable']); } //parameters if (!io::isPositiveInteger($data['type']) || isset($data['multi']) && $data['multi']) { $fieldObject = $this->getTypeObject(); $GLOBALS['moduleCodename'] = $params['module']; if ($fieldObject && isset($data['params']['params']) && $data['params']['params']) { if (method_exists($fieldObject, 'treatParams')) { $params = $fieldObject->treatParams($data['params']['params'], ''); if ($params) { $this->setValue("params", $params); //set this object into definition to convert array so it can be converted again at end of import process $idsRelation['definitionToConvert'][] = $this; //store field to convert params at end of import if (method_exists($fieldObject, 'importParams')) { $idsRelation['paramsFieldsToConvert'][] = $this; } } else { $infos .= 'Error : missing or invalid parameters for field importation ...' . "\n"; return false; } } } } //write field if (!$this->writeToPersistence()) { $infos .= 'Error : can not write object field ...' . "\n"; return false; } //if current field id has changed from imported id, set relation if (isset($data['id']) && $data['id'] && $this->getID() != $data['id']) { $idsRelation['fields'][$data['id']] = $this->getID(); if (isset($data['uuid']) && $data['uuid']) { $idsRelation['fields'][$data['uuid']] = $this->getID(); } } return true; }