1
|
|
|
<?php namespace Arcanedev\LaravelNestedSet\Contracts; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Interface Nodeable |
5
|
|
|
* |
6
|
|
|
* @package Arcanedev\LaravelNestedSet\Contracts |
7
|
|
|
* @author ARCANEDEV <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @property int $id |
10
|
|
|
* @property int $_lft |
11
|
|
|
* @property int $_rgt |
12
|
|
|
* @property int $parent_id |
13
|
|
|
* @property \Arcanedev\LaravelNestedSet\Contracts\Nodeable $parent |
14
|
|
|
* @property \Illuminate\Database\Eloquent\Collection $children |
15
|
|
|
*/ |
16
|
|
|
interface Nodeable extends Eloquent |
17
|
|
|
{ |
18
|
|
|
/* ----------------------------------------------------------------- |
19
|
|
|
| Getters & Setters |
20
|
|
|
| ----------------------------------------------------------------- |
21
|
|
|
*/ |
22
|
|
|
/** |
23
|
|
|
* Get the lft key name. |
24
|
|
|
* |
25
|
|
|
* @return string |
26
|
|
|
*/ |
27
|
|
|
public function getLftName(); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get the rgt key name. |
31
|
|
|
* |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
public function getRgtName(); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the parent id key name. |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function getParentIdName(); |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the value of the model's lft key. |
45
|
|
|
* |
46
|
|
|
* @return int |
47
|
|
|
*/ |
48
|
|
|
public function getLft(); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Set the value of the model's lft key. |
52
|
|
|
* |
53
|
|
|
* @param int $value |
54
|
|
|
* |
55
|
|
|
* @return self |
56
|
|
|
*/ |
57
|
|
|
public function setLft($value); |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get the value of the model's rgt key. |
61
|
|
|
* |
62
|
|
|
* @return int |
63
|
|
|
*/ |
64
|
|
|
public function getRgt(); |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Set the value of the model's rgt key. |
68
|
|
|
* |
69
|
|
|
* @param int $value |
70
|
|
|
* |
71
|
|
|
* @return self |
72
|
|
|
*/ |
73
|
|
|
public function setRgt($value); |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the value of the model's parent id key. |
77
|
|
|
* |
78
|
|
|
* @return int |
79
|
|
|
*/ |
80
|
|
|
public function getParentId(); |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set the value of the model's parent id key. |
84
|
|
|
* |
85
|
|
|
* @param int $value |
86
|
|
|
* |
87
|
|
|
* @return self |
88
|
|
|
*/ |
89
|
|
|
public function setParentId($value); |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set the value of model's parent id key. |
93
|
|
|
* |
94
|
|
|
* Behind the scenes node is appended to found parent node. |
95
|
|
|
* |
96
|
|
|
* @param int $value |
97
|
|
|
* |
98
|
|
|
* @throws \Exception If parent node doesn't exists |
99
|
|
|
*/ |
100
|
|
|
public function setParentIdAttribute($value); |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get the boundaries. |
104
|
|
|
* |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
public function getBounds(); |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Returns node that is next to current node without constraining to siblings. |
111
|
|
|
* This can be either a next sibling or a next sibling of the parent node. |
112
|
|
|
* |
113
|
|
|
* @param array $columns |
114
|
|
|
* |
115
|
|
|
* @return self |
116
|
|
|
*/ |
117
|
|
|
public function getNextNode(array $columns = ['*']); |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Returns node that is before current node without constraining to siblings. |
121
|
|
|
* This can be either a prev sibling or parent node. |
122
|
|
|
* |
123
|
|
|
* @param array $columns |
124
|
|
|
* |
125
|
|
|
* @return self |
126
|
|
|
*/ |
127
|
|
|
public function getPrevNode(array $columns = ['*']); |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get the ancestors nodes. |
131
|
|
|
* |
132
|
|
|
* @param array $columns |
133
|
|
|
* |
134
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
135
|
|
|
*/ |
136
|
|
|
public function getAncestors(array $columns = ['*']); |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get the descendants nodes. |
140
|
|
|
* |
141
|
|
|
* @param array $columns |
142
|
|
|
* |
143
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
144
|
|
|
*/ |
145
|
|
|
public function getDescendants(array $columns = ['*']); |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Get the siblings nodes. |
149
|
|
|
* |
150
|
|
|
* @param array $columns |
151
|
|
|
* |
152
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
153
|
|
|
*/ |
154
|
|
|
public function getSiblings(array $columns = ['*']); |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get the next siblings nodes. |
158
|
|
|
* |
159
|
|
|
* @param array $columns |
160
|
|
|
* |
161
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
162
|
|
|
*/ |
163
|
|
|
public function getNextSiblings(array $columns = ['*']); |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Get the previous siblings nodes. |
167
|
|
|
* |
168
|
|
|
* @param array $columns |
169
|
|
|
* |
170
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
171
|
|
|
*/ |
172
|
|
|
public function getPrevSiblings(array $columns = ['*']); |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Get the next sibling node. |
176
|
|
|
* |
177
|
|
|
* @param array $columns |
178
|
|
|
* |
179
|
|
|
* @return self |
180
|
|
|
*/ |
181
|
|
|
public function getNextSibling(array $columns = ['*']); |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Get the previous sibling node. |
185
|
|
|
* |
186
|
|
|
* @param array $columns |
187
|
|
|
* |
188
|
|
|
* @return self |
189
|
|
|
*/ |
190
|
|
|
public function getPrevSibling(array $columns = ['*']); |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Get node height (rgt - lft + 1). |
194
|
|
|
* |
195
|
|
|
* @return int |
196
|
|
|
*/ |
197
|
|
|
public function getNodeHeight(); |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Get number of descendant nodes. |
201
|
|
|
* |
202
|
|
|
* @return int |
203
|
|
|
*/ |
204
|
|
|
public function getDescendantCount(); |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Set raw node. |
208
|
|
|
* |
209
|
|
|
* @param int $lft |
210
|
|
|
* @param int $rgt |
211
|
|
|
* @param int $parentId |
212
|
|
|
* |
213
|
|
|
* @return self |
214
|
|
|
*/ |
215
|
|
|
public function rawNode($lft, $rgt, $parentId); |
216
|
|
|
|
217
|
|
|
/* ----------------------------------------------------------------- |
218
|
|
|
| Main Methods |
219
|
|
|
| ----------------------------------------------------------------- |
220
|
|
|
*/ |
221
|
|
|
/** |
222
|
|
|
* Refresh node's crucial attributes. |
223
|
|
|
*/ |
224
|
|
|
public function refreshNode(); |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Get query for siblings after the node. |
228
|
|
|
* |
229
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
230
|
|
|
*/ |
231
|
|
|
public function nextSiblings(); |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Get query for siblings before the node. |
235
|
|
|
* |
236
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
237
|
|
|
*/ |
238
|
|
|
public function prevSiblings(); |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Get query for nodes after current node. |
242
|
|
|
* |
243
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
244
|
|
|
*/ |
245
|
|
|
public function nextNodes(); |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Get query for nodes before current node in reversed order. |
249
|
|
|
* |
250
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
251
|
|
|
*/ |
252
|
|
|
public function prevNodes(); |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Get query for ancestors to the node not including the node itself. |
256
|
|
|
* |
257
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
258
|
|
|
*/ |
259
|
|
|
public function ancestors(); |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Make this node a root node. |
263
|
|
|
* |
264
|
|
|
* @return self |
265
|
|
|
*/ |
266
|
|
|
public function makeRoot(); |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Save node as root. |
270
|
|
|
* |
271
|
|
|
* @return bool |
272
|
|
|
*/ |
273
|
|
|
public function saveAsRoot(); |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Append and save a node. |
277
|
|
|
* |
278
|
|
|
* @param self $node |
279
|
|
|
* |
280
|
|
|
* @return bool |
281
|
|
|
*/ |
282
|
|
|
public function appendNode(Nodeable $node); |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Prepend and save a node. |
286
|
|
|
* |
287
|
|
|
* @param self $node |
288
|
|
|
* |
289
|
|
|
* @return bool |
290
|
|
|
*/ |
291
|
|
|
public function prependNode(Nodeable $node); |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Append a node to the new parent. |
295
|
|
|
* |
296
|
|
|
* @param self $parent |
297
|
|
|
* |
298
|
|
|
* @return self |
299
|
|
|
*/ |
300
|
|
|
public function appendToNode(Nodeable $parent); |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Prepend a node to the new parent. |
304
|
|
|
* |
305
|
|
|
* @param self $parent |
306
|
|
|
* |
307
|
|
|
* @return self |
308
|
|
|
*/ |
309
|
|
|
public function prependToNode(Nodeable $parent); |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Append or prepend a node to parent. |
313
|
|
|
* |
314
|
|
|
* @param self $parent |
315
|
|
|
* @param bool $prepend |
316
|
|
|
* |
317
|
|
|
* @return self |
318
|
|
|
*/ |
319
|
|
|
public function appendOrPrependTo(Nodeable $parent, $prepend = false); |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Insert self after a node. |
323
|
|
|
* |
324
|
|
|
* @param self $node |
325
|
|
|
* |
326
|
|
|
* @return self |
327
|
|
|
*/ |
328
|
|
|
public function afterNode(Nodeable $node); |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Insert self before node. |
332
|
|
|
* |
333
|
|
|
* @param self $node |
334
|
|
|
* |
335
|
|
|
* @return self |
336
|
|
|
*/ |
337
|
|
|
public function beforeNode(Nodeable $node); |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* Set before or after a node. |
341
|
|
|
* |
342
|
|
|
* @param self $node |
343
|
|
|
* @param bool $after |
344
|
|
|
* |
345
|
|
|
* @return self |
346
|
|
|
*/ |
347
|
|
|
public function beforeOrAfterNode(Nodeable $node, $after = false); |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Insert after a node and save. |
351
|
|
|
* |
352
|
|
|
* @param self $node |
353
|
|
|
* |
354
|
|
|
* @return bool |
355
|
|
|
*/ |
356
|
|
|
public function insertAfterNode(Nodeable $node); |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Insert before a node and save. |
360
|
|
|
* |
361
|
|
|
* @param self $node |
362
|
|
|
* |
363
|
|
|
* @return bool |
364
|
|
|
*/ |
365
|
|
|
public function insertBeforeNode(Nodeable $node); |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Move node up given amount of positions. |
369
|
|
|
* |
370
|
|
|
* @param int $amount |
371
|
|
|
* |
372
|
|
|
* @return bool |
373
|
|
|
*/ |
374
|
|
|
public function up($amount = 1); |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* Move node down given amount of positions. |
378
|
|
|
* |
379
|
|
|
* @param int $amount |
380
|
|
|
* |
381
|
|
|
* @return bool |
382
|
|
|
*/ |
383
|
|
|
public function down($amount = 1); |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* Get a new base query that includes deleted nodes. |
387
|
|
|
* |
388
|
|
|
* @param string|null $table |
389
|
|
|
* |
390
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
391
|
|
|
*/ |
392
|
|
|
public function newNestedSetQuery($table = null); |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Create a new scoped query. |
396
|
|
|
* |
397
|
|
|
* @param string|null $table |
398
|
|
|
* |
399
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
400
|
|
|
*/ |
401
|
|
|
public function newScopedQuery($table = null); |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Apply the nested set scope. |
405
|
|
|
* |
406
|
|
|
* @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query |
407
|
|
|
* @param string $table |
408
|
|
|
* |
409
|
|
|
* @return \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder|\Illuminate\Database\Query\Builder |
410
|
|
|
*/ |
411
|
|
|
public function applyNestedSetScope($query, $table = null); |
412
|
|
|
|
413
|
|
|
/* ----------------------------------------------------------------- |
414
|
|
|
| Check Methods |
415
|
|
|
| ----------------------------------------------------------------- |
416
|
|
|
*/ |
417
|
|
|
/** |
418
|
|
|
* Get whether node is root. |
419
|
|
|
* |
420
|
|
|
* @return bool |
421
|
|
|
*/ |
422
|
|
|
public function isRoot(); |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Get whether a node is a descendant of other node. |
426
|
|
|
* |
427
|
|
|
* @param self $node |
428
|
|
|
* |
429
|
|
|
* @return bool |
430
|
|
|
*/ |
431
|
|
|
public function isDescendantOf(Nodeable $node); |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* Get whether the node is immediate children of other node. |
435
|
|
|
* |
436
|
|
|
* @param self $node |
437
|
|
|
* |
438
|
|
|
* @return bool |
439
|
|
|
*/ |
440
|
|
|
public function isChildOf(Nodeable $node); |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* Get whether the node is a sibling of another node. |
444
|
|
|
* |
445
|
|
|
* @param self $node |
446
|
|
|
* |
447
|
|
|
* @return bool |
448
|
|
|
*/ |
449
|
|
|
public function isSiblingOf(Nodeable $node); |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* Get whether the node is an ancestor of other node, including immediate parent. |
453
|
|
|
* |
454
|
|
|
* @param self $node |
455
|
|
|
* |
456
|
|
|
* @return bool |
457
|
|
|
*/ |
458
|
|
|
public function isAncestorOf(Nodeable $node); |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* Get whether the node has moved since last save. |
462
|
|
|
* |
463
|
|
|
* @return bool |
464
|
|
|
*/ |
465
|
|
|
public function hasMoved(); |
466
|
|
|
} |
467
|
|
|
|