Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 14 |
CRAP | |
0.00% |
0 / 1 |
| QuestionCategory | |
0.00% |
0 / 18 |
|
0.00% |
0 / 14 |
342 | |
0.00% |
0 / 1 |
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPosition | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setPosition | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| testOnlyGetField | |
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 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCriteriaForQuery | |
0.00% |
0 / 1 |
|
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\OlzEntity; |
| 9 | use Olz\Entity\Common\PositionableInterface; |
| 10 | use Olz\Entity\Common\SearchableInterface; |
| 11 | use Olz\Entity\Common\TestableInterface; |
| 12 | |
| 13 | #[ORM\Table(name: 'question_categories')] |
| 14 | #[ORM\Index(name: 'position_index', columns: ['on_off', 'position'])] |
| 15 | #[ORM\Entity] |
| 16 | class QuestionCategory extends OlzEntity implements PositionableInterface, SearchableInterface, TestableInterface { |
| 17 | #[ORM\Id] |
| 18 | #[ORM\Column(type: 'integer', nullable: false)] |
| 19 | #[ORM\GeneratedValue] |
| 20 | private int $id; |
| 21 | |
| 22 | #[ORM\Column(type: 'smallfloat', nullable: false)] |
| 23 | private float $position; |
| 24 | |
| 25 | #[ORM\Column(type: 'string', nullable: false)] |
| 26 | private string $name; |
| 27 | |
| 28 | public function getId(): ?int { |
| 29 | return $this->id ?? null; |
| 30 | } |
| 31 | |
| 32 | public function setId(int $new_value): void { |
| 33 | $this->id = $new_value; |
| 34 | } |
| 35 | |
| 36 | public function getPosition(): float { |
| 37 | return $this->position; |
| 38 | } |
| 39 | |
| 40 | public function setPosition(float $new_value): void { |
| 41 | $this->position = $new_value; |
| 42 | } |
| 43 | |
| 44 | public function getName(): string { |
| 45 | return $this->name; |
| 46 | } |
| 47 | |
| 48 | public function setName(string $new_value): void { |
| 49 | $this->name = $new_value; |
| 50 | } |
| 51 | |
| 52 | // --- |
| 53 | |
| 54 | public function testOnlyGetField(string $field_name): mixed { |
| 55 | return $this->{$field_name}; |
| 56 | } |
| 57 | |
| 58 | public static function getPositionFieldName(string $field): string { |
| 59 | switch ($field) { |
| 60 | case 'position': |
| 61 | return 'position'; |
| 62 | default: throw new \Exception("No such position field: {$field}"); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | public function getPositionForEntityField(string $field): ?float { |
| 67 | switch ($field) { |
| 68 | case 'position': |
| 69 | return $this->getPosition(); |
| 70 | default: throw new \Exception("No such position field: {$field}"); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | public static function getIdFieldNameForSearch(): string { |
| 75 | return 'id'; |
| 76 | } |
| 77 | |
| 78 | public function getIdForSearch(): int { |
| 79 | return $this->getId() ?? 0; |
| 80 | } |
| 81 | |
| 82 | public function getTitleForSearch(): string { |
| 83 | return $this->getName(); |
| 84 | } |
| 85 | |
| 86 | public static function getCriteriaForFilter(string $key, string $value): Expression { |
| 87 | throw new \Exception("No such QuestionCategory filter: {$key}"); |
| 88 | } |
| 89 | |
| 90 | public static function getCriteriaForQuery(string $query): Expression { |
| 91 | return Criteria::expr()->contains('name', $query); |
| 92 | } |
| 93 | } |