*/ #[ORM\OneToMany(targetEntity: Answer::class, mappedBy: 'question', orphanRemoval: true, cascade: ['persist'])] private Collection $answers; /** * @var Collection */ #[ORM\OneToMany(targetEntity: Attachment::class, mappedBy: 'question', orphanRemoval: true, cascade: ['persist'])] private Collection $attachments; /** * @var Collection */ #[ORM\OneToMany(targetEntity: QuestionVote::class, mappedBy: 'question', orphanRemoval: true)] private Collection $questionVotes; /** * @var Collection */ #[ORM\OneToMany(targetEntity: QuestionTagRelation::class, mappedBy: 'question', orphanRemoval: true, cascade: ['persist'])] private Collection $tagRelations; public function __construct() { $this->answers = new ArrayCollection(); $this->questionVotes = new ArrayCollection(); $this->tagRelations = new ArrayCollection(); $this->attachments = new ArrayCollection(); $this->createdAt = new \DateTime(); } public function getId(): ?int { return $this->id; } public function getTitle(): ?string { return $this->title; } public function setTitle(string $title): static { $this->title = $title; return $this; } public function getContent(): ?string { return $this->content; } public function setContent(string $content): static { $this->content = $content; return $this; } public function getAuthor(): ?User { return $this->author; } public function setAuthor(?User $author): static { $this->author = $author; return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } public function setCreatedAt(\DateTimeInterface $createdAt): static { $this->createdAt = $createdAt; return $this; } public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } public function setUpdatedAt(?\DateTimeInterface $updatedAt): static { $this->updatedAt = $updatedAt; return $this; } public function isSolved(): bool { return $this->isSolved; } public function setIsSolved(bool $isSolved): static { $this->isSolved = $isSolved; return $this; } public function getViews(): int { return $this->views; } public function setViews(int $views): static { $this->views = $views; return $this; } public function incrementViews(): static { $this->views++; return $this; } public function getVotes(): int { return $this->votes; } public function setVotes(int $votes): static { $this->votes = $votes; return $this; } public function isActive(): bool { return $this->isActive; } public function setIsActive(bool $isActive): static { $this->isActive = $isActive; return $this; } /** * @return Collection */ public function getAnswers(): Collection { return $this->answers; } public function addAnswer(Answer $answer): static { if (!$this->answers->contains($answer)) { $this->answers->add($answer); $answer->setQuestion($this); } return $this; } public function removeAnswer(Answer $answer): static { if ($this->answers->removeElement($answer)) { if ($answer->getQuestion() === $this) { $answer->setQuestion(null); } } return $this; } /** * @return Collection */ public function getQuestionVotes(): Collection { return $this->questionVotes; } public function addQuestionVote(QuestionVote $questionVote): static { if (!$this->questionVotes->contains($questionVote)) { $this->questionVotes->add($questionVote); $questionVote->setQuestion($this); } return $this; } public function removeQuestionVote(QuestionVote $questionVote): static { if ($this->questionVotes->removeElement($questionVote)) { if ($questionVote->getQuestion() === $this) { $questionVote->setQuestion(null); } } return $this; } /** * @return Collection */ public function getTagRelations(): Collection { return $this->tagRelations; } public function addTagRelation(QuestionTagRelation $tagRelation): static { if (!$this->tagRelations->contains($tagRelation)) { $this->tagRelations->add($tagRelation); $tagRelation->setQuestion($this); } return $this; } public function removeTagRelation(QuestionTagRelation $tagRelation): static { if ($this->tagRelations->removeElement($tagRelation)) { if ($tagRelation->getQuestion() === $this) { $tagRelation->setQuestion(null); } } return $this; } public function getAnswersCount(): int { return $this->answers->count(); } public function getBestAnswer(): ?Answer { foreach ($this->answers as $answer) { if ($answer->isAccepted()) { return $answer; } } return null; } public function isNotifyOnAnswer(): bool { return $this->notifyOnAnswer; } public function setNotifyOnAnswer(bool $notifyOnAnswer): static { $this->notifyOnAnswer = $notifyOnAnswer; return $this; } /** * @return Collection */ public function getAttachments(): Collection { return $this->attachments; } public function addAttachment(Attachment $attachment): static { if (!$this->attachments->contains($attachment)) { $this->attachments->add($attachment); $attachment->setQuestion($this); } return $this; } public function removeAttachment(Attachment $attachment): static { if ($this->attachments->removeElement($attachment)) { if ($attachment->getQuestion() === $this) { $attachment->setQuestion(null); } } return $this; } public function getAttachmentsCount(): int { return $this->attachments->count(); } }