1 | <?php namespace Arcanedev\LaravelNestedSet\Eloquent; |
||
20 | class DescendantsRelation extends Relation |
||
21 | { |
||
22 | /* ------------------------------------------------------------------------------------------------ |
||
23 | | Properties |
||
24 | | ------------------------------------------------------------------------------------------------ |
||
25 | */ |
||
26 | /** |
||
27 | * The Eloquent query builder instance. |
||
28 | * |
||
29 | * @var \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder |
||
30 | */ |
||
31 | protected $query; |
||
32 | |||
33 | /** |
||
34 | * The parent model instance. |
||
35 | * |
||
36 | * @var \Arcanedev\LaravelNestedSet\NodeTrait |
||
37 | */ |
||
38 | protected $parent; |
||
39 | |||
40 | /* ------------------------------------------------------------------------------------------------ |
||
41 | | Constructor |
||
42 | | ------------------------------------------------------------------------------------------------ |
||
43 | */ |
||
44 | /** |
||
45 | * DescendantsRelation constructor. |
||
46 | * |
||
47 | * @param \Arcanedev\LaravelNestedSet\Eloquent\QueryBuilder $builder |
||
48 | * @param \Illuminate\Database\Eloquent\Model|NodeTrait $model |
||
49 | */ |
||
50 | 36 | public function __construct(QueryBuilder $builder, Model $model) |
|
60 | |||
61 | /** |
||
62 | * Add the constraints for a relationship query. |
||
63 | * |
||
64 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
65 | * @param \Illuminate\Database\Eloquent\Builder $parent |
||
66 | * @param array|mixed $columns |
||
67 | * |
||
68 | * @return \Illuminate\Database\Eloquent\Builder |
||
69 | */ |
||
70 | public function getRelationQuery( |
||
71 | EloquentBuilder $query, |
||
72 | EloquentBuilder $parent, |
||
|
|||
73 | $columns = ['*'] |
||
74 | ) { |
||
75 | $query->select($columns); |
||
76 | |||
77 | $table = $query->getModel()->getTable(); |
||
78 | $hash = $this->getRelationCountHash(); |
||
79 | |||
80 | $query->from("$table as $hash"); |
||
81 | |||
82 | $table = $this->wrap($table); |
||
83 | $hash = $this->wrap($hash); |
||
84 | $lft = $this->wrap($this->parent->getLftName()); |
||
85 | $rgt = $this->wrap($this->parent->getRgtName()); |
||
86 | |||
87 | return $query->whereRaw("{$hash}.{$lft} between {$table}.{$lft} + 1 and {$table}.{$rgt}"); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Get a relationship join table hash. |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getRelationCountHash() |
||
96 | { |
||
97 | return 'self_'.md5(microtime(true)); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Set the base constraints on the relation query. |
||
102 | */ |
||
103 | 36 | public function addConstraints() |
|
111 | |||
112 | /** |
||
113 | * Set the constraints for an eager load of the relation. |
||
114 | * |
||
115 | * @param array $models |
||
116 | */ |
||
117 | public function addEagerConstraints(array $models) |
||
128 | |||
129 | /** |
||
130 | * Initialize the relation on a set of models. |
||
131 | * |
||
132 | * @param array $models |
||
133 | * @param string $relation |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | 3 | public function initRelation(array $models, $relation) |
|
141 | |||
142 | /** |
||
143 | * Match the eagerly loaded results to their parents. |
||
144 | * |
||
145 | * @param array $models |
||
146 | * @param \Illuminate\Database\Eloquent\Collection $results |
||
147 | * @param string $relation |
||
148 | * |
||
149 | * @return array |
||
150 | */ |
||
151 | 3 | public function match(array $models, EloquentCollection $results, $relation) |
|
163 | |||
164 | /** |
||
165 | * Get the results of the relationship. |
||
166 | * |
||
167 | * @return mixed |
||
168 | */ |
||
169 | 3 | public function getResults() |
|
173 | |||
174 | /** |
||
175 | * @param \Illuminate\Database\Eloquent\Model $model |
||
176 | * @param \Illuminate\Database\Eloquent\Collection $results |
||
177 | * |
||
178 | * @return \Arcanedev\LaravelNestedSet\Eloquent\Collection |
||
179 | */ |
||
180 | 3 | protected function getDescendantsForModel(Model $model, EloquentCollection $results) |
|
192 | } |
||
193 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.