Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| WeeklyPictureRepository | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| getLatestThree | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| search | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Repository\Startseite; |
| 4 | |
| 5 | use Doctrine\Common\Collections\Collection; |
| 6 | use Doctrine\Common\Collections\Criteria; |
| 7 | use Doctrine\Common\Collections\Order; |
| 8 | use Olz\Entity\Startseite\WeeklyPicture; |
| 9 | use Olz\Repository\Common\OlzRepository; |
| 10 | |
| 11 | /** |
| 12 | * @extends OlzRepository<WeeklyPicture> |
| 13 | */ |
| 14 | class WeeklyPictureRepository extends OlzRepository { |
| 15 | protected string $entityClass = WeeklyPicture::class; |
| 16 | |
| 17 | /** @return array<WeeklyPicture> */ |
| 18 | public function getLatestThree(): array { |
| 19 | $dql = " |
| 20 | SELECT wp |
| 21 | FROM {$this->entityClass} wp |
| 22 | WHERE wp.on_off = 1 |
| 23 | ORDER BY wp.datum DESC |
| 24 | "; |
| 25 | $query = $this->getEntityManager()->createQuery($dql)->setMaxResults(3); |
| 26 | return $query->getResult(); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @param string[] $terms |
| 31 | * |
| 32 | * @return Collection<int, WeeklyPicture>&iterable<WeeklyPicture> |
| 33 | */ |
| 34 | public function search(array $terms): Collection { |
| 35 | $archive_threshold = $this->dateUtils()->getIsoArchiveThreshold(); |
| 36 | $is_not_archived = Criteria::expr()->gte('datum', new \DateTime($archive_threshold)); |
| 37 | $criteria = Criteria::create() |
| 38 | ->where(Criteria::expr()->andX( |
| 39 | $is_not_archived, |
| 40 | Criteria::expr()->eq('on_off', 1), |
| 41 | ...array_map(fn ($term) => Criteria::expr()->contains('text', $term), $terms), |
| 42 | )) |
| 43 | ->orderBy([ |
| 44 | 'datum' => Order::Descending, |
| 45 | ]) |
| 46 | ->setFirstResult(0) |
| 47 | ->setMaxResults(1000000) |
| 48 | ; |
| 49 | return $this->matching($criteria); |
| 50 | } |
| 51 | } |