forked from etrepat/baum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.php
1277 lines (1102 loc) · 31.7 KB
/
Node.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace Baum;
use Baum\Extensions\Eloquent\Collection;
use Baum\Extensions\Eloquent\Model;
/**
* Node
*
* This abstract class implements Nested Set functionality. A Nested Set is a
* smart way to implement an ordered tree with the added benefit that you can
* select all of their descendants with a single query. Drawbacks are that
* insertion or move operations need more complex sql queries.
*
* Nested sets are appropiate when you want either an ordered tree (menus,
* commercial categories, etc.) or an efficient way of querying big trees.
*/
abstract class Node extends Model {
/**
* Column name to store the reference to parent's node.
*
* @var string
*/
protected $parentColumn = 'parent_id';
/**
* Column name for left index.
*
* @var string
*/
protected $leftColumn = 'lft';
/**
* Column name for right index.
*
* @var string
*/
protected $rightColumn = 'rgt';
/**
* Column name for depth field.
*
* @var string
*/
protected $depthColumn = 'depth';
/**
* Column to perform the default sorting
*
* @var string
*/
protected $orderColumn = null;
/**
* Guard NestedSet fields from mass-assignment.
*
* @var array
*/
protected $guarded = array('id', 'parent_id', 'lft', 'rgt', 'depth');
/**
* Indicates whether we should move to a new parent.
*
* @var int
*/
protected static $moveToNewParentId = NULL;
/**
* Columns which restrict what we consider our Nested Set list
*
* @var array
*/
protected $scoped = array();
/**
* The "booting" method of the model.
*
* We'll use this method to register event listeners on a Node instance as
* suggested in the beta documentation...
*
* TODO:
*
* - Find a way to avoid needing to declare the called methods "public"
* as registering the event listeners *inside* this methods does not give
* us an object context.
*
* Events:
*
* 1. "creating": Before creating a new Node we'll assign a default value
* for the left and right indexes.
*
* 2. "saving": Before saving, we'll perform a check to see if we have to
* move to another parent.
*
* 3. "saved": Move to the new parent after saving if needed and re-set
* depth.
*
* 4. "deleting": Before delete we should prune all children and update
* the left and right indexes for the remaining nodes.
*
* 5. (optional) "restoring": Before a soft-delete node restore operation,
* shift its siblings.
*
* 6. (optional) "restore": After having restored a soft-deleted node,
* restore all of its descendants.
*
* @return void
*/
protected static function boot() {
parent::boot();
static::creating(function($node) {
$node->setDefaultLeftAndRight();
});
static::saving(function($node) {
$node->storeNewParent();
});
static::saved(function($node) {
$node->moveToNewParent();
$node->setDepth();
});
static::deleting(function($node) {
$node->destroyDescendants();
});
if ( static::softDeletesEnabled() ) {
static::restoring(function($node) {
$node->shiftSiblingsForRestore();
});
static::restored(function($node) {
$node->restoreDescendants();
});
}
}
/**
* Get the parent column name.
*
* @return string
*/
public function getParentColumnName() {
return $this->parentColumn;
}
/**
* Get the table qualified parent column name.
*
* @return string
*/
public function getQualifiedParentColumnName() {
return $this->getTable(). '.' .$this->getParentColumnName();
}
/**
* Get the value of the models "parent_id" field.
*
* @return int
*/
public function getParentId() {
return $this->getAttribute($this->getparentColumnName());
}
/**
* Get the "left" field column name.
*
* @return string
*/
public function getLeftColumnName() {
return $this->leftColumn;
}
/**
* Get the table qualified "left" field column name.
*
* @return string
*/
public function getQualifiedLeftColumnName() {
return $this->getTable() . '.' . $this->getLeftColumnName();
}
/**
* Get the value of the model's "left" field.
*
* @return int
*/
public function getLeft() {
return $this->getAttribute($this->getLeftColumnName());
}
/**
* Get the "right" field column name.
*
* @return string
*/
public function getRightColumnName() {
return $this->rightColumn;
}
/**
* Get the table qualified "right" field column name.
*
* @return string
*/
public function getQualifiedRightColumnName() {
return $this->getTable() . '.' . $this->getRightColumnName();
}
/**
* Get the value of the model's "right" field.
*
* @return int
*/
public function getRight() {
return $this->getAttribute($this->getRightColumnName());
}
/**
* Get the "depth" field column name.
*
* @return string
*/
public function getDepthColumnName() {
return $this->depthColumn;
}
/**
* Get the table qualified "depth" field column name.
*
* @return string
*/
public function getQualifiedDepthColumnName() {
return $this->getTable() . '.' . $this->getDepthColumnName();
}
/**
* Get the model's "depth" value.
*
* @return int
*/
public function getDepth() {
return $this->getAttribute($this->getDepthColumnName());
}
/**
* Get the "order" field column name.
*
* @return string
*/
public function getOrderColumnName() {
return is_null($this->orderColumn) ? $this->getLeftColumnName() : $this->orderColumn;
}
/**
* Get the table qualified "order" field column name.
*
* @return string
*/
public function getQualifiedOrderColumnName() {
return $this->getTable() . '.' . $this->getOrderColumnName();
}
/**
* Get the model's "order" value.
*
* @return mixed
*/
public function getOrder() {
return $this->getAttribute($this->getOrderColumnName());
}
/**
* Get the column names which define our scope
*
* @return array
*/
public function getScopedColumns() {
return (array) $this->scoped;
}
/**
* Get the qualified column names which define our scope
*
* @return array
*/
public function getQualifiedScopedColumns() {
if ( !$this->isScoped() )
return $this->getScopedColumns();
$prefix = $this->getTable() . '.';
return array_map(function($c) use ($prefix) {
return $prefix . $c; }, $this->getScopedColumns());
}
/**
* Returns wether this particular node instance is scoped by certain fields
* or not.
*
* @return boolean
*/
public function isScoped() {
return !!(count($this->getScopedColumns()) > 0);
}
/**
* Parent relation (self-referential) 1-1.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function parent() {
return $this->belongsTo(get_class($this), $this->getParentColumnName());
}
/**
* Children relation (self-referential) 1-N.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function children() {
return $this->hasMany(get_class($this), $this->getParentColumnName())
->orderBy($this->getOrderColumnName());
}
/**
* Get a new "scoped" query builder for the Node's model.
*
* @param bool $excludeDeleted
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function newNestedSetQuery($excludeDeleted = true) {
$builder = $this->newQuery($excludeDeleted)->orderBy($this->getQualifiedOrderColumnName());
if ( $this->isScoped() ) {
foreach($this->scoped as $scopeFld)
$builder->where($scopeFld, '=', $this->$scopeFld);
}
return $builder;
}
/**
* Overload new Collection
*
* @param array $models
* @return \Baum\Extensions\Eloquent\Collection
*/
public function newCollection(array $models = array()) {
return new Collection($models);
}
/**
* Get all of the nodes from the database.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public static function all($columns = array('*')) {
$instance = new static;
return $instance->newQuery()
->orderBy($instance->getQualifiedOrderColumnName())
->get();
}
/**
* Returns the first root node.
*
* @return NestedSet
*/
public static function root() {
return static::roots()->first();
}
/**
* Static query scope. Returns a query scope with all root nodes.
*
* @return \Illuminate\Database\Query\Builder
*/
public static function roots() {
$instance = new static;
return $instance->newQuery()
->whereNull($instance->getParentColumnName())
->orderBy($instance->getQualifiedOrderColumnName());
}
/**
* Static query scope. Returns a query scope with all nodes which are at
* the end of a branch.
*
* @return \Illuminate\Database\Query\Builder
*/
public static function allLeaves() {
$instance = new static;
$grammar = $instance->getConnection()->getQueryGrammar();
$rgtCol = $grammar->wrap($instance->getQualifiedRightColumnName());
$lftCol = $grammar->wrap($instance->getQualifiedLeftColumnName());
return $instance->newQuery()
->whereRaw($rgtCol . ' - ' . $lftCol . ' = 1')
->orderBy($instance->getQualifiedOrderColumnName());
}
/**
* Static query scope. Returns a query scope with all nodes which are at
* the middle of a branch (not root and not leaves).
*
* @return \Illuminate\Database\Query\Builder
*/
public static function allTrunks() {
$instance = new static;
$grammar = $instance->getConnection()->getQueryGrammar();
$rgtCol = $grammar->wrap($instance->getQualifiedRightColumnName());
$lftCol = $grammar->wrap($instance->getQualifiedLeftColumnName());
return $instance->newQuery()
->whereNotNull($instance->getParentColumnName())
->whereRaw($rgtCol . ' - ' . $lftCol . ' != 1')
->orderBy($instance->getQualifiedOrderColumnName());
}
/**
* Checks wether the underlying Nested Set structure is valid.
*
* @return boolean
*/
public static function isValidNestedSet() {
$validator = new SetValidator(new static);
return $validator->passes();
}
/**
* Rebuilds the structure of the current Nested Set.
*
* @param bool $force
* @return void
*/
public static function rebuild($force = false) {
$builder = new SetBuilder(new static);
$builder->rebuild($force);
}
/**
* Maps the provided tree structure into the database.
*
* @param array|\Illuminate\Support\Contracts\ArrayableInterface
* @return boolean
*/
public static function buildTree($nodeList) {
return with(new static)->makeTree($nodeList);
}
/**
* Query scope which extracts a certain node object from the current query
* expression.
*
* @return \Illuminate\Database\Query\Builder
*/
public function scopeWithoutNode($query, $node) {
return $query->where($node->getKeyName(), '!=', $node->getKey());
}
/**
* Extracts current node (self) from current query expression.
*
* @return \Illuminate\Database\Query\Builder
*/
public function scopeWithoutSelf($query) {
return $this->scopeWithoutNode($query, $this);
}
/**
* Extracts first root (from the current node p-o-v) from current query
* expression.
*
* @return \Illuminate\Database\Query\Builder
*/
public function scopeWithoutRoot($query) {
return $this->scopeWithoutNode($query, $this->getRoot());
}
/**
* Provides a depth level limit for the query.
*
* @param query \Illuminate\Database\Query\Builder
* @param limit integer
* @return \Illuminate\Database\Query\Builder
*/
public function scopeLimitDepth($query, $limit) {
$depth = $this->exists ? $this->getDepth() : $this->getLevel();
$max = $depth + $limit;
$scopes = array($depth, $max);
return $query->whereBetween($this->getDepthColumnName(), array(min($scopes), max($scopes)));
}
/**
* Returns true if this is a root node.
*
* @return boolean
*/
public function isRoot() {
return is_null($this->getParentId());
}
/**
* Returns true if this is a leaf node (end of a branch).
*
* @return boolean
*/
public function isLeaf() {
return $this->exists && ($this->getRight() - $this->getLeft() == 1);
}
/**
* Returns true if this is a trunk node (not root or leaf).
*
* @return boolean
*/
public function isTrunk() {
return !$this->isRoot() && !$this->isLeaf();
}
/**
* Returns true if this is a child node.
*
* @return boolean
*/
public function isChild() {
return !$this->isRoot();
}
/**
* Returns the root node starting at the current node.
*
* @return NestedSet
*/
public function getRoot() {
if ( $this->exists ) {
return $this->ancestorsAndSelf()->whereNull($this->getParentColumnName())->first();
} else {
$parentId = $this->getParentId();
if ( !is_null($parentId) && $currentParent = static::find($parentId) ) {
return $currentParent->getRoot();
} else {
return $this;
}
}
}
/**
* Instance scope which targes all the ancestor chain nodes including
* the current one.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function ancestorsAndSelf() {
return $this->newNestedSetQuery()
->where($this->getLeftColumnName(), '<=', $this->getLeft())
->where($this->getRightColumnName(), '>=', $this->getRight());
}
/**
* Get all the ancestor chain from the database including the current node.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getAncestorsAndSelf($columns = array('*')) {
return $this->ancestorsAndSelf()->get($columns);
}
/**
* Get all the ancestor chain from the database including the current node
* but without the root node.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getAncestorsAndSelfWithoutRoot($columns = array('*')) {
return $this->ancestorsAndSelf()->withoutRoot()->get($columns);
}
/**
* Instance scope which targets all the ancestor chain nodes excluding
* the current one.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function ancestors() {
return $this->ancestorsAndSelf()->withoutSelf();
}
/**
* Get all the ancestor chain from the database excluding the current node.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getAncestors($columns = array('*')) {
return $this->ancestors()->get($columns);
}
/**
* Get all the ancestor chain from the database excluding the current node
* and the root node (from the current node's perspective).
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getAncestorsWithoutRoot($columns = array('*')) {
return $this->ancestors()->withoutRoot()->get($columns);
}
/**
* Instance scope which targets all children of the parent, including self.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function siblingsAndSelf() {
return $this->newNestedSetQuery()
->where($this->getParentColumnName(), $this->getParentId());
}
/**
* Get all children of the parent, including self.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getSiblingsAndSelf($columns = array('*')) {
return $this->siblingsAndSelf()->get($columns);
}
/**
* Instance scope targeting all children of the parent, except self.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function siblings() {
return $this->siblingsAndSelf()->withoutSelf();
}
/**
* Return all children of the parent, except self.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getSiblings($columns = array('*')) {
return $this->siblings()->get($columns);
}
/**
* Instance scope targeting all of its nested children which do not have
* children.
*
* @return \Illuminate\Database\Query\Builder
*/
public function leaves() {
$grammar = $this->getConnection()->getQueryGrammar();
$rgtCol = $grammar->wrap($this->getQualifiedRightColumnName());
$lftCol = $grammar->wrap($this->getQualifiedLeftColumnName());
return $this->descendants()
->whereRaw($rgtCol . ' - ' . $lftCol . ' = 1');
}
/**
* Return all of its nested children which do not have children.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getLeaves($columns = array('*')) {
return $this->leaves()->get($columns);
}
/**
* Instance scope targeting all of its nested children which are between the
* root and the leaf nodes (middle branch).
*
* @return \Illuminate\Database\Query\Builder
*/
public function trunks() {
$grammar = $this->getConnection()->getQueryGrammar();
$rgtCol = $grammar->wrap($this->getQualifiedRightColumnName());
$lftCol = $grammar->wrap($this->getQualifiedLeftColumnName());
return $this->descendants()
->whereNotNull($this->getQualifiedParentColumnName())
->whereRaw($rgtCol . ' - ' . $lftCol . ' != 1');
}
/**
* Return all of its nested children which are trunks.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getTrunks($columns = array('*')) {
return $this->trunks()->get($columns);
}
/**
* Scope targeting itself and all of its nested children.
*
* @return \Illuminate\Database\Query\Builder
*/
public function descendantsAndSelf() {
return $this->newNestedSetQuery()
->where($this->getLeftColumnName(), '>=', $this->getLeft())
->where($this->getLeftColumnName(), '<', $this->getRight());
}
/**
* Retrieve all nested children an self.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getDescendantsAndSelf($columns = array('*')) {
if ( is_array($columns) )
return $this->descendantsAndSelf()->get($columns);
$arguments = func_get_args();
$limit = intval(array_shift($arguments));
$columns = array_shift($arguments) ?: array('*');
return $this->descendantsAndSelf()->limitDepth($limit)->get($columns);
}
/**
* Set of all children & nested children.
*
* @return \Illuminate\Database\Query\Builder
*/
public function descendants() {
return $this->descendantsAndSelf()->withoutSelf();
}
/**
* Retrieve all of its children & nested children.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getDescendants($columns = array('*')) {
if ( is_array($columns) )
return $this->descendants()->get($columns);
$arguments = func_get_args();
$limit = intval(array_shift($arguments));
$columns = array_shift($arguments) ?: array('*');
return $this->descendants()->limitDepth($limit)->get($columns);
}
/**
* Set of "immediate" descendants (aka children), alias for the children relation.
*
* @return \Illuminate\Database\Query\Builder
*/
public function immediateDescendants() {
return $this->children();
}
/**
* Retrive all of its "immediate" descendants.
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getImmediateDescendants($columns = array('*')) {
return $this->children()->get($columns);
}
/**
* Returns the level of this node in the tree.
* Root level is 0.
*
* @return int
*/
public function getLevel() {
if ( is_null($this->getParentId()) )
return 0;
return $this->computeLevel();
}
/**
* Returns true if node is a descendant.
*
* @param NestedSet
* @return boolean
*/
public function isDescendantOf($other) {
return (
$this->getLeft() > $other->getLeft() &&
$this->getLeft() < $other->getRight() &&
$this->inSameScope($other)
);
}
/**
* Returns true if node is self or a descendant.
*
* @param NestedSet
* @return boolean
*/
public function isSelfOrDescendantOf($other) {
return (
$this->getLeft() >= $other->getLeft() &&
$this->getLeft() < $other->getRight() &&
$this->inSameScope($other)
);
}
/**
* Returns true if node is an ancestor.
*
* @param NestedSet
* @return boolean
*/
public function isAncestorOf($other) {
return (
$this->getLeft() < $other->getLeft() &&
$this->getRight() > $other->getLeft() &&
$this->inSameScope($other)
);
}
/**
* Returns true if node is self or an ancestor.
*
* @param NestedSet
* @return boolean
*/
public function isSelfOrAncestorOf($other) {
return (
$this->getLeft() <= $other->getLeft() &&
$this->getRight() > $other->getLeft() &&
$this->inSameScope($other)
);
}
/**
* Returns the first sibling to the left.
*
* @return NestedSet
*/
public function getLeftSibling() {
return $this->siblings()
->where($this->getLeftColumnName(), '<', $this->getLeft())
->orderBy($this->getOrderColumnName(), 'desc')
->get()
->last();
}
/**
* Returns the first sibling to the right.
*
* @return NestedSet
*/
public function getRightSibling() {
return $this->siblings()
->where($this->getLeftColumnName(), '>', $this->getLeft())
->first();
}
/**
* Find the left sibling and move to left of it.
*
* @return \Baum\Node
*/
public function moveLeft() {
return $this->moveToLeftOf($this->getLeftSibling());
}
/**
* Find the right sibling and move to the right of it.
*
* @return \Baum\Node
*/
public function moveRight() {
return $this->moveToRightOf($this->getRightSibling());
}
/**
* Move to the node to the left of ...
*
* @return \Baum\Node
*/
public function moveToLeftOf($node) {
return $this->moveTo($node, 'left');
}
/**
* Move to the node to the right of ...
*
* @return \Baum\Node
*/
public function moveToRightOf($node) {
return $this->moveTo($node, 'right');
}
/**
* Alias for moveToRightOf
*
* @return \Baum\Node
*/
public function makeNextSiblingOf($node) {
return $this->moveToRightOf($node);
}
/**
* Alias for moveToRightOf
*
* @return \Baum\Node
*/
public function makeSiblingOf($node) {
return $this->moveToRightOf($node);
}
/**
* Alias for moveToLeftOf
*
* @return \Baum\Node
*/
public function makePreviousSiblingOf($node) {
return $this->moveToLeftOf($node);
}
/**
* Make the node a child of ...
*
* @return \Baum\Node
*/
public function makeChildOf($node) {
return $this->moveTo($node, 'child');
}
/**
* Make the node the first child of ...
*
* @return \Baum\Node
*/
public function makeFirstChildOf($node) {
if ( $node->children()->count() == 0 )
return $this->makeChildOf($node);
return $this->moveToLeftOf($node->children()->first());
}
/**
* Make the node the last child of ...
*
* @return \Baum\Node
*/
public function makeLastChildOf($node) {
return $this->makeChildOf($node);
}
/**
* Make current node a root node.
*
* @return \Baum\Node
*/
public function makeRoot() {
return $this->moveTo($this, 'root');
}
/**
* Equals?
*
* @param \Baum\Node
* @return boolean
*/
public function equals($node) {
return ($this == $node);
}
/**
* Checkes if the given node is in the same scope as the current one.