1 | <?php |
||
10 | class Tree implements Renderable |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $items = []; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $elementId = 'tree-'; |
||
21 | |||
22 | /** |
||
23 | * @var Model |
||
24 | */ |
||
25 | protected $model; |
||
26 | |||
27 | /** |
||
28 | * @var \Closure |
||
29 | */ |
||
30 | protected $queryCallback; |
||
31 | |||
32 | /** |
||
33 | * View of tree to render. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $view = [ |
||
38 | 'tree' => 'admin::tree', |
||
39 | 'branch' => 'admin::tree.branch', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * @var \Closure |
||
44 | */ |
||
45 | protected $callback; |
||
46 | |||
47 | /** |
||
48 | * @var null |
||
49 | */ |
||
50 | protected $branchCallback = null; |
||
51 | |||
52 | /** |
||
53 | * @var bool |
||
54 | */ |
||
55 | public $useCreate = true; |
||
56 | |||
57 | /** |
||
58 | * @var bool |
||
59 | */ |
||
60 | public $useSave = true; |
||
61 | |||
62 | /** |
||
63 | * @var bool |
||
64 | */ |
||
65 | public $useRefresh = true; |
||
66 | |||
67 | /** |
||
68 | * @var array |
||
69 | */ |
||
70 | protected $nestableOptions = []; |
||
71 | |||
72 | /** |
||
73 | * Header tools. |
||
74 | * |
||
75 | * @var Tools |
||
76 | */ |
||
77 | public $tools; |
||
78 | |||
79 | /** |
||
80 | * Menu constructor. |
||
81 | * |
||
82 | * @param Model|null $model |
||
83 | */ |
||
84 | public function __construct(Model $model = null, \Closure $callback = null) |
||
99 | |||
100 | /** |
||
101 | * Setup tree tools. |
||
102 | */ |
||
103 | public function setupTools() |
||
107 | |||
108 | /** |
||
109 | * Initialize branch callback. |
||
110 | * |
||
111 | * @return void |
||
112 | */ |
||
113 | protected function initBranchCallback() |
||
124 | |||
125 | /** |
||
126 | * Set branch callback. |
||
127 | * |
||
128 | * @param \Closure $branchCallback |
||
129 | * |
||
130 | * @return $this |
||
131 | */ |
||
132 | public function branch(\Closure $branchCallback) |
||
138 | |||
139 | /** |
||
140 | * Set query callback this tree. |
||
141 | * |
||
142 | * @return Model |
||
143 | */ |
||
144 | public function query(\Closure $callback) |
||
150 | |||
151 | /** |
||
152 | * Set nestable options. |
||
153 | * |
||
154 | * @param array $options |
||
155 | * |
||
156 | * @return $this |
||
157 | */ |
||
158 | public function nestable($options = []) |
||
164 | |||
165 | /** |
||
166 | * Disable create. |
||
167 | * |
||
168 | * @return void |
||
169 | */ |
||
170 | public function disableCreate() |
||
174 | |||
175 | /** |
||
176 | * Disable save. |
||
177 | * |
||
178 | * @return void |
||
179 | */ |
||
180 | public function disableSave() |
||
184 | |||
185 | /** |
||
186 | * Disable refresh. |
||
187 | * |
||
188 | * @return void |
||
189 | */ |
||
190 | public function disableRefresh() |
||
194 | |||
195 | /** |
||
196 | * Save tree order from a input. |
||
197 | * |
||
198 | * @param string $serialize |
||
199 | * |
||
200 | * @return bool |
||
201 | */ |
||
202 | public function saveOrder($serialize) |
||
214 | |||
215 | /** |
||
216 | * Build tree grid scripts. |
||
217 | * |
||
218 | * @return string |
||
219 | */ |
||
220 | protected function script() |
||
301 | |||
302 | /** |
||
303 | * Set view of tree. |
||
304 | * |
||
305 | * @param string $view |
||
306 | */ |
||
307 | public function setView($view) |
||
311 | |||
312 | /** |
||
313 | * Return all items of the tree. |
||
314 | * |
||
315 | * @param array $items |
||
316 | */ |
||
317 | public function getItems() |
||
321 | |||
322 | /** |
||
323 | * Variables in tree template. |
||
324 | * |
||
325 | * @return array |
||
326 | */ |
||
327 | public function variables() |
||
338 | |||
339 | /** |
||
340 | * Setup grid tools. |
||
341 | * |
||
342 | * @param Closure $callback |
||
343 | * |
||
344 | * @return void |
||
345 | */ |
||
346 | public function tools(Closure $callback) |
||
350 | |||
351 | /** |
||
352 | * Render a tree. |
||
353 | * |
||
354 | * @return \Illuminate\Http\JsonResponse|string |
||
355 | */ |
||
356 | public function render() |
||
369 | |||
370 | /** |
||
371 | * Get the string contents of the grid view. |
||
372 | * |
||
373 | * @return string |
||
374 | */ |
||
375 | public function __toString() |
||
379 | } |
||
380 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: