mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +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
|
<?php
|
||||||
|
/**
|
||||||
/*
|
|
||||||
* This file is part of Phraseanet
|
* 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
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@@ -11,16 +10,10 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Model\Repositories;
|
namespace Alchemy\Phrasea\Model\Repositories;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Model\Entities\Order;
|
||||||
use Alchemy\Phrasea\Model\Entities\User;
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
use Doctrine\ORM\EntityRepository;
|
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
|
class OrderRepository extends EntityRepository
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -28,7 +21,7 @@ class OrderRepository extends EntityRepository
|
|||||||
*
|
*
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*
|
*
|
||||||
* @return array
|
* @return Order[]
|
||||||
*/
|
*/
|
||||||
public function findByUser(User $user)
|
public function findByUser(User $user)
|
||||||
{
|
{
|
||||||
@@ -43,7 +36,7 @@ class OrderRepository extends EntityRepository
|
|||||||
* @param integer $perPage
|
* @param integer $perPage
|
||||||
* @param string $sort
|
* @param string $sort
|
||||||
*
|
*
|
||||||
* @return array
|
* @return Order[]
|
||||||
*/
|
*/
|
||||||
public function listOrders($baseIds, $offsetStart = 0, $perPage = 20, $sort = "created_on")
|
public function listOrders($baseIds, $offsetStart = 0, $perPage = 20, $sort = "created_on")
|
||||||
{
|
{
|
||||||
@@ -75,25 +68,19 @@ class OrderRepository extends EntityRepository
|
|||||||
*
|
*
|
||||||
* @param array $baseIds
|
* @param array $baseIds
|
||||||
*
|
*
|
||||||
* @return integer
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function countTotalOrders(array $baseIds = [])
|
public function countTotalOrders(array $baseIds = [])
|
||||||
{
|
{
|
||||||
$qb = $this
|
$builder = $this->createQueryBuilder('o');
|
||||||
->createQueryBuilder('o');
|
$builder->select($builder->expr()->countDistinct('o.id'));
|
||||||
$qb->select($qb->expr()->countDistinct('o.id'))
|
|
||||||
->innerJoin('o.elements', 'e');
|
|
||||||
|
|
||||||
if (!empty($baseIds)) {
|
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');
|
return $builder->getQuery()->getSingleScalarResult();
|
||||||
|
|
||||||
try {
|
|
||||||
return $qb->getQuery()->getSingleScalarResult();
|
|
||||||
} catch (NoResultException $e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user