Deserializes resource node data into entities.

@param array        $data
@param ResourceNode $resourceNode
196517
public function deserialize(array $data, ResourceNode $resourceNode, array $options = [])
    {
        $this->sipe('name', 'setName', $data, $resourceNode);

        if (!in_array(Options::REFRESH_UUID, $options)) {
            $this->sipe('id', 'setUuid', $data, $resourceNode);
        }

        if (isset($data['meta']['workspace'])) {
            /** @var Workspace $workspace */
            $workspace = $this->om->getRepository(Workspace::class)->findOneBy(['uuid' => $data['meta']['workspace']['uuid']]);
            $resourceNode->setWorkspace($workspace);
        }

        if (isset($data['poster']) && isset($data['poster']['url'])) {
            $resourceNode->setPoster($data['poster']['url']);
        }

        if (isset($data['thumbnail']) && isset($data['thumbnail']['url'])) {
            $resourceNode->setThumbnail($data['thumbnail']['url']);
        }

        // meta
        if (empty($resourceNode->getResourceType())) {
            /** @var ResourceType $resourceType */
            $resourceType = $this->om
                ->getRepository('ClarolineCoreBundle:Resource\ResourceType')
                ->findOneBy(['name' => $data['meta']['type']]);

            $resourceNode->setResourceType($resourceType);
        }

        if (empty($resourceNode->getMimeType())) {
            if (isset($data['meta']) && !empty($data['meta']['mimeType'])) {
                $mimeType = $data['meta']['mimeType'];
            } else {
                $mimeType = 'custom/'.$resourceNode->getResourceType()->getName();
            }

            $resourceNode->setMimeType($mimeType);
        }

        if (isset($data['rights'])) {
            $this->deserializeRights($data['rights'], $resourceNode, $options);
        }

        $this->sipe('meta.published', 'setPublished', $data, $resourceNode);
        $this->sipe('meta.description', 'setDescription', $data, $resourceNode);
        $this->sipe('meta.license', 'setLicense', $data, $resourceNode);
        $this->sipe('meta.authors', 'setAuthor', $data, $resourceNode);
        $this->sipe('meta.commentsActivated', 'setCommentsActivated', $data, $resourceNode);

        // display
        $this->sipe('display.fullscreen', 'setFullscreen', $data, $resourceNode);
        $this->sipe('display.showIcon', 'setShowIcon', $data, $resourceNode);
        $this->sipe('display.closable', 'setClosable', $data, $resourceNode);
        $this->sipe('display.closeTarget', 'setCloseTarget', $data, $resourceNode);

        // restrictions
        $this->sipe('restrictions.code', 'setAccessCode', $data, $resourceNode);
        $this->sipe('restrictions.allowedIps', 'setAllowedIps', $data, $resourceNode);
        $this->sipe('restrictions.hidden', 'setHidden', $data, $resourceNode);

        if (isset($data['restrictions']['dates'])) {
            $dateRange = DateRangeNormalizer::denormalize($data['restrictions']['dates']);

            $resourceNode->setAccessibleFrom($dateRange[0]);
            $resourceNode->setAccessibleUntil($dateRange[1]);
        }
    }
62027
public function collection($resourceKey, array $data)
    {
        $resources = [];

        foreach ($data as $resource) {
            $resources[] = $this->item($resourceKey, $resource)['data'];
        }

        return ['data' => $resources];
    }
432741
public function collection($resourceKey, array $data, $includeAttributes = true)
    {
        $resources = [];

        foreach ($data as $resource) {

            /**
             * Add option to override resource key with data.
             */
            if (is_array($resource) && array_key_exists('_resource_key', $resource)) {
                $resourceKey = $resource['_resource_key'];
                unset($resource['_resource_key']);
            }

            $resources[] = $this->item($resourceKey, $resource, $includeAttributes)['data'];
        }

        return ['data' => $resources];
    }
1038122
public function unserialize($data)
    {
        if (!is_string($data)) {
            throw new \common_exception_InconsistentData('The encoded resource metadata should be provided as a string');
        }

        $metaData = json_decode($data, true);

        if (!is_array($metaData)) {
            throw new \common_exception_InconsistentData('The decoded resource metadata should be an array');
        }
        $this->metaData = $metaData;

        return $this->metaData;
    }
1139105
public function serialize(DAV\Server $server, \DOMElement $errorNode)
    {
        if ($this->header) {
            $prop = $errorNode->ownerDocument->createElement('s:header');
            $prop->nodeValue = $this->header;
            $errorNode->appendChild($prop);
        }
    }
1046738
private function stream(ResourceNode $resourceNode)
    {
        //temporary because otherwise injected resource must have the "open" right
        $this->checkPermission('OPEN', $resourceNode, [], true);

        // free the session as soon as possible
        // see https://github.com/claroline/CoreBundle/commit/7cee6de85bbc9448f86eb98af2abb1cb072c7b6b
        $this->session->save();

        /** @var File $file */
        $file = $this->resourceManager->getResourceFromNode($resourceNode);
        $path = $this->fileDir.DIRECTORY_SEPARATOR.$file->getHashName();

        if (!file_exists($path)) {
            return new JsonResponse(['File not found'], 500);
        }

        $response = new BinaryFileResponse($path);
        $response->headers->set('Content-Type', $resourceNode->getMimeType());

        return $response;
    }
571339
public function getChildren(
        ResourceNode $node,
        array $roles,
        $user,
        $withLastOpenDate = false,
        $canAdministrate = false
    ) {
        return $this->resourceNodeRepo->findChildren($node, $roles, $user, $withLastOpenDate, $canAdministrate);
    }
