Pimcore\Model\Object\ClassDefinition\Data\Objectbricks::getFromWebserviceImport PHP Method

getFromWebserviceImport() public method

public getFromWebserviceImport ( mixed $data, null $relatedObject = null, mixed $params = [], null $idMapper = null ) : mixed
$data mixed
$relatedObject null
$params mixed
$idMapper null
return mixed
    public function getFromWebserviceImport($data, $relatedObject = null, $params = [], $idMapper = null)
    {
        $containerName = "\\Pimcore\\Model\\Object\\" . ucfirst($relatedObject->getClass()->getName()) . "\\" . ucfirst($this->getName());
        if (Tool::classExists($containerName)) {
            $container = new $containerName($relatedObject, $this->getName());
            if (is_array($data)) {
                foreach ($data as $collectionRaw) {
                    if ($collectionRaw instanceof \stdClass) {
                        $class = "\\Pimcore\\Model\\Webservice\\Data\\Object\\Element";
                        $collectionRaw = Tool\Cast::castToClass($class, $collectionRaw);
                    }
                    if ($collectionRaw != null) {
                        if (!$collectionRaw instanceof Webservice\Data\Object\Element) {
                            throw new \Exception("invalid data in objectbrick [" . $this->getName() . "]");
                        }
                        $brick = $collectionRaw->type;
                        $collectionData = [];
                        $collectionDef = Object\Objectbrick\Definition::getByKey($brick);
                        if (!$collectionDef) {
                            throw new \Exception("Unknown objectbrick in webservice import [" . $brick . "]");
                        }
                        foreach ($collectionDef->getFieldDefinitions() as $fd) {
                            foreach ($collectionRaw->value as $field) {
                                if ($field instanceof \stdClass) {
                                    $class = "\\Pimcore\\Model\\Webservice\\Data\\Object\\Element";
                                    $field = Tool\Cast::castToClass($class, $field);
                                }
                                if (!$field instanceof Webservice\Data\Object\Element) {
                                    throw new \Exception("invalid data in objectbricks [" . $this->getName() . "]");
                                } elseif ($field->name == $fd->getName()) {
                                    if ($field->type != $fd->getFieldType()) {
                                        throw new \Exception("Type mismatch for objectbricks field [" . $field->name . "]. Should be [" . $fd->getFieldType() . "] but is [" . $field->type . "]");
                                    }
                                    $collectionData[$fd->getName()] = $fd->getFromWebserviceImport($field->value, $relatedObject, $params, $idMapper);
                                    break;
                                }
                            }
                        }
                        $collectionClass = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brick);
                        $collection = new $collectionClass($relatedObject);
                        $collection->setValues($collectionData);
                        $collection->setFieldname($this->getName());
                        $setter = "set" . ucfirst($brick);
                        $container->{$setter}($collection);
                    }
                }
            }
            return $container;
        }
        return null;
    }