Serializes an Entry entity for the JSON api.

@param Entry $entry   - the entry to serialize
@param array $options - a list of serialization options

@return array - the serialized representation of the entry
438436
public function serialize(Entry $entry, array $options = [])
    {
        $user = $entry->getUser();

        $serialized = [
            'id' => $entry->getUuid(),
            'autoId' => $entry->getId(),
            'title' => $entry->getTitle(),
            'status' => $entry->getStatus(),
            'locked' => $entry->isLocked(),
            'creationDate' => $entry->getCreationDate() ? $entry->getCreationDate()->format('Y-m-d H:i:s') : null,
            'editionDate' => $entry->getEditionDate() ? $entry->getEditionDate()->format('Y-m-d H:i:s') : null,
            'publicationDate' => $entry->getPublicationDate() ? $entry->getPublicationDate()->format('Y-m-d H:i:s') : null,
            'user' => $user ? $this->userSerializer->serialize($user, [Options::SERIALIZE_MINIMAL]) : null,
            'clacoForm' => [
                'id' => $entry->getClacoForm()->getUuid(),
            ],
        ];
        $fieldValues = $entry->getFieldValues();

        if (count($fieldValues) > 0) {
            $serialized['values'] = $this->serializeValues($fieldValues);
        }
        if (!in_array(Options::SERIALIZE_MINIMAL, $options)) {
            $serialized = array_merge($serialized, [
                'categories' => $this->getCategories($entry),
                'keywords' => $this->getKeywords($entry),
                'comments' => $this->getComments($entry),
            ]);
        }

        return $serialized;
    }
130359
protected function parseEntry($entry)
    {
        if (!get_property($entry, 'url')) {
            throw new \InvalidArgumentException('Url is missing or not accessible.');
        }
        $url        = get_property($entry, 'url');
        $lastmod    = get_property($entry, 'lastmod');
        $changefreq = get_property($entry, 'changefreq');
        $priority   = get_property($entry, 'priority');

        return [$url, $lastmod, $changefreq, $priority];
    }
489054
public static final function jsonDecode($data, array $options = null): array
    {
        $encoder = new JsonEncoder($options);

        return [$encoder->decode($data), $encoder->hasError()
            ? new EncoderException('JSON Error: '. $encoder->getError()) : null];
    }
135221
function serializeEntry(entry) {
    return {
        id: entry.id,
        remote_id: entry.remote ? entry.remote.getId() : undefined,
        matrix_id: entry.matrix ? entry.matrix.getId() : undefined,
        remote: entry.remote ? entry.remote.serialize() : undefined,
        matrix: entry.matrix ? entry.matrix.serialize() : undefined,
        data: entry.data
    }
}
44241
public function serialize(CompetencyAbility $competencyAbility, array $options = [])
    {
        $serialized = [
            'id' => $competencyAbility->getUuid(),
            'level' => $this->levelSerializer->serialize($competencyAbility->getLevel(), [Options::SERIALIZE_MINIMAL]),
            'competency' => [
                'id' => $competencyAbility->getCompetency()->getUuid(),
            ],
            'ability' => $this->abilitySerializer->serialize($competencyAbility->getAbility(), [Options::SERIALIZE_MINIMAL]),
        ];

        return $serialized;
    }
1005256
public function serialize($content, array $options = [])
    {
        $node = $content->getResourceNode();

        if (!empty($node)) {
            $serialized = $this->resourceContentSerializer->serialize($node, $options);
        } else {
            $serialized = [
                'type' => 'text/html',
                'data' => $content->getData(),
            ];
        }

        return $serialized;
    }
1303369
public function addEntry(AbstractEntry $entry, $prepend = false) {
        if ($prepend) {
            array_unshift($this->entries, $entry);
        } else {
            $this->entries[] = $entry;
        }
    }
