getQueryBuilder() public method

public getQueryBuilder ( ) : Nextras\Dbal\QueryBuilder\QueryBuilder
return Nextras\Dbal\QueryBuilder\QueryBuilder
Example #1
0
 public function sortCollectionByLocales(Nextras\Orm\Mapper\Dbal\DbalCollection $collection, string $column) : Nextras\Orm\Mapper\Dbal\DbalCollection
 {
     $builder = $collection->getQueryBuilder();
     foreach ([$this->translator->getLocale(), $this->translator->getDefaultLocale()] as $locale) {
         $separator = strpos($locale, '_');
         $subLocales = $separator === FALSE ? [$locale] : [$locale, substr($locale, 0, $separator)];
         foreach ($subLocales as $subLocale) {
             $builder->addOrderBy(implode('=', [$column, '%s']) . ' DESC', $subLocale);
         }
     }
     return $collection;
 }
 protected function execute(DbalCollection $collection, IEntity $parent)
 {
     $builder = $collection->getQueryBuilder();
     $preloadIterator = $parent->getPreloadContainer();
     $cacheKey = $this->calculateCacheKey($builder, $preloadIterator, $parent);
     $data =& $this->cacheEntityContainers[$cacheKey];
     if ($data) {
         return $data;
     }
     $values = $preloadIterator ? $preloadIterator->getPreloadValues($this->metadata->name) : [$parent->getRawValue($this->metadata->name)];
     $data = $this->fetch(clone $builder, stripos($cacheKey, 'JOIN') !== FALSE, $values, $preloadIterator);
     return $data;
 }
Example #3
0
 public function sortByParameters(Nextras\Orm\Mapper\Dbal\DbalCollection $collection, array $parameters) : Nextras\Orm\Mapper\Dbal\DbalCollection
 {
     if ($parameters) {
         $builder = $collection->getQueryBuilder();
         $from = 'SELECT "link".* FROM "link" LEFT JOIN link_parameter AS "parameters" ON ("link"."id" = "parameters"."link_id")';
         $order = [];
         foreach ($parameters as $key => $value) {
             $order[] = 'parameters.key=\'' . $key . '\' AND parameters.value ' . ($value === NULL ? 'IS NULL' : '= \'' . (is_scalar($value) ? $value : serialize($value)) . '\' DESC');
         }
         //			dump($order);exit;
         $from .= ' ORDER BY ' . implode(', ', $order);
         $builder->from('(' . $from . ')', $builder->getFromAlias());
     }
     return $collection;
 }
Example #4
0
 /**
  * Sort data
  * @param  Sorting $sorting
  * @return static
  */
 public function sort(Sorting $sorting)
 {
     if (is_callable($sorting->getSortCallback())) {
         call_user_func($sorting->getSortCallback(), $this->data_source, $sorting->getSort());
         return $this;
     }
     $sort = $sorting->getSort();
     if (!empty($sort)) {
         foreach ($sort as $column => $order) {
             $this->data_source = $this->data_source->orderBy($column, $order);
         }
     } else {
         /**
          * Has the statement already a order by clause?
          */
         $order = $this->data_source->getQueryBuilder()->getClause('order');
         if (ArraysHelper::testEmpty($order)) {
             $this->data_source = $this->data_source->orderBy($this->primary_key);
         }
     }
     return $this;
 }
 protected function executeCounts(DbalCollection $collection, IEntity $parent)
 {
     $builder = $collection->getQueryBuilder();
     $preloadIterator = $parent->getPreloadContainer();
     $values = $preloadIterator ? $preloadIterator->getPreloadValues('id') : [$parent->getValue('id')];
     $cacheKey = $this->calculateCacheKey($builder, $values);
     $data =& $this->cacheCounts[$cacheKey];
     if ($data !== NULL) {
         return $data;
     }
     $data = $this->fetchCounts($builder, $values);
     return $data;
 }