src/App/Entity/FrequentlyAskedQuestion.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Utility\GuidUtility;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use InvalidArgumentException;
  6. /**
  7. * @ORM\Entity
  8. *
  9. * @ORM\Table(
  10. * name="frequently_asked_questions"
  11. * )
  12. */
  13. class FrequentlyAskedQuestion
  14. {
  15. public const CATEGORY_JOBSEEKER = 0;
  16. public const CATEGORY_JOBOFFERER = 1;
  17. public function __construct(
  18. int $category,
  19. string $subcategory,
  20. string $question,
  21. string $answer
  22. ) {
  23. $this->setCategory($category);
  24. $this->setQuestion($question);
  25. $this->setAnswer($answer);
  26. $this->setSubcategory($subcategory);
  27. }
  28. /**
  29. * @ORM\GeneratedValue(strategy="CUSTOM")
  30. *
  31. * @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
  32. *
  33. * @ORM\Column(name="id", type="guid")
  34. *
  35. * @ORM\Id
  36. */
  37. private string $id;
  38. public function setId(string $id): void
  39. {
  40. GuidUtility::validOrThrow($id);
  41. $this->id = $id;
  42. }
  43. public function getId()
  44. {
  45. return $this->id;
  46. }
  47. /**
  48. * @ORM\Column(name="category", type="integer", nullable=false)
  49. */
  50. private int $category;
  51. public function getCategory(): int
  52. {
  53. return $this->category;
  54. }
  55. public function setCategory(int $category): void
  56. {
  57. if (!in_array($category, [self::CATEGORY_JOBSEEKER, self::CATEGORY_JOBOFFERER])) {
  58. throw new InvalidArgumentException('Category does not exist for FAQ entry');
  59. }
  60. $this->category = $category;
  61. }
  62. /**
  63. * @ORM\Column(name="question", type="string", length=1024, nullable=false)
  64. */
  65. private string $question;
  66. public function getQuestion(): string
  67. {
  68. return $this->question;
  69. }
  70. public function setQuestion(string $question): void
  71. {
  72. $this->question = mb_substr($question, 0, 1023);
  73. }
  74. /**
  75. * @ORM\Column(name="answer", type="string", length=2048, nullable=false)
  76. */
  77. private string $answer;
  78. public function getAnswer(): string
  79. {
  80. return $this->answer;
  81. }
  82. public function setAnswer(string $answer): void
  83. {
  84. $this->answer = mb_substr($answer, 0, 2047);
  85. }
  86. /**
  87. * @ORM\Column(name="subcategory", type="string", length=128, nullable=false)
  88. */
  89. private string $subcategory;
  90. public function getSubcategory(): string
  91. {
  92. return $this->subcategory;
  93. }
  94. public function setSubcategory(string $subcategory): void
  95. {
  96. $this->subcategory = mb_substr($subcategory, 0, 127);
  97. }
  98. }