src/Entity/Answer.php line 11

Open in your IDE?
  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 getId(): ?int
  26.     {
  27.         return $this->id;
  28.     }
  29.     public function getAnswer(): ?string
  30.     {
  31.         return $this->answer;
  32.     }
  33.     public function setAnswer(string $answer): self
  34.     {
  35.         $this->answer $answer;
  36.         return $this;
  37.     }
  38.     public function getQuestion(): ?Question
  39.     {
  40.         return $this->question;
  41.     }
  42.     public function setQuestion(?Question $question): self
  43.     {
  44.         $this->question $question;
  45.         return $this;
  46.     }
  47.     public function getAnsweredBy(): ?User
  48.     {
  49.         return $this->answeredBy;
  50.     }
  51.     public function setAnsweredBy(?User $answeredBy): self
  52.     {
  53.         $this->answeredBy $answeredBy;
  54.         return $this;
  55.     }
  56.     public function getVotes(): ?int
  57.     {
  58.         return $this->votes;
  59.     }
  60.     public function getVotesString(): string
  61.     {
  62.         $prefix $this->getVotes() >= '+' '-';
  63.         return sprintf('%s %d'$prefixabs($this->getVotes()));
  64.     }
  65.     public function setVotes(int $votes): self
  66.     {
  67.         $this->votes $votes;
  68.         return $this;
  69.     }
  70. }