Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
QuestionRepository
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 getPredefinedQuestion
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 search
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Olz\Repository\Faq;
4
5use Doctrine\Common\Collections\Collection;
6use Doctrine\Common\Collections\Criteria;
7use Olz\Entity\Faq\Question;
8use Olz\Repository\Common\OlzRepository;
9
10/**
11 * @extends OlzRepository<Question>
12 */
13class QuestionRepository extends OlzRepository {
14    protected string $entityClass = Question::class;
15
16    public function getPredefinedQuestion(PredefinedQuestion $predefined_question): ?Question {
17        $question = $this->findOneBy(['ident' => $predefined_question->value]);
18        if (!$question) {
19            $this->log()->warning("Predefined question does not exist: {$predefined_question->value}");
20        }
21        return $question;
22    }
23
24    /**
25     * @param string[] $terms
26     *
27     * @return Collection<int, Question>&iterable<Question>
28     */
29    public function search(array $terms): Collection {
30        $criteria = Criteria::create()
31            ->where(Criteria::expr()->andX(
32                Criteria::expr()->eq('on_off', 1),
33                ...array_map(fn ($term) => Criteria::expr()->orX(
34                    Criteria::expr()->contains('ident', $term),
35                    Criteria::expr()->contains('question', $term),
36                    Criteria::expr()->contains('answer', $term),
37                ), $terms),
38            ))
39            ->setFirstResult(0)
40            ->setMaxResults(1000000)
41        ;
42        return $this->matching($criteria);
43    }
44}