plugin/exo/Serializer/Item/ItemSerializer.php
private function serializeMetadata(Item $question, array $options = [])
    {
        $metadata = ['protectQuestion' => $question->getProtectUpdate()];

        $creator = $question->getCreator();

        if (!empty($creator)) {
            $metadata['creator'] = $this->userSerializer->serialize($creator, $options);
            // TODO : remove me. for retro compatibility with old schema
            $metadata['authors'] = [$this->userSerializer->serialize($creator, $options)];
        }

        if ($question->getDateCreate()) {
            $metadata['created'] = DateNormalizer::normalize($question->getDateCreate());
        }

        if ($question->getDateModify()) {
            $metadata['updated'] = DateNormalizer::normalize($question->getDateModify());
        }

        if (in_array(Transfer::INCLUDE_ADMIN_META, $options)) {
            /** @var ExerciseRepository $exerciseRepo */
            $exerciseRepo = $this->om->getRepository(Exercise::class);

            // Gets exercises that use this item
            $exercises = $exerciseRepo->findByQuestion($question);
            $metadata['usedBy'] = array_map(function (Exercise $exercise) {
                return $exercise->getUuid();
            }, $exercises);

            // Gets users who have access to this item
            $users = $this->om->getRepository(Shared::class)->findBy(['question' => $question]);
            $metadata['sharedWith'] = array_map(function (Shared $sharedQuestion) use ($options) {
                $shared = [
                    'adminRights' => $sharedQuestion->hasAdminRights(),
                    'user' => $this->userSerializer->serialize($sharedQuestion->getUser(), $options),
                ];

                return $shared;
            }, $users);
        }

        return $metadata;
    }
private function serializeMetadata(Item $question, array $options = [])
    {
        $metadata = ['protectQuestion' => $question->getProtectUpdate()];

        $creator = $question->getCreator();

        if (!empty($creator)) {
            $metadata['creator'] = $this->userSerializer->serialize($creator, $options);
            // TODO : remove me. for retro compatibility with old schema
            $metadata['authors'] = [$this->userSerializer->serialize($creator, $options)];
        }

        if ($question->getDateCreate()) {
            $metadata['created'] = DateNormalizer::normalize($question->getDateCreate());
        }

        if ($question->getDateModify()) {
            $metadata['updated'] = DateNormalizer::normalize($question->getDateModify());
        }

        if (in_array(Transfer::INCLUDE_ADMIN_META, $options)) {
            /** @var ExerciseRepository $exerciseRepo */
            $exerciseRepo = $this->om->getRepository(Exercise::class);

            // Gets exercises that use this item
            $exercises = $exerciseRepo->findByQuestion($question);
            $metadata['usedBy'] = array_map(function (Exercise $exercise) {
                return $exercise->getUuid();
            }, $exercises);

            // Gets users who have access to this item
            $users = $this->om->getRepository(Shared::class)->findBy(['question' => $question]);
            $metadata['sharedWith'] = array_map(function (Shared $sharedQuestion) use ($options) {
                $shared = [
                    'adminRights' => $sharedQuestion->hasAdminRights(),
                    'user' => $this->userSerializer->serialize($sharedQuestion->getUser(), $options),
                ];

                return $shared;
            }, $users);
        }

        return $metadata;
    }
private function serializeMetadata ( Item $ question , array $ options = [ ] ) { $ metadata = [ 'protectQuestion' => $ question -> getProtectUpdate ( ) ] ; $ creator = $ question -> getCreator ( ) ; if ( ! empty ( $ creator ) ) { $ metadata [ 'creator' ] = $ this -> userSerializer -> serialize ( $ creator , $ options ) ; // TODO : remove me. for retro compatibility with old schema $ metadata [ 'authors' ] = [ $ this -> userSerializer -> serialize ( $ creator , $ options ) ] ; } if ( $ question -> getDateCreate ( ) ) { $ metadata [ 'created' ] = DateNormalizer :: normalize ( $ question -> getDateCreate ( ) ) ; } if ( $ question -> getDateModify ( ) ) { $ metadata [ 'updated' ] = DateNormalizer :: normalize ( $ question -> getDateModify ( ) ) ; } if ( in_array ( Transfer :: INCLUDE_ADMIN_META , $ options ) ) { /** @var ExerciseRepository $exerciseRepo */ $ exerciseRepo = $ this -> om -> getRepository ( Exercise :: class ) ; // Gets exercises that use this item $ exercises = $ exerciseRepo -> findByQuestion ( $ question ) ; $ metadata [ 'usedBy' ] = array_map ( function ( Exercise $ exercise ) { return $ exercise -> getUuid ( ) ; } , $ exercises ) ; // Gets users who have access to this item $ users = $ this -> om -> getRepository ( Shared :: class ) -> findBy ( [ 'question' => $ question ] ) ; $ metadata [ 'sharedWith' ] = array_map ( function ( Shared $ sharedQuestion ) use ( $ options ) { $ shared = [ 'adminRights' => $ sharedQuestion -> hasAdminRights ( ) , 'user' => $ this -> userSerializer -> serialize ( $ sharedQuestion -> getUser ( ) , $ options ) , ] ; return $ shared ; } , $ users ) ; } return $ metadata ; }
Serializes Item metadata.

@param Item  $question
@param array $options

@return array
Serializes Item metadata .