<?php
namespace App\Entity;
use App\Repository\CBRCUserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=CBRCUserRepository::class)
*/
class CBRCUser implements UserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
private $plainPassword;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\OneToOne(targetEntity=CBRCUserDescription::class, cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false)
*/
private $description;
/**
* @ORM\Column(type="datetime")
*/
private $creationdate;
/**
* @ORM\OneToMany(targetEntity=CBRCArticle::class, mappedBy="author")
* @ORM\OrderBy({"publisheddate" = "DESC", "creationdate" = "DESC"})
*/
private $articles;
/**
* @ORM\OneToMany(targetEntity=CBRCPageContentUpdate::class, mappedBy="user")
*/
private $pagecontentupdates;
/**
* @ORM\OneToOne(targetEntity=CBRCResetPassword::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $resetpassword;
/**
* @ORM\OneToMany(targetEntity=CBRCArticleComment::class, mappedBy="user", orphanRemoval=true)
*/
private $comments;
public function __construct()
{
$this->description= new CBRCUserDescription();
$this->creationdate= new \DateTime('now');
$this->CBRCArticles = new ArrayCollection();
$this->pagecontentupdates = new ArrayCollection();
$this->comments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string)$this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getPlainPassword()
{
return $this->plainPassword;
}
public function setPlainPassword($password)
{
$this->plainPassword = $password;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getDescription(): ?CBRCUserDescription
{
return $this->description;
}
public function setDescription(CBRCUserDescription $description): self
{
$this->description = $description;
return $this;
}
public function getCreationdate(): ?\DateTimeInterface
{
return $this->creationdate;
}
public function setCreationdate(\DateTimeInterface $creationdate): self
{
$this->creationdate = $creationdate;
return $this;
}
/**
* @return Collection|CBRCArticle[]
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(CBRCArticle $cBRCArticle): self
{
if (!$this->articles->contains($cBRCArticle)) {
$this->articles[] = $cBRCArticle;
$cBRCArticle->setAuthor($this);
}
return $this;
}
public function removeArticle(CBRCArticle $cBRCArticle): self
{
if ($this->articles->removeElement($cBRCArticle)) {
// set the owning side to null (unless already changed)
if ($cBRCArticle->getAuthor() === $this) {
$cBRCArticle->setAuthor(null);
}
}
return $this;
}
/**
* @return Collection|CBRCPageContentUpdate[]
*/
public function getPagecontentupdates(): Collection
{
return $this->pagecontentupdates;
}
public function addPagecontentupdate(CBRCPageContentUpdate $pagecontentupdate): self
{
if (!$this->pagecontentupdates->contains($pagecontentupdate)) {
$this->pagecontentupdates[] = $pagecontentupdate;
$pagecontentupdate->setUser($this);
}
return $this;
}
public function removePagecontentupdate(CBRCPageContentUpdate $pagecontentupdate): self
{
if ($this->pagecontentupdates->removeElement($pagecontentupdate)) {
// set the owning side to null (unless already changed)
if ($pagecontentupdate->getUser() === $this) {
$pagecontentupdate->setUser(null);
}
}
return $this;
}
public function getResetpassword(): ?CBRCResetPassword
{
return $this->resetpassword;
}
public function setResetpassword(CBRCResetPassword $resetpassword): self
{
// set the owning side of the relation if necessary
if ($resetpassword->getUser() !== $this) {
$resetpassword->setUser($this);
}
$this->resetpassword = $resetpassword;
return $this;
}
/**
* @return Collection|CBRCArticleComment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(CBRCArticleComment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setUser($this);
}
return $this;
}
public function removeComment(CBRCArticleComment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getUser() === $this) {
$comment->setUser(null);
}
}
return $this;
}
public function getDisplayname()
{
if($this->description->getName() || $this->description->getForname())
{
return $this->description->getForname().' '.$this->description->getName();
}
return 'Anonyme';
}
}