<?phpnamespace App\Entity;use App\Repository\ForumTopicRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass=ForumTopicRepository::class) */class ForumTopic{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255, nullable=true) */ private ?string $name; /** * @ORM\Column(type="string", length=25, nullable=true) */ private ?string $countryMin; /** * @ORM\ManyToOne(targetEntity=ForumCategory::class, inversedBy="topics") */ private ?ForumCategory $category; /** * @ORM\OneToMany(targetEntity=ForumPost::class, mappedBy="topic") */ private Collection $posts; /** * @ORM\Column(type="string", length=255) */ private $slug; //---------------------------------------------------------------------------- public function getCommentNumber(): int { $nbComment = 0; /** @var ForumPost[] $posts */ $posts = $this->posts; foreach ($posts as $post){ $nbComment += count($post->getComments()); } return $nbComment; } /** * * POST ACTIVE * * @return ForumPost[] */ public function getPostActives(): array { /** @var ForumPost[] $activePost */ $activePost = []; /** @var ForumPost[] $posts */ $posts = $this->posts; foreach ($posts as $post){ if ($post->isActived()){ $activePost[] = $post; } } return $activePost; } public function getLastPost() { /** @var ForumPost $nbComment */ $lastPost = null; $posts = $this->getPostActives(); if (count($posts) > 0){ $lastPost = end($posts); } return $lastPost; } public function getStringTitle(): ?string { if($this->category->getCountryMin() == "uae"){ return $this->name." in UAE (Dubai, Abu Dhabi…)"; } return $this->name; } //---------------------------------------------------------------------------- public function __construct() { $this->posts = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getName(): ?string { return $this->name; } public function setName(?string $name): self { $this->name = $name; return $this; } public function getCategory(): ?ForumCategory { return $this->category; } public function setCategory(?ForumCategory $category): self { $this->category = $category; return $this; } /** * @return Collection<int, ForumPost> */ public function getPosts(): Collection { return $this->posts; } public function addPost(ForumPost $post): self { if (!$this->posts->contains($post)) { $this->posts[] = $post; $post->setTopic($this); } return $this; } public function removePost(ForumPost $post): self { if ($this->posts->removeElement($post)) { // set the owning side to null (unless already changed) if ($post->getTopic() === $this) { $post->setTopic(null); } } return $this; } public function getCountryMin(): ?string { return $this->countryMin; } public function setCountryMin(?string $countryMin): self { $this->countryMin = $countryMin; return $this; } public function getSlug(): ?string { return $this->slug; } public function setSlug(string $slug): self { $this->slug = $slug; return $this; }}