1 | <?php |
||
18 | class NodeTranslationRepository extends EntityRepository |
||
19 | { |
||
20 | /** |
||
21 | * Get the QueryBuilder based on node id and language. |
||
22 | * |
||
23 | * @param int $nodeId |
||
24 | * @param string $lang |
||
25 | * |
||
26 | * @return array_shift($result) |
||
|
|||
27 | */ |
||
28 | public function getNodeTranslationByNodeIdQueryBuilder($nodeId, $lang) |
||
44 | |||
45 | /** |
||
46 | * Get max children weight |
||
47 | * |
||
48 | * @param Node $parentNode |
||
49 | * @param string $lang (optional) Only return max weight for the |
||
50 | * given language |
||
51 | * |
||
52 | * @return int |
||
53 | */ |
||
54 | public function getMaxChildrenWeight(Node $parentNode = null, $lang = null) |
||
65 | |||
66 | /** |
||
67 | * QueryBuilder to fetch node translations (ignoring nodes that have been |
||
68 | * deleted) |
||
69 | * |
||
70 | * @param string $lang (optional) Only return NodeTranslations for the |
||
71 | * given language |
||
72 | * |
||
73 | * @return \Doctrine\ORM\QueryBuilder |
||
74 | */ |
||
75 | public function getNodeTranslationsQueryBuilder($lang = null) |
||
98 | |||
99 | /** |
||
100 | * QueryBuilder to fetch node translations that are currently published |
||
101 | * (ignoring nodes that have been deleted) |
||
102 | * |
||
103 | * @param string $lang (optional) Only return NodeTranslations for the |
||
104 | * given language |
||
105 | * |
||
106 | * @return \Doctrine\ORM\QueryBuilder |
||
107 | */ |
||
108 | public function getOnlineNodeTranslationsQueryBuilder($lang = null) |
||
113 | |||
114 | /** |
||
115 | * QueryBuilder to fetch immediate child NodeTranslations for a specific |
||
116 | * node and (optional) language |
||
117 | * |
||
118 | * @return \Doctrine\ORM\QueryBuilder |
||
119 | */ |
||
120 | public function getChildrenQueryBuilder(Node $parent, $lang = null) |
||
126 | |||
127 | /** |
||
128 | * QueryBuilder to fetch immediate child NodeTranslations for a specific |
||
129 | * node and (optional) language that are currently published |
||
130 | * |
||
131 | * @return \Doctrine\ORM\QueryBuilder |
||
132 | */ |
||
133 | public function getOnlineChildrenQueryBuilder(Node $parent, $lang = null) |
||
138 | |||
139 | /** |
||
140 | * Get all online child node translations for a given node and (optional) |
||
141 | * language |
||
142 | * |
||
143 | * @param Node $parent |
||
144 | * @param string $lang (optional, if not specified all languages will be |
||
145 | * returned) |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | public function getOnlineChildren(Node $parent, $lang = null) |
||
154 | |||
155 | /** |
||
156 | * Finds all nodetranslations where title is like the given $title parameter |
||
157 | * |
||
158 | * |
||
159 | * @param string $title |
||
160 | * @param string $lang (optional, if not specified all languages will be |
||
161 | * returned) |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | public function getNodeTranslationsLikeTitle($title, $lang = null) |
||
174 | |||
175 | /** |
||
176 | * Get the node translation for a node |
||
177 | * |
||
178 | * @param HasNodeInterface $hasNode |
||
179 | * |
||
180 | * @return NodeTranslation |
||
181 | */ |
||
182 | public function getNodeTranslationFor(HasNodeInterface $hasNode) |
||
195 | |||
196 | /** |
||
197 | * Get the node translation for a given slug string |
||
198 | * |
||
199 | * @param string $slug The slug |
||
200 | * @param NodeTranslation|null $parentNode The parentnode |
||
201 | * |
||
202 | * @return NodeTranslation|null |
||
203 | */ |
||
204 | public function getNodeTranslationForSlug( |
||
220 | |||
221 | /** |
||
222 | * Returns the node translation for a given slug |
||
223 | * |
||
224 | * @param NodeTranslation|null $parentNode The parentNode |
||
225 | * @param string $slugPart The slug part |
||
226 | * |
||
227 | * @return NodeTranslation|null |
||
228 | */ |
||
229 | private function getNodeTranslationForSlugPart( |
||
264 | |||
265 | /** |
||
266 | * Get the node translation for a given url |
||
267 | * |
||
268 | * @param string $urlSlug The full url |
||
269 | * @param string $locale The locale |
||
270 | * @param bool $includeDeleted Include deleted nodes |
||
271 | * @param NodeTranslation $toExclude Optional NodeTranslation instance |
||
272 | * you wish to exclude |
||
273 | * @param Node $rootNode Optional Root node of the tree you |
||
274 | * wish to use |
||
275 | * |
||
276 | * @return array |
||
277 | */ |
||
278 | public function getAllNodeTranslationsForUrl( |
||
328 | |||
329 | /** |
||
330 | * Get the node translation for a given url |
||
331 | * |
||
332 | * @param string $urlSlug The full url |
||
333 | * @param string $locale The locale |
||
334 | * @param bool $includeDeleted Include deleted nodes |
||
335 | * @param NodeTranslation $toExclude Optional NodeTranslation instance |
||
336 | * you wish to exclude |
||
337 | * @param Node $rootNode Optional Root node of the tree you |
||
338 | * wish to use |
||
339 | * |
||
340 | * @return NodeTranslation|null |
||
341 | */ |
||
342 | public function getNodeTranslationForUrl( |
||
357 | |||
358 | /** |
||
359 | * Get all top node translations |
||
360 | * |
||
361 | * @return NodeTranslation[] |
||
362 | */ |
||
363 | public function getTopNodeTranslations() |
||
379 | |||
380 | /** |
||
381 | * Create a node translation for a given node |
||
382 | * |
||
383 | * @param HasNodeInterface $hasNode The hasNode |
||
384 | * @param string $lang The locale |
||
385 | * @param Node $node The node |
||
386 | * @param BaseUser $owner The user |
||
387 | * |
||
388 | * @throws \InvalidArgumentException |
||
389 | * |
||
390 | * @return NodeTranslation |
||
391 | */ |
||
392 | public function createNodeTranslationFor( |
||
433 | |||
434 | /** |
||
435 | * Add a draft node version for a given node |
||
436 | * |
||
437 | * @param HasNodeInterface $hasNode The hasNode |
||
438 | * @param string $lang The locale |
||
439 | * @param Node $node The node |
||
440 | * @param BaseUser $owner The user |
||
441 | * |
||
442 | * @throws \InvalidArgumentException |
||
443 | * |
||
444 | * @return NodeTranslation |
||
445 | */ |
||
446 | public function addDraftNodeVersionFor( |
||
477 | |||
478 | /** |
||
479 | * Find best match for given URL and locale |
||
480 | * |
||
481 | * @param string $urlSlug The slug |
||
482 | * @param string $locale The locale |
||
483 | * |
||
484 | * @return NodeTranslation |
||
485 | */ |
||
486 | public function getBestMatchForUrl($urlSlug, $locale) |
||
487 | { |
||
488 | $em = $this->getEntityManager(); |
||
489 | |||
490 | $rsm = new ResultSetMappingBuilder($em); |
||
491 | $rsm->addRootEntityFromClassMetadata( |
||
492 | 'Kunstmaan\NodeBundle\Entity\NodeTranslation', |
||
493 | 'nt' |
||
494 | ); |
||
495 | |||
496 | $query = $em |
||
497 | ->createNativeQuery( |
||
498 | 'select nt.* |
||
499 | from kuma_node_translations nt |
||
500 | join kuma_nodes n on n.id = nt.node_id |
||
501 | where n.deleted = 0 and nt.lang = :lang and locate(nt.url, :url) = 1 |
||
502 | order by length(nt.url) desc limit 1', |
||
503 | $rsm |
||
504 | ); |
||
505 | $query->setParameter('lang', $locale); |
||
506 | $query->setParameter('url', $urlSlug); |
||
507 | |||
508 | return $query->getOneOrNullResult(); |
||
509 | } |
||
510 | |||
511 | /** |
||
512 | * Test if all parents of the specified NodeTranslation have a node |
||
513 | * translation for the specified language |
||
514 | * |
||
515 | * @param NodeTranslation $nodeTranslation The node translation |
||
516 | * @param string $language The locale |
||
517 | * |
||
518 | * @return bool |
||
519 | */ |
||
520 | public function hasParentNodeTranslationsForLanguage( |
||
542 | |||
543 | /** |
||
544 | * This will return 1 NodeTranslation by default (if one exists). |
||
545 | * Just give it the internal name as defined on the Node in the database |
||
546 | * and the language. |
||
547 | * |
||
548 | * It'll only return the latest version. It'll also hide deleted & offline |
||
549 | * nodes. |
||
550 | * |
||
551 | * @param $language |
||
552 | * @param $internalName |
||
553 | */ |
||
554 | public function getNodeTranslationByLanguageAndInternalName( |
||
580 | |||
581 | public function getAllNodeTranslationsByRefEntityName($refEntityName) |
||
592 | |||
593 | public function getParentNodeTranslation(NodeTranslation $nodeTranslation) |
||
612 | } |
||
613 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.