src/Entity/Question.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\QuestionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. #[ORM\Entity(QuestionRepository::class)]
  11. class Question
  12. {
  13.     use TimestampableEntity;
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id;
  18.     #[ORM\Column]
  19.     private ?string $name;
  20.     /**
  21.      * @Gedmo\Slug(fields={"name"})
  22.      */
  23.     #[ORM\Column(length100uniquetrue)]
  24.     private ?string $slug;
  25.     #[ORM\Column(typeTypes::TEXT)]
  26.     private ?string $question;
  27.     #[ORM\ManyToOne(inversedBy'questions')]
  28.     #[ORM\JoinColumn(nullablefalse)]
  29.     private User $askedBy;
  30.     #[ORM\Column]
  31.     private int $votes 0;
  32.     #[ORM\OneToMany('question'Answer::class)]
  33.     private Collection $answers;
  34.     #[ORM\ManyToOne(inversedBy'questions')]
  35.     #[ORM\JoinColumn(nullablefalse)]
  36.     private Topic $topic;
  37.     #[ORM\Column]
  38.     private bool $isApproved false;
  39.     #[ORM\ManyToOne]
  40.     private User $updatedBy;
  41.     public function __construct()
  42.     {
  43.         $this->answers = new ArrayCollection();
  44.     }
  45.     public function getId(): ?int
  46.     {
  47.         return $this->id;
  48.     }
  49.     public function getName(): ?string
  50.     {
  51.         return $this->name;
  52.     }
  53.     public function setName(string $name): self
  54.     {
  55.         $this->name $name;
  56.         return $this;
  57.     }
  58.     public function getSlug(): ?string
  59.     {
  60.         return $this->slug;
  61.     }
  62.     public function setSlug(string $slug): self
  63.     {
  64.         $this->slug $slug;
  65.         return $this;
  66.     }
  67.     public function getQuestion(): ?string
  68.     {
  69.         return $this->question;
  70.     }
  71.     public function setQuestion(string $question): self
  72.     {
  73.         $this->question $question;
  74.         return $this;
  75.     }
  76.     public function getAskedBy(): ?User
  77.     {
  78.         return $this->askedBy;
  79.     }
  80.     public function setAskedBy(?User $askedBy): self
  81.     {
  82.         $this->askedBy $askedBy;
  83.         return $this;
  84.     }
  85.     public function getVotes(): ?int
  86.     {
  87.         return $this->votes;
  88.     }
  89.     public function getVotesString(): string
  90.     {
  91.         $prefix $this->getVotes() >= '+' '-';
  92.         return sprintf('%s %d'$prefixabs($this->getVotes()));
  93.     }
  94.     public function setVotes(int $votes): self
  95.     {
  96.         $this->votes $votes;
  97.         return $this;
  98.     }
  99.     public function upVote(): self
  100.     {
  101.         $this->votes++;
  102.         return $this;
  103.     }
  104.     public function downVote(): self
  105.     {
  106.         $this->votes--;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @return Collection<int, Answer>
  111.      */
  112.     public function getAnswers(): Collection
  113.     {
  114.         return $this->answers;
  115.     }
  116.     public function addAnswer(Answer $answer): self
  117.     {
  118.         if (!$this->answers->contains($answer)) {
  119.             $this->answers->add($answer);
  120.             $answer->setQuestion($this);
  121.         }
  122.         return $this;
  123.     }
  124.     public function removeAnswer(Answer $answer): self
  125.     {
  126.         if ($this->answers->removeElement($answer)) {
  127.             // set the owning side to null (unless already changed)
  128.             if ($answer->getQuestion() === $this) {
  129.                 $answer->setQuestion(null);
  130.             }
  131.         }
  132.         return $this;
  133.     }
  134.     public function getTopic(): ?Topic
  135.     {
  136.         return $this->topic;
  137.     }
  138.     public function setTopic(?Topic $topic): self
  139.     {
  140.         $this->topic $topic;
  141.         return $this;
  142.     }
  143.     public function getIsApproved(): bool
  144.     {
  145.         return $this->isApproved;
  146.     }
  147.     public function setIsApproved(bool $isApproved): self
  148.     {
  149.         $this->isApproved $isApproved;
  150.         return $this;
  151.     }
  152.     public function getUpdatedBy(): ?User
  153.     {
  154.         return $this->updatedBy;
  155.     }
  156.     public function setUpdatedBy(?User $updatedBy): self
  157.     {
  158.         $this->updatedBy $updatedBy;
  159.         return $this;
  160.     }
  161.     public function isIsApproved(): ?bool
  162.     {
  163.         return $this->isApproved;
  164.     }
  165. }