Completed
Push — master ( 3a864f...49d434 )
by Rafał
06:22 queued 03:09
created

TranslationRepository::setTranslatableHints()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 2
eloc 16
nc 2
nop 2
1
<?php
2
3
/**
4
 * @author Rafał Muszyński <[email protected]>
5
 * @copyright 2015 Sourcefabric z.ú.
6
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
7
 */
8
9
namespace Newscoop\PaywallBundle\Entity\Repository;
10
11
use Gedmo\Translatable\Entity\Repository\TranslationRepository as BaseRepository;
12
use Gedmo\Translatable\TranslatableListener;
13
use Doctrine\ORM\Query;
14
15
/**
16
 * Translation repository.
17
 */
18
class TranslationRepository extends BaseRepository
19
{
20
    /**
21
     * Add hints to the query.
22
     *
23
     * @param Query  $query  Query
24
     * @param string|null $locale Locale to which it should fallback
25
     *
26
     * @return Query
27
     */
28
    public function setTranslatableHints(Query $query, $locale = null)
29
    {
30
        // fallback to english by default
31
        if (null === $locale) {
32
            $locale = 'en';
33
        }
34
35
        $query->setHint(
36
            Query::HINT_CUSTOM_OUTPUT_WALKER,
37
            'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
38
        );
39
        $query->setHint(
40
            TranslatableListener::HINT_INNER_JOIN,
41
            false
42
        );
43
        $query->setHint(
44
            TranslatableListener::HINT_TRANSLATABLE_LOCALE,
45
            $locale
46
        );
47
        $query->setHint(
48
            TranslatableListener::HINT_FALLBACK,
49
            true
50
        );
51
52
        return $query;
53
    }
54
}
55