src/Entity/User.php line 15

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. use Sulu\Bundle\SecurityBundle\Entity\User as SuluUser;
  9. #[ORM\Entity]
  10. #[ORM\Table(name'se_users')]
  11. class User extends SuluUser implements UserInterface
  12. {
  13.     #[Serializer\Groups(['profile''frontend''fullUser''consultant'])]
  14.     protected $id;
  15.     #[ORM\OneToMany(mappedBy'user'targetEntityUserArticle::class)]
  16.     #[Serializer\Groups(['profile'])]
  17.     private Collection $articles;
  18.     #[ORM\OneToOne(mappedBy'user'targetEntityConsultantDetails::class, cascade: ['persist''remove'])]
  19.     #[Serializer\Groups(['consultant''profile''fullUser'])]
  20.     private ?ConsultantDetails $consultantDetails null;
  21.     #[ORM\OneToOne(mappedBy'user'targetEntityConsultantImpressum::class, cascade: ['persist''remove'])]
  22.     #[Serializer\Groups(['profile'])]
  23.     private ?ConsultantImpressum $impressum null;
  24.     #[Serializer\Groups(['profile''frontend''fullUser'])]
  25.     private bool $isConsultant false;
  26.     #[Serializer\Groups(['profile''frontend''fullUser'])]
  27.     private bool $isArticleWriter false;
  28.     #[Serializer\Groups(['profile''frontend''fullUser'])]
  29.     private string $userAvatar;
  30.     public function __construct()
  31.     {
  32.         parent::__construct();
  33.         $this->articles = new ArrayCollection();
  34.         if (null !== $this->consultantDetails) {
  35.             $this->isConsultant true;
  36.         }
  37.     }
  38.     public function getArticles(bool $onlyActive true): Collection
  39.     {
  40.         if ($onlyActive) {
  41.             $filteredArticles = new ArrayCollection();
  42.             foreach ($this->articles as $article) {
  43.                 if (true === $article->isActive()) {
  44.                     $filteredArticles->add($article);
  45.                 }
  46.             }
  47.             return $filteredArticles;
  48.         }
  49.         return $this->articles;
  50.     }
  51.     public function addArticle(UserArticle $article): self
  52.     {
  53.         if (!$this->articles->contains($article) && $article->isActive()) {
  54.             $this->articles[] = $article;
  55.             $article->setUser($this);
  56.         }
  57.         return $this;
  58.     }
  59.     public function setArticles(Collection $articles): self
  60.     {
  61.         $this->articles $articles;
  62.         return $this;
  63.     }
  64.     public function getConsultantDetails(): ?ConsultantDetails
  65.     {
  66.         if (null === $this->consultantDetails) {
  67.             $this->isConsultant true;
  68.         }
  69.         return $this->consultantDetails;
  70.     }
  71.     public function setConsultantDetails(?ConsultantDetails $consultantDetails): self
  72.     {
  73.         if (null === $consultantDetails) {
  74.             $this->isConsultant false;
  75.             $this->consultantDetails null;
  76.             return $this;
  77.         }
  78.         $consultantDetails->setUser($this);
  79.         $this->consultantDetails $consultantDetails;
  80.         $this->isConsultant true;
  81.         return $this;
  82.     }
  83.     public function getImpressum(): ?ConsultantImpressum
  84.     {
  85.         return $this->impressum;
  86.     }
  87.     public function setImpressum(?ConsultantImpressum $impressum): self
  88.     {
  89.         $this->impressum $impressum;
  90.         $impressum?->setUser($this);
  91.         return $this;
  92.     }
  93.     public function isConsultant(): bool
  94.     {
  95.         if (null !== $this->consultantDetails) {
  96.             $this->isConsultant true;
  97.         }
  98.         return $this->isConsultant;
  99.     }
  100.     public function setIsConsultant(bool $isConsultant): self
  101.     {
  102.         $this->isConsultant $isConsultant;
  103.         return $this;
  104.     }
  105.     public function isArticleWriter(): bool
  106.     {
  107.         return $this->isArticleWriter;
  108.     }
  109.     public function setIsArticleWriter(bool $isArticleWriter): self
  110.     {
  111.         $this->isArticleWriter $isArticleWriter;
  112.         return $this;
  113.     }
  114.     public function getUserAvatar(): ?string
  115.     {
  116.         return $this->userAvatar;
  117.     }
  118.     public function setUserAvatar(?string $userAvatar): self
  119.     {
  120.         $this->userAvatar $userAvatar;
  121.         return $this;
  122.     }
  123. }