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