<?php
namespace App\Entity;
use App\Entity\SuperClass\BaseEntity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity("email" , message="Email is already registered")
*/
class User extends BaseEntity implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\NotBlank
* @Assert\Email(
* message = "The email '{{ value }}' is not a valid email."
* )
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
* @Assert\NotBlank
* @Assert\Length(
* min = 8,
* max = 100
* )
*/
private $password;
/**
* @ORM\OneToMany(targetEntity=Blog::class, mappedBy="created_by", cascade={"persist"})
*/
private $blogs;
/**
* @ORM\OneToMany(targetEntity=Templates::class, mappedBy="created_by", cascade={"persist"})
*/
private $templates;
/**
* @ORM\OneToMany(targetEntity=MediaObject::class, mappedBy="created_by")
*/
private $mediaObjects;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="created_by")
*/
private $comments;
/**
* @ORM\OneToMany(targetEntity=Category::class, mappedBy="created_by")
*/
private $categories;
/**
* @ORM\OneToMany(targetEntity=Post::class, mappedBy="created_by")
*/
private $posts;
/**
* @ORM\OneToMany(targetEntity=Product::class, mappedBy="created_by")
*/
private $products;
/**
* @ORM\OneToOne(targetEntity=Customer::class, mappedBy="owner", cascade={"persist", "remove"})
*/
private $customer;
/**
* @ORM\Column(type="boolean")
*/
private $enabled = 0;
/**
* @ORM\OneToOne(targetEntity=Profile::class, mappedBy="owner", cascade={"persist", "remove"})
*/
private $profile;
/**
* @ORM\OneToMany(targetEntity=Address::class, mappedBy="owner", cascade={"persist"})
*/
private $addresses;
/**
* @ORM\OneToMany(targetEntity=Source::class, mappedBy="owner")
*/
private $sources;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="created_by")
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="user")
*/
private $created_by;
/**
* @ORM\OneToMany(targetEntity=Cart::class, mappedBy="created_by")
*/
private $carts;
/**
* @ORM\OneToMany(targetEntity=Cart::class, mappedBy="owner")
*/
private $cart;
/**
* @ORM\OneToMany(targetEntity=Profile::class, mappedBy="created_by")
*/
private $profiles;
public function __construct()
{
$this->blogs = new ArrayCollection();
$this->templates = new ArrayCollection();
$this->mediaObjects = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->posts = new ArrayCollection();
$this->products = new ArrayCollection();
$this->addresses = new ArrayCollection();
$this->sources = new ArrayCollection();
$this->created_by = new ArrayCollection();
$this->carts = new ArrayCollection();
$this->cart = new ArrayCollection();
$this->profiles = 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;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
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;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return Collection|Blog[]
*/
public function getBlogs(): Collection
{
return $this->blogs;
}
public function addBlog(Blog $blog): self
{
if (!$this->blogs->contains($blog)) {
$this->blogs[] = $blog;
$blog->setCreatedBy($this);
}
return $this;
}
public function removeBlog(Blog $blog): self
{
if ($this->blogs->removeElement($blog)) {
// set the owning side to null (unless already changed)
if ($blog->getCreatedBy() === $this) {
$blog->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection|Templates[]
*/
public function getTemplates(): Collection
{
return $this->templates;
}
public function addTemplate(Templates $template): self
{
if (!$this->templates->contains($template)) {
$this->templates[] = $template;
$template->setCreatedBy($this);
}
return $this;
}
public function removeTemplate(Templates $template): self
{
if ($this->templates->removeElement($template)) {
// set the owning side to null (unless already changed)
if ($template->getCreatedBy() === $this) {
$template->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection|MediaObject[]
*/
public function getMediaObjects(): Collection
{
return $this->mediaObjects;
}
public function addMediaObject(MediaObject $mediaObject): self
{
if (!$this->mediaObjects->contains($mediaObject)) {
$this->mediaObjects[] = $mediaObject;
$mediaObject->setCreatedBy($this);
}
return $this;
}
public function removeMediaObject(MediaObject $mediaObject): self
{
if ($this->mediaObjects->removeElement($mediaObject)) {
// set the owning side to null (unless already changed)
if ($mediaObject->getCreatedBy() === $this) {
$mediaObject->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setCreatedBy($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getCreatedBy() === $this) {
$comment->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection|Category[]
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
$category->setCreatedBy($this);
}
return $this;
}
public function removeCategory(Category $category): self
{
if ($this->categories->removeElement($category)) {
// set the owning side to null (unless already changed)
if ($category->getCreatedBy() === $this) {
$category->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection|Post[]
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setCreatedBy($this);
}
return $this;
}
public function removePost(Post $post): self
{
if ($this->posts->removeElement($post)) {
// set the owning side to null (unless already changed)
if ($post->getCreatedBy() === $this) {
$post->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection|Product[]
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setCreatedBy($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getCreatedBy() === $this) {
$product->setCreatedBy(null);
}
}
return $this;
}
public function getCustomer(): ?Customer
{
return $this->customer;
}
public function setCustomer(Customer $customer): self
{
// set the owning side of the relation if necessary
if ($customer->getOwner() !== $this) {
$customer->setOwner($this);
}
$this->customer = $customer;
return $this;
}
public function getEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getProfile(): ?Profile
{
return $this->profile;
}
public function setProfile(?Profile $profile): self
{
// unset the owning side of the relation if necessary
if ($profile === null && $this->profile !== null) {
$this->profile->setOwner(null);
}
// set the owning side of the relation if necessary
if ($profile !== null && $profile->getCreatedBy() !== $this) {
$profile->setCreatedBy($this);
}
$this->profile = $profile;
return $this;
}
/**
* @return Collection|Address[]
*/
public function getAddresses(): Collection
{
return $this->addresses;
}
public function addAddress(Address $address): self
{
if (!$this->addresses->contains($address)) {
$this->addresses[] = $address;
$address->setOwner($this);
}
return $this;
}
public function removeAddress(Address $address): self
{
if ($this->addresses->removeElement($address)) {
// set the owning side to null (unless already changed)
if ($address->getOwner() === $this) {
$address->setOwner(null);
}
}
return $this;
}
public function __toString()
{
return $this->getEmail();
}
/**
* @return Collection|Source[]
*/
public function getSources(): Collection
{
return $this->sources;
}
public function addSource(Source $source): self
{
if (!$this->sources->contains($source)) {
$this->sources[] = $source;
$source->setOwner($this);
}
return $this;
}
public function removeSource(Source $source): self
{
if ($this->sources->removeElement($source)) {
// set the owning side to null (unless already changed)
if ($source->getOwner() === $this) {
$source->setOwner(null);
}
}
return $this;
}
public function getUser(): ?self
{
return $this->user;
}
public function setUser(?self $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getCreatedBy(): Collection
{
return $this->created_by;
}
public function addCreatedBy(self $createdBy): self
{
if (!$this->created_by->contains($createdBy)) {
$this->created_by[] = $createdBy;
$createdBy->setUser($this);
}
return $this;
}
public function removeCreatedBy(self $createdBy): self
{
if ($this->created_by->removeElement($createdBy)) {
// set the owning side to null (unless already changed)
if ($createdBy->getUser() === $this) {
$createdBy->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Cart>
*/
public function getCarts(): Collection
{
return $this->carts;
}
public function addCart(Cart $cart): self
{
if (!$this->carts->contains($cart)) {
$this->carts[] = $cart;
$cart->setCreatedBy($this);
}
return $this;
}
public function removeCart(Cart $cart): self
{
if ($this->carts->removeElement($cart)) {
// set the owning side to null (unless already changed)
if ($cart->getCreatedBy() === $this) {
$cart->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Cart>
*/
public function getCart(): Collection
{
return $this->cart;
}
/**
* @return Collection<int, Profile>
*/
public function getProfiles(): Collection
{
return $this->profiles;
}
public function addProfile(Profile $profile): self
{
if (!$this->profiles->contains($profile)) {
$this->profiles[] = $profile;
$profile->setCreatedBy($this);
}
return $this;
}
public function removeProfile(Profile $profile): self
{
if ($this->profiles->removeElement($profile)) {
// set the owning side to null (unless already changed)
if ($profile->getCreatedBy() === $this) {
$profile->setCreatedBy(null);
}
}
return $this;
}
}