Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 21 |
CRAP | |
0.00% |
0 / 1 |
Question | |
0.00% |
0 / 32 |
|
0.00% |
0 / 21 |
756 | |
0.00% |
0 / 1 |
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIdent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setIdent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQuestion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setQuestion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCategory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setCategory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPositionWithinCategory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setPositionWithinCategory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAnswer | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setAnswer | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEntityNameForStorage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEntityIdForStorage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPositionFieldName | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
getPositionForEntityField | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
getIdFieldNameForSearch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIdForSearch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTitleForSearch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCriteriaForFilter | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
getCriteriaForQuery | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Olz\Entity\Faq; |
4 | |
5 | use Doctrine\Common\Collections\Criteria; |
6 | use Doctrine\Common\Collections\Expr\Expression; |
7 | use Doctrine\ORM\Mapping as ORM; |
8 | use Olz\Entity\Common\DataStorageInterface; |
9 | use Olz\Entity\Common\DataStorageTrait; |
10 | use Olz\Entity\Common\OlzEntity; |
11 | use Olz\Entity\Common\PositionableInterface; |
12 | use Olz\Repository\Faq\QuestionRepository; |
13 | |
14 | #[ORM\Table(name: 'questions')] |
15 | #[ORM\Index(name: 'ident_index', columns: ['on_off', 'ident'])] |
16 | #[ORM\Index(name: 'category_position_index', columns: ['on_off', 'category_id', 'position_within_category'])] |
17 | #[ORM\Entity(repositoryClass: QuestionRepository::class)] |
18 | class Question extends OlzEntity implements DataStorageInterface, PositionableInterface { |
19 | use DataStorageTrait; |
20 | |
21 | #[ORM\Id] |
22 | #[ORM\Column(type: 'integer', nullable: false)] |
23 | #[ORM\GeneratedValue] |
24 | private int $id; |
25 | |
26 | #[ORM\Column(type: 'string', length: 31, nullable: false)] |
27 | private string $ident; |
28 | |
29 | #[ORM\ManyToOne(targetEntity: QuestionCategory::class)] |
30 | #[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id', nullable: true)] |
31 | private ?QuestionCategory $category; |
32 | |
33 | #[ORM\Column(type: 'smallfloat', nullable: false)] |
34 | private float $position_within_category; |
35 | |
36 | #[ORM\Column(type: 'text', nullable: false)] |
37 | private string $question; |
38 | |
39 | #[ORM\Column(type: 'text', nullable: true)] |
40 | private ?string $answer; |
41 | |
42 | public function getId(): ?int { |
43 | return $this->id ?? null; |
44 | } |
45 | |
46 | public function setId(int $new_value): void { |
47 | $this->id = $new_value; |
48 | } |
49 | |
50 | public function getIdent(): string { |
51 | return $this->ident; |
52 | } |
53 | |
54 | public function setIdent(string $new_value): void { |
55 | $this->ident = $new_value; |
56 | } |
57 | |
58 | public function getQuestion(): string { |
59 | return $this->question; |
60 | } |
61 | |
62 | public function setQuestion(string $new_value): void { |
63 | $this->question = $new_value; |
64 | } |
65 | |
66 | public function getCategory(): ?QuestionCategory { |
67 | return $this->category; |
68 | } |
69 | |
70 | public function setCategory(?QuestionCategory $new_value): void { |
71 | $this->category = $new_value; |
72 | } |
73 | |
74 | public function getPositionWithinCategory(): float { |
75 | return $this->position_within_category; |
76 | } |
77 | |
78 | public function setPositionWithinCategory(float $new_value): void { |
79 | $this->position_within_category = $new_value; |
80 | } |
81 | |
82 | public function getAnswer(): ?string { |
83 | return $this->answer; |
84 | } |
85 | |
86 | public function setAnswer(?string $new_value): void { |
87 | $this->answer = $new_value; |
88 | } |
89 | |
90 | // --- |
91 | |
92 | public static function getEntityNameForStorage(): string { |
93 | return 'questions'; |
94 | } |
95 | |
96 | public function getEntityIdForStorage(): string { |
97 | return "{$this->getId()}"; |
98 | } |
99 | |
100 | public static function getPositionFieldName(string $field): string { |
101 | switch ($field) { |
102 | case 'positionWithinCategory': |
103 | return 'position_within_category'; |
104 | default: throw new \Exception("No such position field: {$field}"); |
105 | } |
106 | } |
107 | |
108 | public function getPositionForEntityField(string $field): ?float { |
109 | switch ($field) { |
110 | case 'positionWithinCategory': |
111 | return $this->getPositionWithinCategory(); |
112 | default: throw new \Exception("No such position field: {$field}"); |
113 | } |
114 | } |
115 | |
116 | public static function getIdFieldNameForSearch(): string { |
117 | return 'id'; |
118 | } |
119 | |
120 | public function getIdForSearch(): int { |
121 | return $this->getId() ?? 0; |
122 | } |
123 | |
124 | public function getTitleForSearch(): string { |
125 | return "{$this->getIdent()} - {$this->getQuestion()}"; |
126 | } |
127 | |
128 | public static function getCriteriaForFilter(string $key, string $value): Expression { |
129 | switch ($key) { |
130 | case 'questionCategoryId': |
131 | $category = new QuestionCategory(); |
132 | $category->setId(intval($value)); |
133 | return Criteria::expr()->eq('category', $category); |
134 | default: throw new \Exception("No such Question filter: {$key}"); |
135 | } |
136 | } |
137 | |
138 | public static function getCriteriaForQuery(string $query): Expression { |
139 | return Criteria::expr()->orX( |
140 | Criteria::expr()->contains('ident', $query), |
141 | Criteria::expr()->contains('question', $query), |
142 | ); |
143 | } |
144 | } |