src/Entity/CBRCUser.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CBRCUserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. /**
  9.  * @ORM\Entity(repositoryClass=CBRCUserRepository::class)
  10.  */
  11. class CBRCUser implements UserInterface
  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)
  21.      */
  22.     private $email;
  23.     /**
  24.      * @var string The hashed password
  25.      * @ORM\Column(type="string")
  26.      */
  27.     private $password;
  28.     private $plainPassword;
  29.     /**
  30.      * @ORM\Column(type="json")
  31.      */
  32.     private $roles = [];
  33.     /**
  34.      * @ORM\OneToOne(targetEntity=CBRCUserDescription::class, cascade={"persist", "remove"})
  35.      * @ORM\JoinColumn(nullable=false)
  36.      */
  37.     private $description;
  38.     /**
  39.      * @ORM\Column(type="datetime")
  40.      */
  41.     private $creationdate;
  42.     /**
  43.      * @ORM\OneToMany(targetEntity=CBRCArticle::class, mappedBy="author")
  44.      * @ORM\OrderBy({"publisheddate" = "DESC", "creationdate" = "DESC"})
  45.      */
  46.     private $articles;
  47.     /**
  48.      * @ORM\OneToMany(targetEntity=CBRCPageContentUpdate::class, mappedBy="user")
  49.      */
  50.     private $pagecontentupdates;
  51.     /**
  52.      * @ORM\OneToOne(targetEntity=CBRCResetPassword::class, mappedBy="user", cascade={"persist", "remove"})
  53.      */
  54.     private $resetpassword;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity=CBRCArticleComment::class, mappedBy="user", orphanRemoval=true)
  57.      */
  58.     private $comments;
  59.     public function __construct()
  60.     {
  61.         $this->description= new CBRCUserDescription();
  62.         $this->creationdate= new \DateTime('now');
  63.         $this->CBRCArticles = new ArrayCollection();
  64.         $this->pagecontentupdates = new ArrayCollection();
  65.         $this->comments = new ArrayCollection();
  66.     }
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getEmail(): ?string
  72.     {
  73.         return $this->email;
  74.     }
  75.     public function setEmail(string $email): self
  76.     {
  77.         $this->email $email;
  78.         return $this;
  79.     }
  80.     public function getPassword(): ?string
  81.     {
  82.         return $this->password;
  83.     }
  84.     public function setPassword(string $password): self
  85.     {
  86.         $this->password $password;
  87.         return $this;
  88.     }
  89.     /**
  90.      * A visual identifier that represents this user.
  91.      *
  92.      * @see UserInterface
  93.      */
  94.     public function getUsername(): string
  95.     {
  96.         return (string)$this->email;
  97.     }
  98.     /**
  99.      * @see UserInterface
  100.      */
  101.     public function getRoles(): array
  102.     {
  103.         $roles $this->roles;
  104.         // guarantee every user at least has ROLE_USER
  105.         $roles[] = 'ROLE_USER';
  106.         return array_unique($roles);
  107.     }
  108.     public function setRoles(array $roles): self
  109.     {
  110.         $this->roles $roles;
  111.         return $this;
  112.     }
  113.     public function getPlainPassword()
  114.     {
  115.         return $this->plainPassword;
  116.     }
  117.     public function setPlainPassword($password)
  118.     {
  119.         $this->plainPassword $password;
  120.     }
  121.     /**
  122.      * @see UserInterface
  123.      */
  124.     public function getSalt()
  125.     {
  126.         // not needed when using the "bcrypt" algorithm in security.yaml
  127.     }
  128.     /**
  129.      * @see UserInterface
  130.      */
  131.     public function eraseCredentials()
  132.     {
  133.         // If you store any temporary, sensitive data on the user, clear it here
  134.         // $this->plainPassword = null;
  135.     }
  136.     public function getDescription(): ?CBRCUserDescription
  137.     {
  138.         return $this->description;
  139.     }
  140.     public function setDescription(CBRCUserDescription $description): self
  141.     {
  142.         $this->description $description;
  143.         return $this;
  144.     }
  145.     public function getCreationdate(): ?\DateTimeInterface
  146.     {
  147.         return $this->creationdate;
  148.     }
  149.     public function setCreationdate(\DateTimeInterface $creationdate): self
  150.     {
  151.         $this->creationdate $creationdate;
  152.         return $this;
  153.     }
  154.     /**
  155.      * @return Collection|CBRCArticle[]
  156.      */
  157.     public function getArticles(): Collection
  158.     {
  159.         return $this->articles;
  160.     }
  161.     public function addArticle(CBRCArticle $cBRCArticle): self
  162.     {
  163.         if (!$this->articles->contains($cBRCArticle)) {
  164.             $this->articles[] = $cBRCArticle;
  165.             $cBRCArticle->setAuthor($this);
  166.         }
  167.         return $this;
  168.     }
  169.     public function removeArticle(CBRCArticle $cBRCArticle): self
  170.     {
  171.         if ($this->articles->removeElement($cBRCArticle)) {
  172.             // set the owning side to null (unless already changed)
  173.             if ($cBRCArticle->getAuthor() === $this) {
  174.                 $cBRCArticle->setAuthor(null);
  175.             }
  176.         }
  177.         return $this;
  178.     }
  179.     /**
  180.      * @return Collection|CBRCPageContentUpdate[]
  181.      */
  182.     public function getPagecontentupdates(): Collection
  183.     {
  184.         return $this->pagecontentupdates;
  185.     }
  186.     public function addPagecontentupdate(CBRCPageContentUpdate $pagecontentupdate): self
  187.     {
  188.         if (!$this->pagecontentupdates->contains($pagecontentupdate)) {
  189.             $this->pagecontentupdates[] = $pagecontentupdate;
  190.             $pagecontentupdate->setUser($this);
  191.         }
  192.         return $this;
  193.     }
  194.     public function removePagecontentupdate(CBRCPageContentUpdate $pagecontentupdate): self
  195.     {
  196.         if ($this->pagecontentupdates->removeElement($pagecontentupdate)) {
  197.             // set the owning side to null (unless already changed)
  198.             if ($pagecontentupdate->getUser() === $this) {
  199.                 $pagecontentupdate->setUser(null);
  200.             }
  201.         }
  202.         return $this;
  203.     }
  204.     public function getResetpassword(): ?CBRCResetPassword
  205.     {
  206.         return $this->resetpassword;
  207.     }
  208.     public function setResetpassword(CBRCResetPassword $resetpassword): self
  209.     {
  210.         // set the owning side of the relation if necessary
  211.         if ($resetpassword->getUser() !== $this) {
  212.             $resetpassword->setUser($this);
  213.         }
  214.         $this->resetpassword $resetpassword;
  215.         return $this;
  216.     }
  217.     /**
  218.      * @return Collection|CBRCArticleComment[]
  219.      */
  220.     public function getComments(): Collection
  221.     {
  222.         return $this->comments;
  223.     }
  224.     public function addComment(CBRCArticleComment $comment): self
  225.     {
  226.         if (!$this->comments->contains($comment)) {
  227.             $this->comments[] = $comment;
  228.             $comment->setUser($this);
  229.         }
  230.         return $this;
  231.     }
  232.     public function removeComment(CBRCArticleComment $comment): self
  233.     {
  234.         if ($this->comments->removeElement($comment)) {
  235.             // set the owning side to null (unless already changed)
  236.             if ($comment->getUser() === $this) {
  237.                 $comment->setUser(null);
  238.             }
  239.         }
  240.         return $this;
  241.     }
  242.     public function getDisplayname()
  243.     {
  244.         if($this->description->getName() || $this->description->getForname())
  245.         {
  246.             return $this->description->getForname().' '.$this->description->getName();
  247.         }
  248.         return 'Anonyme';
  249.     }
  250. }