<?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Sulu\Bundle\SecurityBundle\Entity\User as SuluUser;
#[ORM\Entity]
#[ORM\Table(name: 'se_users')]
class User extends SuluUser implements UserInterface
{
#[Serializer\Groups(['profile', 'frontend', 'fullUser', 'consultant'])]
protected $id;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserArticle::class)]
#[Serializer\Groups(['profile'])]
private Collection $articles;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: ConsultantDetails::class, cascade: ['persist', 'remove'])]
#[Serializer\Groups(['consultant', 'profile', 'fullUser'])]
private ?ConsultantDetails $consultantDetails = null;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: ConsultantImpressum::class, cascade: ['persist', 'remove'])]
#[Serializer\Groups(['profile'])]
private ?ConsultantImpressum $impressum = null;
#[Serializer\Groups(['profile', 'frontend', 'fullUser'])]
private bool $isConsultant = false;
#[Serializer\Groups(['profile', 'frontend', 'fullUser'])]
private bool $isArticleWriter = false;
#[Serializer\Groups(['profile', 'frontend', 'fullUser'])]
private string $userAvatar;
public function __construct()
{
parent::__construct();
$this->articles = new ArrayCollection();
if (null !== $this->consultantDetails) {
$this->isConsultant = true;
}
}
public function getArticles(bool $onlyActive = true): Collection
{
if ($onlyActive) {
$filteredArticles = new ArrayCollection();
foreach ($this->articles as $article) {
if (true === $article->isActive()) {
$filteredArticles->add($article);
}
}
return $filteredArticles;
}
return $this->articles;
}
public function addArticle(UserArticle $article): self
{
if (!$this->articles->contains($article) && $article->isActive()) {
$this->articles[] = $article;
$article->setUser($this);
}
return $this;
}
public function setArticles(Collection $articles): self
{
$this->articles = $articles;
return $this;
}
public function getConsultantDetails(): ?ConsultantDetails
{
if (null === $this->consultantDetails) {
$this->isConsultant = true;
}
return $this->consultantDetails;
}
public function setConsultantDetails(?ConsultantDetails $consultantDetails): self
{
if (null === $consultantDetails) {
$this->isConsultant = false;
$this->consultantDetails = null;
return $this;
}
$consultantDetails->setUser($this);
$this->consultantDetails = $consultantDetails;
$this->isConsultant = true;
return $this;
}
public function getImpressum(): ?ConsultantImpressum
{
return $this->impressum;
}
public function setImpressum(?ConsultantImpressum $impressum): self
{
$this->impressum = $impressum;
$impressum?->setUser($this);
return $this;
}
public function isConsultant(): bool
{
if (null !== $this->consultantDetails) {
$this->isConsultant = true;
}
return $this->isConsultant;
}
public function setIsConsultant(bool $isConsultant): self
{
$this->isConsultant = $isConsultant;
return $this;
}
public function isArticleWriter(): bool
{
return $this->isArticleWriter;
}
public function setIsArticleWriter(bool $isArticleWriter): self
{
$this->isArticleWriter = $isArticleWriter;
return $this;
}
public function getUserAvatar(): ?string
{
return $this->userAvatar;
}
public function setUserAvatar(?string $userAvatar): self
{
$this->userAvatar = $userAvatar;
return $this;
}
}