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