638968
protected function serialize(ResourceInterface $resource, $data)
    {
        // Get the serializer from the resource, or use the default.
        $serializer = $resource->getSerializer() ?? $this->getSerializer();
        
        if ($serializer instanceof SerializerInterface) {
            if ($resource instanceof Collection) {
                if ($data === null) {
                    return $serializer->nullCollection();
                }
                $data = $serializer->collection($resource->getResourceKey(), $data);
                if ($resource->hasPaginator()) {
                    $data = array_merge($data, $serializer->paginator($resource->getPaginator()));
                }
            } elseif ($resource instanceof Item) {
                if ($data === null) {
                    return $serializer->nullItem();
                }
                $data = $serializer->item($resource->getResourceKey(), $data);
            }
        } elseif (\is_callable($serializer)) {
            // Serialize via a callable/closure
            $data = $serializer($resource->getResourceKey(), $data);
        }
       
        return $data;
    }
457002
public function deserialize($data, Post $post = null, array $options = [])
    {
        if (empty($post)) {
            $post = new Post();
        }

        if (!in_array(Options::REFRESH_UUID, $options)) {
            $this->sipe('id', 'setUuid', $data, $post);
        }

        if (isset($data['title'])) {
            $post->setTitle($data['title']);
        }
        if (isset($data['content'])) {
            $post->setContent($data['content']);
        }
        if (isset($data['creationDate'])) {
            $post->setCreationDate(DateNormalizer::denormalize($data['creationDate']));
        }
        if (isset($data['publicationDate'])) {
            $post->setPublicationDate(DateNormalizer::denormalize($data['publicationDate']));
        }
        if (isset($data['modificationDate'])) {
            $post->setModificationDate(DateNormalizer::denormalize($data['modificationDate']));
        }
        if (isset($data['viewCounter'])) {
            $post->setViewCounter($data['viewCounter']);
        }
        if (isset($data['user'])) {
            $user = isset($data['user']['id']) ? $this->userRepo->findOneBy(['id' => $data['user']['id']]) : null;
            $post->setAuthor($user);
        }
        if (isset($data['tags'])) {
            $this->deserializeTags($post, $data['tags']);
        }
        if (isset($data['published']) && true === $data['published']) {
            $post->publish();
        }
        if (isset($data['commentModerationMode'])) {
            $post->setCommentModerationMode($data['commentModerationMode']);
        }

        return $post;
    }
411743
public function setNodeData(NodeData $nodeData): void
    {
        $this->nodeData = $nodeData;
        $this->nodeDataIsMatchingContext = null;
    }
1244776
private function convertNodes(array &$data): void
    {
        array_walk_recursive(
            $data,
            function (&$value) {
                if ($value instanceof NodeInterface) {
                    $value = IDEncoder::encode($value);
                }
            }
        );
    }
1258855
protected static function deserializeCommonAttributes(array $data)
    {
        $result = new static(isset($data['id']) ? $data['id'] : null);
        if ($result->getResourceType() != $data['meta']['resourceType']) {
            throw new \RuntimeException(sprintf('Error deserializing resource type "%s" into class "%s"', $data['meta']['resourceType'], get_class($result)));
        }
        $result->meta = Meta::deserializeObject($data['meta']);
        if (isset($arr['externalId'])) {
            $result->externalId = $data['externalId'];
        }
        if (isset($data['schemas'])) {
            foreach ($data['schemas'] as $schemaId) {
                if ($schemaId != $result->getSchemaId()) {
                    $result->extensions[$schemaId] = isset($data[$schemaId]) ? $data[$schemaId] : null;
                }
            }
        }

        return $result;
    }
559985
public function getOneByRoleAndResource(Role $role, ResourceNode $node)
    {
        /** @var ResourceRights $resourceRights */
        $resourceRights = $this->rightsRepo->findOneBy(['resourceNode' => $node, 'role' => $role]);
        if ($resourceRights) {
            return $resourceRights;
        }

        $resourceRights = new ResourceRights();
        $resourceRights->setResourceNode($node);
        $resourceRights->setRole($role);

        return $resourceRights;
    }
594085
public function findRootPageByResourceNode(ResourceNode $resourceNode)
    {
        return $this->createQueryBuilder('page')
            ->leftJoin('page.website', 'website')
            ->leftJoin('website.resourceNode', 'resource')
            ->where('resource = :resourceNode')
            ->andWhere('page.type = :type')
            ->setParameter('resourceNode', $resourceNode)
            ->setParameter('type', 'root')
            ->getQuery()
            ->getSingleResult();
    }
917938
private function createNodeFromArray(array $data = []): Node
    {
        if (null === $this->serializer) {
            $this->serializer = new PhpArraySerializer();
        }

        /** @var Node $node */
        $node = $this->serializer->deserialize($data);
        return $node;
    }
849617
public function onResourcesDelete(GenericDatasEvent $event)
    {
        $resources = $event->getDatas();
        $ids = array();

        foreach ($resources as $resource) {
            $ids[] = $resource->getId();
        }
        $this->tagManager->removeTaggedObjectsByClassAndIds(
            'Claroline\CoreBundle\Entity\Resource\ResourceNode',
            $ids
        );
    }
662212
public function normalize($data, Resource $resource)
    {
        if (isset($data['value']['map'])) {
            $options = isset($data['value']['map']['options']) ? $data['value']['map']['options'] : [];
            $data['value']['map'] = $this->normalizer->normalize(
                [
                    'key'   => $data['value']['map']['validator'],
                    'value' => $options,
                ],
                $resource
            );
        }

        return $this->createDefinition($data['value']);
    }