1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher Content 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\ContentBundle\Doctrine\ORM; |
18
|
|
|
|
19
|
|
|
use Doctrine\ORM\QueryBuilder; |
20
|
|
|
use SWP\Component\Common\Criteria\Criteria; |
21
|
|
|
use SWP\Bundle\ContentBundle\Doctrine\ArticleRepositoryInterface; |
22
|
|
|
use SWP\Bundle\ContentBundle\Model\ArticleInterface; |
23
|
|
|
use SWP\Bundle\StorageBundle\Doctrine\ORM\EntityRepository; |
24
|
|
|
|
25
|
|
|
class ArticleRepository extends EntityRepository implements ArticleRepositoryInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
4 |
|
public function findOneBySlug($slug) |
31
|
|
|
{ |
32
|
4 |
|
return $this->findOneBy([ |
33
|
4 |
|
'slug' => $slug, |
34
|
|
|
]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function findAllArticles() |
41
|
|
|
{ |
42
|
|
|
return $this->getQueryByCriteria(new Criteria(), [], 'a')->getQuery()->getResult(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
12 |
|
public function getByCriteria(Criteria $criteria, array $sorting): QueryBuilder |
49
|
|
|
{ |
50
|
12 |
|
$qb = $this->getQueryByCriteria($criteria, $sorting, 'a'); |
51
|
12 |
|
$qb->andWhere('a.status = :status') |
52
|
12 |
|
->setParameter('status', $criteria->get('status', ArticleInterface::STATUS_PUBLISHED)); |
53
|
|
|
|
54
|
12 |
|
return $qb; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
2 |
|
public function countByCriteria(Criteria $criteria): int |
61
|
|
|
{ |
62
|
2 |
|
$qb = $this->createQueryBuilder('a') |
63
|
2 |
|
->select('COUNT(a.id)') |
64
|
2 |
|
->where('a.status = :status') |
65
|
2 |
|
->setParameter('status', $criteria->get('status', ArticleInterface::STATUS_PUBLISHED)); |
66
|
|
|
|
67
|
2 |
|
$this->applyCriteria($qb, $criteria, 'a'); |
68
|
|
|
|
69
|
2 |
|
return (int) $qb->getQuery()->getSingleScalarResult(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string $identifier |
74
|
|
|
* @param array $order |
75
|
|
|
* |
76
|
|
|
* @return SqlQuery |
77
|
|
|
* |
78
|
|
|
* @throws \Exception |
79
|
|
|
*/ |
80
|
|
|
public function getQueryForRouteArticles(string $identifier, array $order = []) |
81
|
|
|
{ |
82
|
|
|
throw new \Exception('Not implemented'); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|