private function formatNodes(
        array &$items,
        array $nodes,
        array $visibleNodes,
        array $childrenNodes,
        User $user = null,
        $levelMax = 1,
        $level = 0
    ) {
        foreach ($nodes as $node) {
            $evaluation = $user ?
                $this->resourceEvalManager->getResourceUserEvaluation($node, $user, false) :
                null;
            $item = $this->serializer->serialize($node, [Options::SERIALIZE_MINIMAL, Options::IS_RECURSIVE]);
            $item['level'] = $level;
            $item['openingUrl'] = ['claro_resource_show_short', ['id' => $item['id']]];
            $item['validated'] = !is_null($evaluation) && 0 < $evaluation->getNbOpenings();
            $items[] = $item;

            if ((is_null($levelMax) || $level < $levelMax) && isset($childrenNodes[$node->getUuid()])) {
                $children = [];

                usort($childrenNodes[$node->getUuid()], function ($a, $b) {
                    return strcmp($a->getName(), $b->getName());
                });

                foreach ($childrenNodes[$node->getUuid()] as $child) {
                    // Checks if node is visible
                    if (isset($visibleNodes[$child->getUuid()])) {
                        $children[] = $visibleNodes[$child->getUuid()];
                    }
                }
                if (0 < count($children)) {
                    $this->formatNodes($items, $children, $visibleNodes, $childrenNodes, $user, $levelMax, $level + 1);
                }
            }
        }
    }