Passed
Push — master ( 22c836...715de5 )
by Jan
03:12
created

TreeViewNode::getHref()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * part-db version 0.1
4
 * Copyright (C) 2005 Christoph Lechner
5
 * http://www.cl-projects.de/.
6
 *
7
 * part-db version 0.2+
8
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
9
 * http://code.google.com/p/part-db/
10
 *
11
 * Part-DB Version 0.4+
12
 * Copyright (C) 2016 - 2019 Jan Böhmer
13
 * https://github.com/jbtronics
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
28
 */
29
30
namespace App\Helpers;
31
32
/**
33
 * This class represents a node for the bootstrap treeview node.
34
 * When you serialize an array of these objects to JSON, you can use the serialized data in data for the treeview.
35
 * @package App\Helpers
36
 */
37
class TreeViewNode
38
{
39
    protected $text;
40
    protected $href;
41
    protected $nodes;
42
43
    /**
44
     * Creates a new TreeView node with the given parameters.
45
     * @param string $text The text that is shown in the node. (e.g. the name of the node)
46
     * @param string|null $href A link for the node. You have to activate "enableLinks" option in init of the treeview.
47
     *                          Set this to null, if no href should be used.
48
     * @param array|null $nodes An array containing other TreeViewNodes. They will be used as children nodes of the
49
     *                          newly created nodes. Set to null, if it should not have children.
50
     */
51
    public function __construct(string $text, ?string $href = null, ?array $nodes = null)
52
    {
53
        $this->text = $text;
54
        $this->href = $href;
55
        $this->nodes = $nodes;
56
    }
57
58
    /**
59
     * Returns the node text.
60
     * @return string
61
     */
62
    public function getText(): string
63
    {
64
        return $this->text;
65
    }
66
67
    /**
68
     * Sets the node text
69
     * @param string $text The new node text.
70
     * @return TreeViewNode
71
     */
72
    public function setText(string $text): self
73
    {
74
        $this->text = $text;
75
        return $this;
76
    }
77
78
    /**
79
     * Returns the href link.
80
     * @return string|null
81
     */
82
    public function getHref(): ?string
83
    {
84
        return $this->href;
85
    }
86
87
    /**
88
     * Sets the href link.
89
     * @param string|null $href The new href link.
90
     * @return TreeViewNode
91
     */
92
    public function setHref(?string $href): self
93
    {
94
        $this->href = $href;
95
        return $this;
96
    }
97
98
    /**
99
     * Returns the children nodes of this node.
100
     * @return array|null
101
     */
102
    public function getNodes(): ?array
103
    {
104
        return $this->nodes;
105
    }
106
107
    /**
108
     * Sets the children nodes.
109
     * @param array|null $nodes The new children nodes
110
     * @return TreeViewNode
111
     */
112
    public function setNodes(?array $nodes): self
113
    {
114
        $this->nodes = $nodes;
115
        return $this;
116
    }
117
118
}
119