Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| NewsRepository | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| getAllActive | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| search | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Repository\News; |
| 4 | |
| 5 | use Doctrine\Common\Collections\Collection; |
| 6 | use Doctrine\Common\Collections\Criteria; |
| 7 | use Doctrine\Common\Collections\Order; |
| 8 | use Olz\Entity\News\NewsEntry; |
| 9 | use Olz\Repository\Common\OlzRepository; |
| 10 | |
| 11 | /** |
| 12 | * @extends OlzRepository<NewsEntry> |
| 13 | */ |
| 14 | class NewsRepository extends OlzRepository { |
| 15 | /** @return Collection<int, NewsEntry>&iterable<NewsEntry> */ |
| 16 | public function getAllActive(): Collection { |
| 17 | $news_utils = $this->newsUtils(); |
| 18 | $is_not_archived = $news_utils->getIsNotArchivedCriteria(); |
| 19 | $criteria = Criteria::create() |
| 20 | ->where(Criteria::expr()->andX( |
| 21 | $is_not_archived, |
| 22 | Criteria::expr()->eq('on_off', 1), |
| 23 | )) |
| 24 | ->setFirstResult(0) |
| 25 | ->setMaxResults(1000000) |
| 26 | ; |
| 27 | return $this->matching($criteria); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @param string[] $terms |
| 32 | * |
| 33 | * @return Collection<int, NewsEntry>&iterable<NewsEntry> |
| 34 | */ |
| 35 | public function search(array $terms): Collection { |
| 36 | $news_utils = $this->newsUtils(); |
| 37 | $is_not_archived = $news_utils->getIsNotArchivedCriteria(); |
| 38 | $criteria = Criteria::create() |
| 39 | ->where(Criteria::expr()->andX( |
| 40 | $is_not_archived, |
| 41 | Criteria::expr()->eq('on_off', 1), |
| 42 | ...array_map(fn ($term) => Criteria::expr()->orX( |
| 43 | Criteria::expr()->contains('title', $term), |
| 44 | Criteria::expr()->contains('teaser', $term), |
| 45 | Criteria::expr()->contains('content', $term), |
| 46 | ...$this->searchUtils()->getDateCriteria('published_date', $term), |
| 47 | ), $terms), |
| 48 | )) |
| 49 | ->orderBy([ |
| 50 | 'published_date' => Order::Descending, |
| 51 | 'published_time' => Order::Descending, |
| 52 | ]) |
| 53 | ->setFirstResult(0) |
| 54 | ->setMaxResults(1000000) |
| 55 | ; |
| 56 | return $this->matching($criteria); |
| 57 | } |
| 58 | } |