src/Entity/Answer.php line 11

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AnswerRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Timestampable\Traits\TimestampableEntity;
  7. #[ORM\Entity(AnswerRepository::class)]
  8. class Answer
  9. {
  10.     use TimestampableEntity;
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id;
  15.     #[ORM\Column(typeTypes::TEXT)]
  16.     private ?string $answer;
  17.     #[ORM\ManyToOne(inversedBy'answers')]
  18.     #[ORM\JoinColumn(nullablefalse)]
  19.     private ?Question $question;
  20.     #[ORM\ManyToOne(inversedBy'answers')]
  21.     #[ORM\JoinColumn(nullablefalse)]
  22.     private ?User $answeredBy;
  23.     #[ORM\Column]
  24.     private int $votes 0;
  25.     public function __toString(): string
  26.     {
  27.         return $this->getId();
  28.     }
  29.     public function getId(): ?int
  30.     {
  31.         return $this->id;
  32.     }
  33.     public function getAnswer(): ?string
  34.     {
  35.         return $this->answer;
  36.     }
  37.     public function setAnswer(string $answer): self
  38.     {
  39.         $this->answer $answer;
  40.         return $this;
  41.     }
  42.     public function getQuestion(): ?Question
  43.     {
  44.         return $this->question;
  45.     }
  46.     public function setQuestion(?Question $question): self
  47.     {
  48.         $this->question $question;
  49.         return $this;
  50.     }
  51.     public function getAnsweredBy(): ?User
  52.     {
  53.         return $this->answeredBy;
  54.     }
  55.     public function setAnsweredBy(?User $answeredBy): self
  56.     {
  57.         $this->answeredBy $answeredBy;
  58.         return $this;
  59.     }
  60.     public function getVotes(): int
  61.     {
  62.         return $this->votes;
  63.     }
  64.     public function getVotesString(): string
  65.     {
  66.         $prefix $this->getVotes() >= '+' '-';
  67.         return sprintf('%s %d'$prefixabs($this->getVotes()));
  68.     }
  69.     public function setVotes(int $votes): self
  70.     {
  71.         $this->votes $votes;
  72.         return $this;
  73.     }
  74. }