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, orphanRemovaltrue)]
  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 __toString()
  46.     {
  47.         return $this->name;
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getName(): ?string
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function setName(string $name): self
  58.     {
  59.         $this->name $name;
  60.         return $this;
  61.     }
  62.     public function getSlug(): ?string
  63.     {
  64.         return $this->slug;
  65.     }
  66.     public function setSlug(string $slug): self
  67.     {
  68.         $this->slug $slug;
  69.         return $this;
  70.     }
  71.     public function getQuestion(): ?string
  72.     {
  73.         return $this->question;
  74.     }
  75.     public function setQuestion(string $question): self
  76.     {
  77.         $this->question $question;
  78.         return $this;
  79.     }
  80.     public function getAskedBy(): ?User
  81.     {
  82.         return $this->askedBy;
  83.     }
  84.     public function setAskedBy(?User $askedBy): self
  85.     {
  86.         $this->askedBy $askedBy;
  87.         return $this;
  88.     }
  89.     public function getVotes(): int
  90.     {
  91.         return $this->votes;
  92.     }
  93.     public function getVotesString(): string
  94.     {
  95.         $prefix $this->getVotes() >= '+' '-';
  96.         return sprintf('%s %d'$prefixabs($this->getVotes()));
  97.     }
  98.     public function setVotes(int $votes): self
  99.     {
  100.         $this->votes $votes;
  101.         return $this;
  102.     }
  103.     public function upVote(): self
  104.     {
  105.         $this->votes++;
  106.         return $this;
  107.     }
  108.     public function downVote(): self
  109.     {
  110.         $this->votes--;
  111.         return $this;
  112.     }
  113.     /**
  114.      * @return Collection|Answer[]
  115.      */
  116.     public function getAnswers(): Collection
  117.     {
  118.         return $this->answers;
  119.     }
  120.     public function addAnswer(Answer $answer): self
  121.     {
  122.         if (!$this->answers->contains($answer)) {
  123.             $this->answers[] = $answer;
  124.             $answer->setQuestion($this);
  125.         }
  126.         return $this;
  127.     }
  128.     public function removeAnswer(Answer $answer): self
  129.     {
  130.         if ($this->answers->removeElement($answer)) {
  131.             // set the owning side to null (unless already changed)
  132.             if ($answer->getQuestion() === $this) {
  133.                 $answer->setQuestion(null);
  134.             }
  135.         }
  136.         return $this;
  137.     }
  138.     public function getTopic(): ?Topic
  139.     {
  140.         return $this->topic;
  141.     }
  142.     public function setTopic(?Topic $topic): self
  143.     {
  144.         $this->topic $topic;
  145.         return $this;
  146.     }
  147.     public function getIsApproved(): bool
  148.     {
  149.         return $this->isApproved;
  150.     }
  151.     public function setIsApproved(bool $isApproved): void
  152.     {
  153.         $this->isApproved $isApproved;
  154.     }
  155.     public function getUpdatedBy(): ?User
  156.     {
  157.         return $this->updatedBy;
  158.     }
  159.     public function setUpdatedBy(User $updatedBy): void
  160.     {
  161.         $this->updatedBy $updatedBy;
  162.     }
  163. }