|
- <?php
-
- namespace Lc\SovBundle\Repository;
-
- use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
- use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
- use Doctrine\ORM\AbstractQuery;
- use Doctrine\ORM\Query;
- use Doctrine\ORM\QueryBuilder;
- use Gedmo\Translatable\TranslatableListener;
-
- abstract class AbstractRepository extends ServiceEntityRepository implements ServiceEntityRepositoryInterface,
- AbstractRepositoryInterface
- {
- protected $defaultLocale;
-
- public function setDefaultLocale($locale)
- {
- $this->defaultLocale = $locale;
- }
-
- public function getOneOrNullResult(QueryBuilder $qb, $locale = null, $hydrationMode = null)
- {
- return $this->getTranslatedQuery($qb, $locale)->getOneOrNullResult($hydrationMode);
- }
-
- public function getResult(QueryBuilder $qb, $locale = null, $hydrationMode = AbstractQuery::HYDRATE_OBJECT)
- {
- return $this->getTranslatedQuery($qb, $locale)->getResult($hydrationMode);
- }
-
- public function getArrayResult(QueryBuilder $qb, $locale = null)
- {
- return $this->getTranslatedQuery($qb, $locale)->getArrayResult();
- }
-
- public function getSingleResult(QueryBuilder $qb, $locale = null, $hydrationMode = null)
- {
- return $this->getTranslatedQuery($qb, $locale)->getSingleResult($hydrationMode);
- }
-
- public function getScalarResult(QueryBuilder $qb, $locale = null)
- {
- return $this->getTranslatedQuery($qb, $locale)->getScalarResult();
- }
-
- public function getSingleScalarResult(QueryBuilder $qb, $locale = null)
- {
- return $this->getTranslatedQuery($qb, $locale)->getSingleScalarResult();
- }
-
- protected function getTranslatedQuery(QueryBuilder $qb, $locale = null)
- {
- $locale = null === $locale ? $this->defaultLocale : $locale;
-
- $query = $qb->getQuery();
-
- $query->setHint(
- Query::HINT_CUSTOM_OUTPUT_WALKER,
- 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
- );
-
- $query->setHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, $locale);
-
- return $query;
- }
-
-
-
-
-
-
-
-
-
- }
|