src/Entity/ForumTopic.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ForumTopicRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=ForumTopicRepository::class)
  9.  */
  10. class ForumTopic
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255, nullable=true)
  20.      */
  21.     private ?string $name;
  22.     /**
  23.      * @ORM\Column(type="string", length=25, nullable=true)
  24.      */
  25.     private ?string $countryMin;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=ForumCategory::class, inversedBy="topics")
  28.      */
  29.     private ?ForumCategory $category;
  30.     /**
  31.      * @ORM\OneToMany(targetEntity=ForumPost::class, mappedBy="topic")
  32.      */
  33.     private Collection $posts;
  34.     /**
  35.      * @ORM\Column(type="string", length=255)
  36.      */
  37.     private $slug;
  38.     //----------------------------------------------------------------------------
  39.     public function getCommentNumber(): int
  40.     {
  41.         $nbComment 0;
  42.         /** @var ForumPost[] $posts */
  43.         $posts $this->posts;
  44.         foreach ($posts as $post){
  45.             $nbComment += count($post->getComments());
  46.         }
  47.         return $nbComment;
  48.     }
  49.     /**
  50.      *
  51.      * POST ACTIVE
  52.      *
  53.      * @return ForumPost[]
  54.      */
  55.     public function getPostActives(): array
  56.     {
  57.         /** @var ForumPost[] $activePost */
  58.         $activePost = [];
  59.         /** @var ForumPost[] $posts */
  60.         $posts $this->posts;
  61.         foreach ($posts as $post){
  62.             if ($post->isActived()){
  63.                 $activePost[] = $post;
  64.             }
  65.         }
  66.         return $activePost;
  67.     }
  68.     public function getLastPost()
  69.     {
  70.         /** @var ForumPost $nbComment */
  71.         $lastPost null;
  72.         $posts $this->getPostActives();
  73.         if (count($posts) > 0){
  74.             $lastPost end($posts);
  75.         }
  76.         return $lastPost;
  77.     }
  78.     public function getStringTitle(): ?string
  79.     {
  80.         if($this->category->getCountryMin() == "uae"){
  81.             return $this->name." in UAE (Dubai, Abu Dhabi…)";
  82.         }
  83.         return $this->name;
  84.     }
  85.     //----------------------------------------------------------------------------
  86.     public function __construct()
  87.     {
  88.         $this->posts = new ArrayCollection();
  89.     }
  90.     public function getId(): ?int
  91.     {
  92.         return $this->id;
  93.     }
  94.     public function getName(): ?string
  95.     {
  96.         return $this->name;
  97.     }
  98.     public function setName(?string $name): self
  99.     {
  100.         $this->name $name;
  101.         return $this;
  102.     }
  103.     public function getCategory(): ?ForumCategory
  104.     {
  105.         return $this->category;
  106.     }
  107.     public function setCategory(?ForumCategory $category): self
  108.     {
  109.         $this->category $category;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return Collection<int, ForumPost>
  114.      */
  115.     public function getPosts(): Collection
  116.     {
  117.         return $this->posts;
  118.     }
  119.     public function addPost(ForumPost $post): self
  120.     {
  121.         if (!$this->posts->contains($post)) {
  122.             $this->posts[] = $post;
  123.             $post->setTopic($this);
  124.         }
  125.         return $this;
  126.     }
  127.     public function removePost(ForumPost $post): self
  128.     {
  129.         if ($this->posts->removeElement($post)) {
  130.             // set the owning side to null (unless already changed)
  131.             if ($post->getTopic() === $this) {
  132.                 $post->setTopic(null);
  133.             }
  134.         }
  135.         return $this;
  136.     }
  137.     public function getCountryMin(): ?string
  138.     {
  139.         return $this->countryMin;
  140.     }
  141.     public function setCountryMin(?string $countryMin): self
  142.     {
  143.         $this->countryMin $countryMin;
  144.         return $this;
  145.     }
  146.     public function getSlug(): ?string
  147.     {
  148.         return $this->slug;
  149.     }
  150.     public function setSlug(string $slug): self
  151.     {
  152.         $this->slug $slug;
  153.         return $this;
  154.     }
  155. }