698718
public function serialize(ClacoForm $clacoForm, array $options = [])
    {
        $serialized = [
            'id' => $clacoForm->getUuid(),

            // TODO : break into multiple sub object
            // TODO : use camelCase
            'details' => [
                'max_entries' => $clacoForm->getMaxEntries(),
                'creation_enabled' => $clacoForm->isCreationEnabled(),
                'edition_enabled' => $clacoForm->isEditionEnabled(),
                'moderated' => $clacoForm->isModerated(),
                'default_home' => $clacoForm->getDefaultHome(),
                'display_nb_entries' => $clacoForm->getDisplayNbEntries(),
                'menu_position' => $clacoForm->getMenuPosition(),
                'search_enabled' => $clacoForm->getSearchEnabled(),
                'display_metadata' => $clacoForm->getDisplayMetadata(),
                'locked_fields_for' => $clacoForm->getLockedFieldsFor(),
                'display_categories' => $clacoForm->getDisplayCategories(),
                'open_categories' => $clacoForm->getOpenCategories(),
                'comments_enabled' => $clacoForm->isCommentsEnabled(),
                'anonymous_comments_enabled' => $clacoForm->isAnonymousCommentsEnabled(),
                'moderate_comments' => $clacoForm->getModerateComments(),
                'display_comments' => $clacoForm->getDisplayComments(),
                'open_comments' => $clacoForm->getOpenComments(),
                'display_comment_author' => $clacoForm->getDisplayCommentAuthor(),
                'display_comment_date' => $clacoForm->getDisplayCommentDate(),
                'comments_roles' => $clacoForm->getCommentsRoles(),
                'comments_display_roles' => $clacoForm->getCommentsDisplayRoles(),
                'votes_enabled' => $clacoForm->isVotesEnabled(),
                'display_votes' => $clacoForm->getDisplayVotes(),
                'open_votes' => $clacoForm->getOpenVotes(),
                'votes_start_date' => $clacoForm->getVotesStartDate(),
                'votes_end_date' => $clacoForm->getVotesEndDate(),
                'keywords_enabled' => $clacoForm->isKeywordsEnabled(),
                'new_keywords_enabled' => $clacoForm->isNewKeywordsEnabled(),
                'display_keywords' => $clacoForm->getDisplayKeywords(),
                'open_keywords' => $clacoForm->getOpenKeywords(),
                'display_title' => $clacoForm->getDisplayTitle(),
                'display_subtitle' => $clacoForm->getDisplaySubtitle(),
                'display_content' => $clacoForm->getDisplayContent(),
                'title_field_label' => $clacoForm->getTitleFieldLabel(),
            ],

            'display' => [
                'showEntryNav' => $clacoForm->getShowEntryNav(),
            ],

            'random' => [
                'enabled' => $clacoForm->isRandomEnabled(),
                'categories' => $clacoForm->getRandomCategories(),
                'dates' => DateRangeNormalizer::normalize(
                    $clacoForm->getRandomStartDate(),
                    $clacoForm->getRandomEndDate()
                ),
            ],

            'template' => [
                'enabled' => $clacoForm->getUseTemplate(),
                'content' => $clacoForm->getTemplate(),
            ],

            // entry list config
            // todo : big c/c from Claroline\CoreBundle\API\Serializer\Widget\Type\ListWidgetSerializer
            'list' => [
                'actions' => $clacoForm->hasActions(),
                'count' => $clacoForm->hasCount(),
                // display feature
                'display' => $clacoForm->getDisplay(),
                'availableDisplays' => $clacoForm->getAvailableDisplays(),

                // sort feature
                'sorting' => $clacoForm->getSortBy(),
                'availableSort' => $clacoForm->getAvailableSort(),

                // filter feature
                'searchMode' => $clacoForm->getSearchMode(),
                'filters' => $clacoForm->getFilters(),
                'availableFilters' => $clacoForm->getAvailableFilters(),

                // pagination feature
                'paginated' => $clacoForm->isPaginated(),
                'pageSize' => $clacoForm->getPageSize(),
                'availablePageSizes' => $clacoForm->getAvailablePageSizes(),

                // table config
                'columns' => $clacoForm->getDisplayedColumns(),
                'availableColumns' => $clacoForm->getAvailableColumns(),

                // grid config
                'card' => [
                    'display' => $clacoForm->getCard(),
                    'mapping' => [], // TODO : grab custom ClacoForm config when standard list can handle it
                ],
            ],
        ];

        if (!in_array(Options::SERIALIZE_MINIMAL, $options)) {
            $serialized = array_merge($serialized, [
                'categories' => array_map(function (Category $category) {
                    return $this->categorySerializer->serialize($category);
                }, $clacoForm->getCategories()),
            ]);
            $serialized = array_merge($serialized, [
                'keywords' => array_map(function (Keyword $keyword) {
                    return $this->keywordSerializer->serialize($keyword);
                }, $clacoForm->getKeywords()),
            ]);
            $serialized = array_merge($serialized, [
                'fields' => array_map(function (Field $field) {
                    return $this->fieldSerializer->serialize($field);
                }, $clacoForm->getFields()),
            ]);
        }

        return $serialized;
    }
252703
public function export_translations(EntryTranslations $entry)
    {
        //TODO: warnings for control characters
        return $entry->is_plural ? implode(chr(0), $entry->translations) : $entry->translations[0];
    }
485332
public function serialize(Keyword $keyword, array $options = [])
    {
        $serialized = [
            'text' => $keyword->getText(),
            'caseSensitive' => $keyword->isCaseSensitive(),
            'score' => $keyword->getScore(),
        ];

        if ($keyword->getFeedback()) {
            $serialized['feedback'] = $keyword->getFeedback();
        }

        return $serialized;
    }
