mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Merge pull request #1694 from bburnichon/bugfix/multiple-orders-PHRAS-960
Change bad SQL query which not always is scalar
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -11,16 +10,10 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Model\Repositories;
|
||||
|
||||
use Alchemy\Phrasea\Model\Entities\Order;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
|
||||
/**
|
||||
* OrderRepository
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class OrderRepository extends EntityRepository
|
||||
{
|
||||
/**
|
||||
@@ -28,7 +21,7 @@ class OrderRepository extends EntityRepository
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return array
|
||||
* @return Order[]
|
||||
*/
|
||||
public function findByUser(User $user)
|
||||
{
|
||||
@@ -43,7 +36,7 @@ class OrderRepository extends EntityRepository
|
||||
* @param integer $perPage
|
||||
* @param string $sort
|
||||
*
|
||||
* @return array
|
||||
* @return Order[]
|
||||
*/
|
||||
public function listOrders($baseIds, $offsetStart = 0, $perPage = 20, $sort = "created_on")
|
||||
{
|
||||
@@ -75,25 +68,19 @@ class OrderRepository extends EntityRepository
|
||||
*
|
||||
* @param array $baseIds
|
||||
*
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function countTotalOrders(array $baseIds = [])
|
||||
{
|
||||
$qb = $this
|
||||
->createQueryBuilder('o');
|
||||
$qb->select($qb->expr()->countDistinct('o.id'))
|
||||
->innerJoin('o.elements', 'e');
|
||||
$builder = $this->createQueryBuilder('o');
|
||||
$builder->select($builder->expr()->countDistinct('o.id'));
|
||||
|
||||
if (!empty($baseIds)) {
|
||||
$qb->where($qb->expr()->in('e.baseId', $baseIds));
|
||||
$builder
|
||||
->innerJoin('o.elements', 'e')
|
||||
->where($builder->expr()->in('e.baseId', $baseIds));
|
||||
}
|
||||
|
||||
$qb->groupBy('o.id');
|
||||
|
||||
try {
|
||||
return $qb->getQuery()->getSingleScalarResult();
|
||||
} catch (NoResultException $e) {
|
||||
return 0;
|
||||
}
|
||||
return $builder->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user