src/Entity/ForumUser.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ForumUserRepository;
  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. /**
  9.  * @ORM\Entity(repositoryClass=ForumUserRepository::class)
  10.  */
  11. class ForumUser
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255, nullable=true, unique=true)
  21.      */
  22.     private ?string $alias;
  23.     /**
  24.      * @ORM\Column(type="datetime")
  25.      */
  26.     private ?\DateTimeInterface $createdAt;
  27.     /**
  28.      * @ORM\Column(type="datetime", nullable=true)
  29.      */
  30.     private ?\DateTimeInterface $deletedAt;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=ForumPost::class, mappedBy="forumUser")
  33.      */
  34.     private Collection $posts;
  35.     /**
  36.      * @ORM\OneToOne(targetEntity=User::class, inversedBy="forumUser", cascade={"persist", "remove"})
  37.      */
  38.     private ?User $user;
  39.     /**
  40.      * @ORM\ManyToMany(targetEntity=ForumPost::class, mappedBy="userViews")
  41.      */
  42.     private Collection $forumPostViews;
  43.     /**
  44.      * @ORM\OneToMany(targetEntity=ForumComment::class, mappedBy="forumUser")
  45.      */
  46.     private Collection $forumComments;
  47.     /**
  48.      * @ORM\OneToMany(targetEntity=ForumCommentReply::class, mappedBy="forumUser")
  49.      */
  50.     private Collection $forumCommentReplies;
  51.     /**
  52.      * @ORM\ManyToMany(targetEntity=ForumPost::class, inversedBy="forumUserFavorites")
  53.      */
  54.     private Collection $favoritePost;
  55.     public function __construct()
  56.     {
  57.         $this->posts = new ArrayCollection();
  58.         $this->createdAt = new \DateTime();
  59.         $this->forumPostViews = new ArrayCollection();
  60.         $this->forumComments = new ArrayCollection();
  61.         $this->forumCommentReplies = new ArrayCollection();
  62.         $this->favoritePost = new ArrayCollection();
  63.     }
  64.     //---------------------------------------------------------------------
  65.     function getAvatarSpanName(): string
  66.     {
  67.         $chaine $this->alias;
  68.         if (strlen($chaine) >= 2) {
  69.             $premiereLettre strtoupper(substr($chaine01));
  70.             $deuxiemeLettre strtolower(substr($chaine11));
  71.             return $premiereLettre $deuxiemeLettre;
  72.         } else {
  73.             // Gérer le cas où la chaîne n'a pas au moins deux caractères.
  74.             return "";
  75.         }
  76.     }
  77.     //---------------------------------------------------------------------
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getAlias(): ?string
  83.     {
  84.         return $this->alias;
  85.     }
  86.     public function setAlias(?string $alias): self
  87.     {
  88.         $this->alias $alias;
  89.         return $this;
  90.     }
  91.     /**
  92.      * @return Collection<int, ForumPost>
  93.      */
  94.     public function getPosts(): Collection
  95.     {
  96.         return $this->posts;
  97.     }
  98.     public function addPost(ForumPost $post): self
  99.     {
  100.         if (!$this->posts->contains($post)) {
  101.             $this->posts[] = $post;
  102.             $post->setForumUser($this);
  103.         }
  104.         return $this;
  105.     }
  106.     public function removePost(ForumPost $post): self
  107.     {
  108.         if ($this->posts->removeElement($post)) {
  109.             // set the owning side to null (unless already changed)
  110.             if ($post->getForumUser() === $this) {
  111.                 $post->setForumUser(null);
  112.             }
  113.         }
  114.         return $this;
  115.     }
  116.     public function getUser(): ?User
  117.     {
  118.         return $this->user;
  119.     }
  120.     public function setUser(?User $user): self
  121.     {
  122.         $this->user $user;
  123.         return $this;
  124.     }
  125.     public function getCreatedAt(): ?\DateTimeInterface
  126.     {
  127.         return $this->createdAt;
  128.     }
  129.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  130.     {
  131.         $this->createdAt $createdAt;
  132.         return $this;
  133.     }
  134.     public function getDeletedAt(): ?\DateTimeInterface
  135.     {
  136.         return $this->deletedAt;
  137.     }
  138.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  139.     {
  140.         $this->deletedAt $deletedAt;
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return Collection<int, ForumPost>
  145.      */
  146.     public function getForumPostViews(): Collection
  147.     {
  148.         return $this->forumPostViews;
  149.     }
  150.     public function addForumPostView(ForumPost $forumPostView): self
  151.     {
  152.         if (!$this->forumPostViews->contains($forumPostView)) {
  153.             $this->forumPostViews[] = $forumPostView;
  154.             $forumPostView->addUserView($this);
  155.         }
  156.         return $this;
  157.     }
  158.     public function removeForumPostView(ForumPost $forumPostView): self
  159.     {
  160.         if ($this->forumPostViews->removeElement($forumPostView)) {
  161.             $forumPostView->removeUserView($this);
  162.         }
  163.         return $this;
  164.     }
  165.     /**
  166.      * @return Collection<int, ForumComment>
  167.      */
  168.     public function getForumComments(): Collection
  169.     {
  170.         return $this->forumComments;
  171.     }
  172.     public function addForumComment(ForumComment $forumComment): self
  173.     {
  174.         if (!$this->forumComments->contains($forumComment)) {
  175.             $this->forumComments[] = $forumComment;
  176.             $forumComment->setForumUser($this);
  177.         }
  178.         return $this;
  179.     }
  180.     public function removeForumComment(ForumComment $forumComment): self
  181.     {
  182.         if ($this->forumComments->removeElement($forumComment)) {
  183.             // set the owning side to null (unless already changed)
  184.             if ($forumComment->getForumUser() === $this) {
  185.                 $forumComment->setForumUser(null);
  186.             }
  187.         }
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return Collection<int, ForumCommentReply>
  192.      */
  193.     public function getForumCommentReplies(): Collection
  194.     {
  195.         return $this->forumCommentReplies;
  196.     }
  197.     public function addForumCommentReply(ForumCommentReply $forumCommentReply): self
  198.     {
  199.         if (!$this->forumCommentReplies->contains($forumCommentReply)) {
  200.             $this->forumCommentReplies[] = $forumCommentReply;
  201.             $forumCommentReply->setForumUser($this);
  202.         }
  203.         return $this;
  204.     }
  205.     public function removeForumCommentReply(ForumCommentReply $forumCommentReply): self
  206.     {
  207.         if ($this->forumCommentReplies->removeElement($forumCommentReply)) {
  208.             // set the owning side to null (unless already changed)
  209.             if ($forumCommentReply->getForumUser() === $this) {
  210.                 $forumCommentReply->setForumUser(null);
  211.             }
  212.         }
  213.         return $this;
  214.     }
  215.     /**
  216.      * @return Collection<int, ForumPost>
  217.      */
  218.     public function getFavoritePost(): Collection
  219.     {
  220.         return $this->favoritePost;
  221.     }
  222.     public function addFavoritePost(ForumPost $favoritePost): self
  223.     {
  224.         if (!$this->favoritePost->contains($favoritePost)) {
  225.             $this->favoritePost[] = $favoritePost;
  226.         }
  227.         return $this;
  228.     }
  229.     public function removeFavoritePost(ForumPost $favoritePost): self
  230.     {
  231.         $this->favoritePost->removeElement($favoritePost);
  232.         return $this;
  233.     }
  234. }