|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Superdesk Web Publisher Content List Bundle. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright 2016 Sourcefabric z.ú. and contributors. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please see the |
|
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright 2016 Sourcefabric z.ú |
|
14
|
|
|
* @license http://www.superdesk.org/license |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace SWP\Bundle\ContentListBundle\Doctrine\ORM; |
|
18
|
|
|
|
|
19
|
|
|
use SWP\Bundle\CoreBundle\Pagination\Paginator; |
|
20
|
|
|
use SWP\Component\Common\Criteria\Criteria; |
|
21
|
|
|
use SWP\Component\Common\Pagination\PaginationData; |
|
22
|
|
|
use SWP\Component\ContentList\Model\ContentListInterface; |
|
23
|
|
|
use SWP\Component\ContentList\Repository\ContentListItemRepositoryInterface; |
|
24
|
|
|
use SWP\Bundle\StorageBundle\Doctrine\ORM\SortableEntityRepository; |
|
25
|
|
|
use SWP\Component\Storage\Repository\RepositoryInterface; |
|
26
|
|
|
|
|
27
|
|
|
class ContentListItemRepository extends SortableEntityRepository implements ContentListItemRepositoryInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function removeItems(ContentListInterface $contentList) |
|
33
|
|
|
{ |
|
34
|
|
|
$queryBuilder = $this->createQueryBuilder('i') |
|
35
|
|
|
->delete() |
|
36
|
|
|
->where('i.contentList = :contentList') |
|
37
|
|
|
->setParameter('contentList', $contentList); |
|
38
|
|
|
|
|
39
|
|
|
$queryBuilder->getQuery()->execute(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getSortedItems(Criteria $criteria, array $sorting = [], array $groupValues = []) |
|
46
|
|
|
{ |
|
47
|
|
|
$queryBuilder = parent::getBySortableGroupsQueryBuilder($groupValues); |
|
|
|
|
|
|
48
|
|
|
$this->applyCriteria($queryBuilder, $criteria, 'n'); |
|
49
|
|
|
$queryBuilder->resetDQLPart('orderBy'); |
|
50
|
|
|
$this->applySorting($queryBuilder, $sorting, 'n'); |
|
51
|
|
|
$queryBuilder->addOrderBy('n.position'); |
|
52
|
|
|
$this->applyLimiting($queryBuilder, $criteria); |
|
53
|
|
|
|
|
54
|
|
|
return $queryBuilder; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getPaginatedByCriteria(Criteria $criteria, array $sorting = [], PaginationData $paginationData = null) |
|
61
|
|
|
{ |
|
62
|
|
|
$queryBuilder = $this->getSortedItems($criteria, $sorting, ['contentList' => $criteria->get('contentList')]); |
|
63
|
|
|
|
|
64
|
|
|
if ($criteria->has('exclude_content')) { |
|
65
|
|
|
$excludeContent = $criteria->get('exclude_content'); |
|
66
|
|
|
if (\is_numeric($excludeContent)) { |
|
67
|
|
|
$excludeContent = [$excludeContent]; |
|
68
|
|
|
} |
|
69
|
|
|
$queryBuilder->andWhere($queryBuilder->expr()->notIn('n.content', $excludeContent)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
if (null === $paginationData) { |
|
73
|
|
|
$paginator = new Paginator(); |
|
74
|
|
|
|
|
75
|
|
|
return $paginator->paginate( |
|
76
|
|
|
$queryBuilder, |
|
77
|
|
|
$criteria->get('firstResult', 0), |
|
78
|
|
|
$criteria->get('maxResults', RepositoryInterface::MAX_RESULTS) |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $this->getPaginator($queryBuilder, $paginationData); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
View Code Duplication |
public function getCountByCriteria(Criteria $criteria): int |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
return (int) $this->getQueryByCriteria($criteria, $criteria->get('order', []), 'n') |
|
88
|
|
|
->select('COUNT(n.id)') |
|
89
|
|
|
->setFirstResult(null) |
|
90
|
|
|
->setMaxResults(null) |
|
91
|
|
|
->getQuery() |
|
92
|
|
|
->getSingleScalarResult(); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.