269297
public function unserializeEntry($Entry)
    {
        if (!$Entry || !is_string($Entry) || !preg_match('~^a\:\d+\:\{.*\}$~', $Entry)) {
            return $Entry;
        }
        $Arr = unserialize($Entry);
        if (is_array($Arr)) {
            $this->clearExpired($Arr);
            return $Arr;
        }
        return $Entry;
    }
781873
protected function json_encode_options($options)
    {
        $data = $this->prepare_options($options);

        $json = json_encode($data['options']);

        $json = str_replace($data['toReplace'], $data['original'], $json);

        return $json;
    }
145651
protected function getPropertiesFromAtomEntry(Entry $entry)
    {
        $result = [];
        $content = $entry->getContent();
        if (!empty($content)) {
            $result = ContentPropertiesSerializer::unserialize(
                $content->getXml()->children(Resources::DSM_XML_NAMESPACE)
            );
        }

        return $result;
    }
421713
public function getAttributeValues($entry)
    {
        $r = $this->entityManager->getRepository('\Concrete\Core\Entity\Attribute\Value\ExpressValue');
        $values = $r->findBy([
            'entry' => $entry,
        ]);

        return $values;
    }
249125
public static final function jsonEncode($data, array $options = null): array
    {
        $encoder = new JsonEncoder($options);

        return [$encoder->encode($data), $encoder->hasError()
            ? new EncoderException('JSON Error: '. $encoder->getError()) : null];
    }
1091173
public function write($message, $options = 0)
    {
        if ($message instanceof \Exception || (interface_exists('\Throwable') && $message instanceof \Throwable)) {
            echo $message;
            return $this;
        } elseif ($message instanceof \JsonSerializable) {
            echo json_encode($message, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
            return $this;
        } elseif ($message instanceof \Serializable) {
            echo serialize($message);
            return $this;
        } elseif (!is_array($message)) {
            echo (string)$message;
            return $this;
        }

        if (!isset($message[0]) || !is_string($message[0])) {
            echo json_encode($message, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
            return $this;
        }

        if (substr_count($message[0], '%') + 1 >= ($count = count($message)) && isset($message[$count - 1])) {
            foreach ((array)$message as $k => $v) {
                if ($k === 0 || is_scalar($v) || $v === null) {
                    continue;
                }

                if ($v instanceof \Exception || (interface_exists('\Throwable') && $v instanceof \Throwable)) {
                    $message[$k] = (string)$v;
                } elseif (is_array($v) || $v instanceof \JsonSerializable) {
                    $message[$k] = json_encode($v, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
                }
            }
            /** @noinspection ArgumentUnpackingCanBeUsedInspection */
            echo call_user_func_array('sprintf', $message);

            return $this;
        }

        if (count($message) === 2) {
            if (isset($message[1]) && strpos($message[0], ':1') === false) {
                if (is_scalar($message[1])) {
                    echo json_encode($message, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
                    return $this;
                } else {
                    $message[0] = rtrim($message[0], ': ') . ': :1';
                }
            }
        } elseif (count($message) === 3) {
            if (isset($message[1], $message[2]) && strpos($message[0], ':1') === false) {
                if (is_scalar($message[1]) && !is_scalar($message[2])) {
                    $message[0] = rtrim($message[0], ': ') . ': :1 => :2';
                } else {
                    echo json_encode($message, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
                    return $this;
                }
            }
        }

        if (strpos($message[0], ':') === false) {
            echo $this->colorize($message[0], $options);
        } else {
            $replaces = [];

            foreach ((array)$message as $k => $v) {
                if ($k === 0) {
                    continue;
                }

                if (is_int($v)) {
                    if (!$options && strpos($v, "\033[") === false) {
                        $v = $this->colorize($v, self::FC_GREEN);
                    }
                } elseif (is_string($v)) {
                    if (!$options && strpos($v, "\033[") === false) {
                        $v = $this->colorize($v, self::FC_CYAN);
                    }
                } elseif ($v instanceof \Exception || (interface_exists('\Throwable') && $v instanceof \Throwable)) {
                    $v = (string)$v;
                } elseif (is_array($v) || $v instanceof \JsonSerializable) {
                    $v = json_encode($v, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
                } elseif ($v instanceof \Serializable) {
                    $v = serialize($v);
                } elseif ($v === null || is_scalar($v)) {
                    $v = json_encode($v);
                } else {
                    $v = (string)$v;
                }

                $replaces[':' . $k] = $v;
            }

            echo $this->colorize(strtr($message[0], $replaces), $options);
        }

        return $this;
    }
990523
public function toJson($options = 0)
    {
        // Models' toJson() calls their toArray() function.  We don't want this to
        // happen twice
        if (!is_a($this, Model::class)) {
            $this->runSerializeTransforms();
        }

        // Continue execution
        return parent::toJson($options);
    }