1<?php
2namespace TYPO3\CMS\Backend\Tree\Renderer;
3
4/*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17/**
18 * Renderer for unordered lists
19 */
20class UnorderedListTreeRenderer extends \TYPO3\CMS\Backend\Tree\Renderer\AbstractTreeRenderer
21{
22    /**
23     * recursion level
24     *
25     * @var int
26     */
27    protected $recursionLevel = 0;
28
29    /**
30     * Renders a node recursive or just a single instance
31     *
32     * @param \TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node
33     * @param bool $recursive
34     * @return string
35     */
36    public function renderNode(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node, $recursive = true)
37    {
38        $code = '<li><span class="' . htmlspecialchars($node->getIcon()) . '">&nbsp;</span>' . htmlspecialchars($node->getLabel());
39        if ($recursive && $node->getChildNodes() !== null) {
40            $this->recursionLevel++;
41            $code .= $this->renderNodeCollection($node->getChildNodes());
42            $this->recursionLevel--;
43        }
44        $code .= '</li>';
45        return $code;
46    }
47
48    /**
49     * Renders a node collection recursive or just a single instance
50     *
51     * @param \TYPO3\CMS\Backend\Tree\AbstractTree $tree
52     * @param bool $recursive
53     * @return string
54     */
55    public function renderTree(\TYPO3\CMS\Backend\Tree\AbstractTree $tree, $recursive = true)
56    {
57        $this->recursionLevel = 0;
58        $code = '<ul class="level' . $this->recursionLevel . '" style="margin-left:10px">';
59        $code .= $this->renderNode($tree->getRoot(), $recursive);
60        $code .= '</ul>';
61        return $code;
62    }
63
64    /**
65     * Renders an tree recursive or just a single instance
66     *
67     * @param \TYPO3\CMS\Backend\Tree\TreeNodeCollection $collection
68     * @param bool $recursive
69     * @return string
70     */
71    public function renderNodeCollection(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $collection, $recursive = true)
72    {
73        $code = '<ul class="level' . $this->recursionLevel . '" style="margin-left:10px">';
74        foreach ($collection as $node) {
75            $code .= $this->renderNode($node, $recursive);
76        }
77        $code .= '</ul>';
78        return $code;
79    }
80}
81