<?php
namespace App\Entity;
use App\Repository\ForumUserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ForumUserRepository::class)
*/
class ForumUser
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
*/
private ?string $alias;
/**
* @ORM\Column(type="datetime")
*/
private ?\DateTimeInterface $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTimeInterface $deletedAt;
/**
* @ORM\OneToMany(targetEntity=ForumPost::class, mappedBy="forumUser")
*/
private Collection $posts;
/**
* @ORM\OneToOne(targetEntity=User::class, inversedBy="forumUser", cascade={"persist", "remove"})
*/
private ?User $user;
/**
* @ORM\ManyToMany(targetEntity=ForumPost::class, mappedBy="userViews")
*/
private Collection $forumPostViews;
/**
* @ORM\OneToMany(targetEntity=ForumComment::class, mappedBy="forumUser")
*/
private Collection $forumComments;
/**
* @ORM\OneToMany(targetEntity=ForumCommentReply::class, mappedBy="forumUser")
*/
private Collection $forumCommentReplies;
/**
* @ORM\ManyToMany(targetEntity=ForumPost::class, inversedBy="forumUserFavorites")
*/
private Collection $favoritePost;
public function __construct()
{
$this->posts = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->forumPostViews = new ArrayCollection();
$this->forumComments = new ArrayCollection();
$this->forumCommentReplies = new ArrayCollection();
$this->favoritePost = new ArrayCollection();
}
//---------------------------------------------------------------------
function getAvatarSpanName(): string
{
$chaine = $this->alias;
if (strlen($chaine) >= 2) {
$premiereLettre = strtoupper(substr($chaine, 0, 1));
$deuxiemeLettre = strtolower(substr($chaine, 1, 1));
return $premiereLettre . $deuxiemeLettre;
} else {
// Gérer le cas où la chaîne n'a pas au moins deux caractères.
return "";
}
}
//---------------------------------------------------------------------
public function getId(): ?int
{
return $this->id;
}
public function getAlias(): ?string
{
return $this->alias;
}
public function setAlias(?string $alias): self
{
$this->alias = $alias;
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->setForumUser($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->getForumUser() === $this) {
$post->setForumUser(null);
}
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeInterface $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
/**
* @return Collection<int, ForumPost>
*/
public function getForumPostViews(): Collection
{
return $this->forumPostViews;
}
public function addForumPostView(ForumPost $forumPostView): self
{
if (!$this->forumPostViews->contains($forumPostView)) {
$this->forumPostViews[] = $forumPostView;
$forumPostView->addUserView($this);
}
return $this;
}
public function removeForumPostView(ForumPost $forumPostView): self
{
if ($this->forumPostViews->removeElement($forumPostView)) {
$forumPostView->removeUserView($this);
}
return $this;
}
/**
* @return Collection<int, ForumComment>
*/
public function getForumComments(): Collection
{
return $this->forumComments;
}
public function addForumComment(ForumComment $forumComment): self
{
if (!$this->forumComments->contains($forumComment)) {
$this->forumComments[] = $forumComment;
$forumComment->setForumUser($this);
}
return $this;
}
public function removeForumComment(ForumComment $forumComment): self
{
if ($this->forumComments->removeElement($forumComment)) {
// set the owning side to null (unless already changed)
if ($forumComment->getForumUser() === $this) {
$forumComment->setForumUser(null);
}
}
return $this;
}
/**
* @return Collection<int, ForumCommentReply>
*/
public function getForumCommentReplies(): Collection
{
return $this->forumCommentReplies;
}
public function addForumCommentReply(ForumCommentReply $forumCommentReply): self
{
if (!$this->forumCommentReplies->contains($forumCommentReply)) {
$this->forumCommentReplies[] = $forumCommentReply;
$forumCommentReply->setForumUser($this);
}
return $this;
}
public function removeForumCommentReply(ForumCommentReply $forumCommentReply): self
{
if ($this->forumCommentReplies->removeElement($forumCommentReply)) {
// set the owning side to null (unless already changed)
if ($forumCommentReply->getForumUser() === $this) {
$forumCommentReply->setForumUser(null);
}
}
return $this;
}
/**
* @return Collection<int, ForumPost>
*/
public function getFavoritePost(): Collection
{
return $this->favoritePost;
}
public function addFavoritePost(ForumPost $favoritePost): self
{
if (!$this->favoritePost->contains($favoritePost)) {
$this->favoritePost[] = $favoritePost;
}
return $this;
}
public function removeFavoritePost(ForumPost $favoritePost): self
{
$this->favoritePost->removeElement($favoritePost);
return $this;
}
}