Fix on Published Events Query

Changed tags join condition from inner
to left

Change-Id: I0e03de15d48fb5fad7f5c9b531baa57c61827243
This commit is contained in:
Sebastian Marcet 2017-12-07 12:10:40 -03:00
parent 3cd6b2685d
commit 86375bd3da
3 changed files with 51 additions and 4 deletions

View File

@ -24,7 +24,7 @@ class DoctrineJoinFilterMapping extends FilterMapping
/**
* @var string
*/
private $alias;
protected $alias;
/**
* DoctrineJoinFilterMapping constructor.

View File

@ -0,0 +1,47 @@
<?php namespace utils;
/**
* Copyright 2017 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
/**
* Class DoctrineLeftJoinFilterMapping
* @package utils
*/
class DoctrineLeftJoinFilterMapping extends DoctrineJoinFilterMapping
{
/**
* @param QueryBuilder $query
* @param FilterElement $filter
* @return QueryBuilder
*/
public function apply(QueryBuilder $query, FilterElement $filter){
$where = str_replace(":value", $filter->getValue(), $this->where);
$where = str_replace(":operator", $filter->getOperator(), $where);
if(!in_array($this->alias, $query->getAllAliases()))
$query->leftJoin($this->table, $this->alias, Join::WITH);
return $query->andWhere($where);
}
/**
* @param QueryBuilder $query
* @param FilterElement $filter
* @return string
*/
public function applyOr(QueryBuilder $query, FilterElement $filter){
$where = str_replace(":value", $filter->getValue(), $this->where);
$where = str_replace(":operator", $filter->getOperator(), $where);
if(!in_array($this->alias, $query->getAllAliases()))
$query->leftJoin($this->table, $this->alias, Join::WITH);
return $where;
}
}

View File

@ -26,7 +26,7 @@ use utils\Order;
use utils\PagingInfo;
use utils\PagingResponse;
use Doctrine\ORM\Query\Expr\Join;
use utils\DoctrineLeftJoinFilterMapping;
/**
* Class DoctrineSummitEventRepository
* @package App\Repositories\Summit
@ -75,7 +75,7 @@ final class DoctrineSummitEventRepository
'published' => 'e.published',
'start_date' => 'e.start_date:datetime_epoch',
'end_date' => 'e.end_date:datetime_epoch',
'tags' => new DoctrineJoinFilterMapping
'tags' => new DoctrineLeftJoinFilterMapping
(
'e.tags',
't',
@ -192,8 +192,8 @@ final class DoctrineSummitEventRepository
}
if($class == \models\summit\Presentation::class) {
$query = $query->innerJoin("e.speakers", "sp", Join::WITH);
$query = $query->innerJoin("e.category", "cc", Join::WITH);
$query = $query->leftJoin("e.speakers", "sp", Join::WITH);
$query = $query->leftJoin('e.selected_presentations', "ssp", Join::LEFT_JOIN);
$query = $query->leftJoin('ssp.list', "sspl", Join::LEFT_JOIN);
$query = $query->leftJoin('e.moderator', "spm", Join::LEFT_JOIN);