1 | <?php |
||
20 | class TermHierarchyRepository implements TermHierarchyRepositoryInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var array<Vertex> all Vertices (Current and parents) |
||
24 | */ |
||
25 | protected $vertices; |
||
26 | |||
27 | /** |
||
28 | * @var \Illuminate\Cache\Repository The cache to store the terms in. |
||
29 | */ |
||
30 | protected $cache; |
||
31 | |||
32 | /** |
||
33 | * Create a Repository |
||
34 | * |
||
35 | * @param \Illuminate\Cache\Repository $cache |
||
36 | */ |
||
37 | 192 | public function __construct(\Illuminate\Cache\Repository $cache) |
|
41 | |||
42 | /** |
||
43 | * Add a parent to this term. |
||
44 | * |
||
45 | * @param int $term_id The term |
||
46 | * @param int $parent_id The parent term |
||
47 | * @return bool |
||
48 | */ |
||
49 | 111 | public function addParent($term_id, $parent_id) |
|
53 | |||
54 | /** |
||
55 | * Remove this term's parents |
||
56 | * |
||
57 | * @param int $term_id The term |
||
58 | * @return bool |
||
59 | */ |
||
60 | 6 | public function unsetParents($term_id) |
|
64 | |||
65 | /** |
||
66 | * Tests if the driver supports Common Table Expression. |
||
67 | * |
||
68 | * If it doesn't we'll fall back to a manually recursive query. |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | 9 | protected function supportsCommonTableExpressionQuery() |
|
86 | |||
87 | /** |
||
88 | * Get the retriever to get the Term's Hierarchy |
||
89 | * |
||
90 | * @return \Rocket\Taxonomy\Utils\RecursiveQueryInterface |
||
91 | */ |
||
92 | 9 | protected function getRecursiveRetriever() |
|
100 | |||
101 | /** |
||
102 | * Get the hierarchy cache key |
||
103 | * |
||
104 | * @param string $direction The hierarchy's direction |
||
105 | * @param int $id The term's id |
||
106 | * @return string |
||
107 | */ |
||
108 | 12 | protected function getCacheKey($direction, $id) |
|
112 | |||
113 | /** |
||
114 | * Get all parents recursively |
||
115 | * |
||
116 | * @param int $id The term's id |
||
117 | * @return \Illuminate\Support\Collection |
||
118 | */ |
||
119 | 12 | public function getAncestry($id) |
|
130 | |||
131 | /** |
||
132 | * Get all childs recursively. |
||
133 | * |
||
134 | * @param int $id The term's id |
||
135 | * @return \Illuminate\Support\Collection |
||
136 | */ |
||
137 | 12 | public function getDescent($id) |
|
148 | |||
149 | /** |
||
150 | * Prepare the vertices to create the graph. |
||
151 | * |
||
152 | * @param \Illuminate\Support\Collection $data The list of vertices that were retrieved |
||
153 | * @return array<Vertex> |
||
154 | */ |
||
155 | 9 | protected function prepareVertices($data) |
|
175 | |||
176 | /** |
||
177 | * Get all parents recursively |
||
178 | * |
||
179 | * @param int $id The term we want the ancestry from. |
||
180 | * @return array Vertex, DirectedGraph |
||
181 | */ |
||
182 | 12 | public function getAncestryGraph($id) |
|
206 | |||
207 | /** |
||
208 | * Get all childs recursively |
||
209 | * |
||
210 | * @param int $id The term we want the descent from. |
||
211 | * @return array Vertex, DirectedGraph |
||
212 | */ |
||
213 | 12 | public function getDescentGraph($id) |
|
237 | |||
238 | /** |
||
239 | * Get all the possible paths from this term |
||
240 | * |
||
241 | * @param int $id The term we want the ancestry from. |
||
242 | * @return array<array<int>> |
||
243 | */ |
||
244 | 12 | public function getAncestryPaths($id) |
|
256 | |||
257 | /** |
||
258 | * Get all the possible paths from this term |
||
259 | * |
||
260 | * @param int $id The term we want the descent from. |
||
261 | * @return array<array<int>> |
||
262 | */ |
||
263 | 12 | public function getDescentPaths($id) |
|
275 | } |
||
276 |