<?php
namespace App\Entity;
use App\Utility\GuidUtility;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="frequently_asked_questions"
* )
*/
class FrequentlyAskedQuestion
{
public const CATEGORY_JOBSEEKER = 0;
public const CATEGORY_JOBOFFERER = 1;
public function __construct(
int $category,
string $subcategory,
string $question,
string $answer
) {
$this->setCategory($category);
$this->setQuestion($question);
$this->setAnswer($answer);
$this->setSubcategory($subcategory);
}
/**
* @ORM\GeneratedValue(strategy="CUSTOM")
*
* @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
*
* @ORM\Column(name="id", type="guid")
*
* @ORM\Id
*/
private string $id;
public function setId(string $id): void
{
GuidUtility::validOrThrow($id);
$this->id = $id;
}
public function getId()
{
return $this->id;
}
/**
* @ORM\Column(name="category", type="integer", nullable=false)
*/
private int $category;
public function getCategory(): int
{
return $this->category;
}
public function setCategory(int $category): void
{
if (!in_array($category, [self::CATEGORY_JOBSEEKER, self::CATEGORY_JOBOFFERER])) {
throw new InvalidArgumentException('Category does not exist for FAQ entry');
}
$this->category = $category;
}
/**
* @ORM\Column(name="question", type="string", length=1024, nullable=false)
*/
private string $question;
public function getQuestion(): string
{
return $this->question;
}
public function setQuestion(string $question): void
{
$this->question = mb_substr($question, 0, 1023);
}
/**
* @ORM\Column(name="answer", type="string", length=2048, nullable=false)
*/
private string $answer;
public function getAnswer(): string
{
return $this->answer;
}
public function setAnswer(string $answer): void
{
$this->answer = mb_substr($answer, 0, 2047);
}
/**
* @ORM\Column(name="subcategory", type="string", length=128, nullable=false)
*/
private string $subcategory;
public function getSubcategory(): string
{
return $this->subcategory;
}
public function setSubcategory(string $subcategory): void
{
$this->subcategory = mb_substr($subcategory, 0, 127);
}
}