These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Victoire\Bundle\BlogBundle\Repository; |
||
4 | |||
5 | use Doctrine\ORM\EntityRepository; |
||
6 | use Doctrine\ORM\Query; |
||
7 | use Victoire\Bundle\BlogBundle\Entity\Blog; |
||
8 | use Victoire\Bundle\CoreBundle\Repository\StateFullRepositoryTrait; |
||
9 | use Victoire\Bundle\PageBundle\Entity\PageStatus; |
||
10 | |||
11 | /** |
||
12 | * The Article repository. |
||
13 | */ |
||
14 | class ArticleRepository extends EntityRepository |
||
15 | { |
||
16 | use StateFullRepositoryTrait; |
||
17 | |||
18 | /** |
||
19 | * Get all articles in the repository. |
||
20 | * |
||
21 | * @param bool $excludeUnpublished Should we get only the published BasePages ? |
||
22 | * |
||
23 | * @return ArticleRepository |
||
24 | */ |
||
25 | public function getAll($excludeUnpublished = false) |
||
26 | { |
||
27 | $this->clearInstance(); |
||
28 | $this->qb = $this->getInstance(); |
||
29 | |||
30 | //If $excludeUnpublished === true, we exclude the non published results |
||
31 | if ($excludeUnpublished) { |
||
32 | $this->qb |
||
33 | ->andWhere('article.status = :status') |
||
34 | ->orWhere('article.status = :scheduled_status AND article.publishedAt > :publicationDate') |
||
35 | ->setParameter('status', PageStatus::PUBLISHED) |
||
36 | ->setParameter('scheduled_status', PageStatus::SCHEDULED) |
||
37 | ->setParameter('publicationDate', new \DateTime()); |
||
38 | } |
||
39 | |||
40 | return $this; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Filter repositoy by Blog. |
||
45 | * |
||
46 | * @return ArticleRepository |
||
47 | */ |
||
48 | public function filterByBlog(Blog $blog) |
||
49 | { |
||
50 | $this->getInstance() |
||
51 | ->andWhere('article.blog = :blog') |
||
52 | ->setParameter('blog', $blog); |
||
53 | |||
54 | return $this; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Get very next festivals query builder. |
||
59 | * |
||
60 | * @param method $method The method to run |
||
61 | * @param hydrationMode $hydrationMode How the results will be (Object ? Array ) |
||
62 | * |
||
63 | * @return array() |
||
64 | */ |
||
65 | public function run($method = 'getResult', $hydrationMode = Query::HYDRATE_OBJECT) |
||
66 | { |
||
67 | return $this->getInstance()->getQuery()->$method($hydrationMode); |
||
68 | } |
||
69 | |||
70 | public function filterWithListingQuery($listingQuery = null) |
||
71 | { |
||
72 | if ($listingQuery) { |
||
73 | $dql = $this->createQueryBuilder('a_article') |
||
74 | ->leftJoin('a_article.blog', 'blog') |
||
75 | ->getDql(); |
||
76 | $dql = $dql.' '.$listingQuery; |
||
77 | $this->qb |
||
78 | ->andWhere($this->qb->expr()->in('article', $dql)); |
||
79 | } |
||
80 | |||
81 | return $this; |
||
82 | } |
||
83 | |||
84 | View Code Duplication | public function getPreviousRecord($id) |
|
0 ignored issues
–
show
|
|||
85 | { |
||
86 | $queryBuilder = $this->getAll(true) |
||
87 | ->getInstance(); |
||
88 | |||
89 | return $queryBuilder->andWhere($queryBuilder->expr()->lt('article.id', ':id')) |
||
90 | ->setParameter('id', $id) |
||
91 | ->orderBy('article.id', 'DESC') |
||
92 | ->setMaxResults(1) |
||
93 | ->getQuery() |
||
94 | ->getOneOrNullResult(); |
||
95 | } |
||
96 | |||
97 | View Code Duplication | public function getNextRecord($id) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
98 | { |
||
99 | $queryBuilder = $this->getAll(true) |
||
100 | ->getInstance(); |
||
101 | |||
102 | return $queryBuilder->andWhere($queryBuilder->expr()->gt('article.id', ':id')) |
||
103 | ->setParameter('id', $id) |
||
104 | ->orderBy('article.id', 'ASC') |
||
105 | ->setMaxResults(1) |
||
106 | ->getQuery() |
||
107 | ->getOneOrNullResult(); |
||
108 | } |
||
109 | |||
110 | View Code Duplication | public function getVeryFirstRecord() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
111 | { |
||
112 | $queryBuilder = $this->getAll(true) |
||
113 | ->getInstance(); |
||
114 | |||
115 | return $queryBuilder |
||
116 | ->orderBy('article.id', 'ASC') |
||
117 | ->setMaxResults(1) |
||
118 | ->getQuery() |
||
119 | ->getOneOrNullResult(); |
||
120 | } |
||
121 | |||
122 | View Code Duplication | public function getVeryLastRecord() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
123 | { |
||
124 | $queryBuilder = $this->getAll(true) |
||
125 | ->getInstance(); |
||
126 | |||
127 | return $queryBuilder |
||
128 | ->orderBy('article.id', 'DESC') |
||
129 | ->setMaxResults(1) |
||
130 | ->getQuery() |
||
131 | ->getOneOrNullResult(); |
||
132 | } |
||
133 | } |
||
134 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.