|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\MediaBundle\Entity; |
|
15
|
|
|
|
|
16
|
|
|
use Sonata\DatagridBundle\Pager\Doctrine\Pager; |
|
17
|
|
|
use Sonata\DatagridBundle\ProxyQuery\Doctrine\ProxyQuery; |
|
18
|
|
|
use Sonata\Doctrine\Entity\BaseEntityManager; |
|
19
|
|
|
use Sonata\MediaBundle\Model\GalleryInterface; |
|
20
|
|
|
use Sonata\MediaBundle\Model\GalleryManagerInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @final since sonata-project/media-bundle 3.21.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
class GalleryManager extends BaseEntityManager implements GalleryManagerInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* BC Compatibility. |
|
29
|
|
|
* |
|
30
|
|
|
* NEXT_MAJOR: remove this method. |
|
31
|
|
|
* |
|
32
|
|
|
* @deprecated Please use save() from now |
|
33
|
|
|
*/ |
|
34
|
|
|
public function update(GalleryInterface $gallery): void |
|
35
|
|
|
{ |
|
36
|
|
|
parent::save($gallery); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getPager(array $criteria, $page, $limit = 10, array $sort = []) |
|
40
|
|
|
{ |
|
41
|
|
|
$query = $this->getRepository() |
|
42
|
|
|
->createQueryBuilder('g') |
|
43
|
|
|
->select('g'); |
|
44
|
|
|
|
|
45
|
|
|
$fields = $this->getEntityManager()->getClassMetadata($this->class)->getFieldNames(); |
|
46
|
|
|
foreach ($sort as $field => $direction) { |
|
47
|
|
|
if (!\in_array($field, $fields, true)) { |
|
48
|
|
|
throw new \RuntimeException(sprintf("Invalid sort field '%s' in '%s' class", $field, $this->class)); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
if (0 === \count($sort)) { |
|
52
|
|
|
$sort = ['name' => 'ASC']; |
|
53
|
|
|
} |
|
54
|
|
|
foreach ($sort as $field => $direction) { |
|
55
|
|
|
$query->orderBy(sprintf('g.%s', $field), strtoupper($direction)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$parameters = []; |
|
59
|
|
|
|
|
60
|
|
|
if (isset($criteria['enabled'])) { |
|
61
|
|
|
$query->andWhere('g.enabled = :enabled'); |
|
62
|
|
|
$parameters['enabled'] = $criteria['enabled']; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$query->setParameters($parameters); |
|
66
|
|
|
|
|
67
|
|
|
$pager = new Pager(); |
|
68
|
|
|
$pager->setMaxPerPage($limit); |
|
69
|
|
|
$pager->setQuery(new ProxyQuery($query)); |
|
70
|
|
|
$pager->setPage($page); |
|
71
|
|
|
$pager->init(); |
|
72
|
|
|
|
|
73
|
|
|
return $pager; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: