Completed
Push — master ( 928b57...650b38 )
by Jan
03:05
created

TreeViewNode::setSelected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
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
    protected $state;
44
45
    /**
46
     * Creates a new TreeView node with the given parameters.
47
     * @param string $text The text that is shown in the node. (e.g. the name of the node)
48
     * @param string|null $href A link for the node. You have to activate "enableLinks" option in init of the treeview.
49
     *                          Set this to null, if no href should be used.
50
     * @param array|null $nodes An array containing other TreeViewNodes. They will be used as children nodes of the
51
     *                          newly created nodes. Set to null, if it should not have children.
52
     */
53
    public function __construct(string $text, ?string $href = null, ?array $nodes = null)
54
    {
55
        $this->text = $text;
56
        $this->href = $href;
57
        $this->nodes = $nodes;
58
59
        $this->state = new TreeViewNodeState();
60
    }
61
62
    /**
63
     * Returns the node text.
64
     * @return string
65
     */
66
    public function getText(): string
67
    {
68
        return $this->text;
69
    }
70
71
    /**
72
     * Sets the node text
73
     * @param string $text The new node text.
74
     * @return TreeViewNode
75
     */
76
    public function setText(string $text): self
77
    {
78
        $this->text = $text;
79
        return $this;
80
    }
81
82
    /**
83
     * Returns the href link.
84
     * @return string|null
85
     */
86
    public function getHref(): ?string
87
    {
88
        return $this->href;
89
    }
90
91
    /**
92
     * Sets the href link.
93
     * @param string|null $href The new href link.
94
     * @return TreeViewNode
95
     */
96
    public function setHref(?string $href): self
97
    {
98
        $this->href = $href;
99
        return $this;
100
    }
101
102
    /**
103
     * Returns the children nodes of this node.
104
     * @return array|null
105
     */
106
    public function getNodes(): ?array
107
    {
108
        return $this->nodes;
109
    }
110
111
    /**
112
     * Sets the children nodes.
113
     * @param array|null $nodes The new children nodes
114
     * @return TreeViewNode
115
     */
116
    public function setNodes(?array $nodes): self
117
    {
118
        $this->nodes = $nodes;
119
        return $this;
120
    }
121
122
    public function getState() : TreeViewNodeState
123
    {
124
        return $this->state;
125
    }
126
127
    public function setState(TreeViewNodeState $state) : self
128
    {
129
        $this->state = $state;
130
        return $this;
131
    }
132
133
    public function setDisabled(?bool $disabled) : self
134
    {
135
        $this->state->setDisabled($disabled);
136
137
        return $this;
138
    }
139
140
    public function setSelected(?bool $selected) : self
141
    {
142
        $this->state->setSelected($selected);
143
144
        return $this;
145
    }
146
147
}
148