<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Stripe\Product;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
*
* @ORM\HasLifecycleCallbacks()
*
* @UniqueEntity("email")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
public function __construct()
{
$this->articles = new ArrayCollection();
$this->suggestedArticles = new ArrayCollection();
$this->articlesViewed = new ArrayCollection();
$this->userOffers = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->userCategories = new ArrayCollection();
$this->likes = new ArrayCollection();
$this->users_cart = new ArrayCollection();
$this->users_favoris = new ArrayCollection();
$this->user_articles = new ArrayCollection();
}
/**
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserCategory", mappedBy="user")
*/
private $userCategories;
/**
* @ORM\Column(type="string", nullable=true, length=180)
*/
private $pseudo = null;
public function getId(): ?int
{
return $this->id;
}
public function getPseudo(): ?string
{
return $this->pseudo;
}
public function setPseudo($pseudo): self
{
$this->pseudo = $pseudo;
return $this;
}
/**
* @ORM\Column(type="string", nullable=true)
*/
private $secteur;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $company;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $fonction;
/**
* @ORM\Column(type="string", length=180, unique=true)
*
* @Assert\NotBlank
*
* @Assert\Email
*/
private $email;
/**
* @var string The hashed password
*
* @ORM\Column(type="string", nullable=true)
*
* @Assert\NotBlank
*/
private $password;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $auth_activation_token;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $auth_password_token;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $activated_at;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $facebook_id;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $google_id;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $linkedin_id;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $stripe_customer_id;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $complement_adresse;
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 getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = [$this->getRole()->getName()];
$roles[] = 'ROLE_USER';
if ('ROLE_USER' !== $this->getRole()->getName()) {
$roles[] = 'ROLE_API';
}
return array_unique($roles);
}
/**
* @see UserInterface
*/
public function getPassword(): ?string
{
return (string) $this->password;
}
public function setPassword(?string $password): self
{
$this->password = $password;
return $this;
}
/**
* @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 getAuthActivationToken(): ?string
{
return $this->auth_activation_token;
}
public function setAuthActivationToken(?string $auth_activation_token): self
{
$this->auth_activation_token = $auth_activation_token;
return $this;
}
public function getAuthPasswordToken(): ?string
{
return $this->auth_password_token;
}
public function setAuthPasswordToken(?string $auth_password_token): self
{
$this->auth_password_token = $auth_password_token;
return $this;
}
public function getActivatedAt(): ?\DateTimeInterface
{
return $this->activated_at;
}
public function setActivatedAt(?\DateTimeInterface $activated_at): self
{
$this->activated_at = $activated_at;
return $this;
}
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $created_at;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updated_at = null;
public function getCreatedAt(): \DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->setCreatedAt(new \DateTime());
}
/**
* @ORM\PreUpdate
*/
public function setUpdatedAtValue()
{
$this->setUpdatedAt(new \DateTime());
}
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deleted_at;
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deleted_at;
}
public function setDeletedAt(?\DateTimeInterface $deleted_at): self
{
$this->deleted_at = $deleted_at;
return $this;
}
/**
* @return mixed
*/
public function getStripeCustomerId()
{
return $this->stripe_customer_id;
}
/**
* @param mixed $stripe_customer_id
*
* @return User
*/
public function setStripeCustomerId($stripe_customer_id)
{
$this->stripe_customer_id = $stripe_customer_id;
return $this;
}
// Target of a LinkedEntity from UserController (Controller)
// Target of a OneToMany from Role (Entity)
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Role", inversedBy="users")
*
* @ORM\JoinColumn(nullable=true)
*
* @MaxDepth(1)
*/
private $role;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Article", mappedBy="user")
*/
private $articles;
/**
* @ORM\OneToMany(targetEntity="App\Entity\SuggestedArticle", mappedBy="user")
*/
private $suggestedArticles;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ArticleView", mappedBy="user")
*/
private $articlesViewed;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $lastname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $address;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $zipcode;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $city;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $country;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $legacy_id;
/**
* @ORM\Column(type="integer", nullable=true, options={"default": 0})
*/
private $is_digital_premium = 0;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserOffer", mappedBy="user")
*/
private $userOffers;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserConfidentialDocument", mappedBy="user")
*/
private $documents;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Media")
*
* @ORM\JoinColumn(nullable=true)
*/
private $avatar;
/**
* @ORM\Column(type="text", length=600, nullable=true)
*/
private $bio;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $facebook_url;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $linkedin_url;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $twitter_url;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $instagram_url;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $youtube_url;
/**
* @ORM\Column(type="string", length=300, nullable=true)
*/
private $journey;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserLikes", mappedBy="user", cascade={"persist", "remove"})
*/
private $likes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Cart", mappedBy="user", cascade={"persist", "remove"})
*/
private $users_cart;
/**
* @ORM\oneToMany(targetEntity="App\Entity\Favoris", mappedBy="user", cascade={"persist", "remove"})
*/
private $users_favoris;
/**
* @ORM\oneToMany(targetEntity="App\Entity\ArticleFavoris", mappedBy="user", cascade={"persist", "remove"})
*/
private $user_articles;
public function getRole(): ?Role
{
return $this->role;
}
public function setRole(?Role $role): self
{
$this->role = $role;
return $this;
}
/**
* @return Collection|Article[]
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): self
{
if (!$this->articles->contains($article)) {
$this->articles[] = $article;
$article->setUser($this);
}
return $this;
}
public function removeArticle(Article $article): self
{
if ($this->articles->contains($article)) {
$this->articles->removeElement($article);
// set the owning side to null (unless already changed)
if ($article->getUser() === $this) {
$article->setUser(null);
}
}
return $this;
}
/**
* @return Collection|SuggestedArticle[]
*/
public function getSuggestedArticles(): Collection
{
return $this->suggestedArticles;
}
public function addSuggestedArticle(SuggestedArticle $suggestedArticle): self
{
if (!$this->suggestedArticles->contains($suggestedArticle)) {
$this->suggestedArticles[] = $suggestedArticle;
$suggestedArticle->setUser($this);
}
return $this;
}
public function removeSuggestedArticle(SuggestedArticle $suggestedArticle): self
{
if ($this->suggestedArticles->contains($suggestedArticle)) {
$this->suggestedArticles->removeElement($suggestedArticle);
// set the owning side to null (unless already changed)
if ($suggestedArticle->getUser() === $this) {
$suggestedArticle->setUser(null);
}
}
return $this;
}
public function hasPrivilege($action)
{
if (null === $this->getRole()) {
return false;
}
if ('ROLE_ADMIN' === $this->getRole()->getName()) {
return true;
}
if ('ROLE_USER' === $this->getRole()->getName()) {
return false;
}
if (!\is_array($this->getRole()->getPrivileges())) {
return false;
}
if (\is_array($action)) {
foreach ($action as $a) {
if (!$this->hasPrivilege($a)) {
return false;
}
}
return true;
}
return \in_array($action, $this->getRole()->getPrivileges(), true);
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(?string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(?string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getZipcode(): ?string
{
return $this->zipcode;
}
public function setZipcode(?string $zipcode): self
{
$this->zipcode = $zipcode;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
public function getLegacyId(): ?int
{
return $this->legacy_id;
}
public function setLegacyId(?int $legacy_id): self
{
$this->legacy_id = $legacy_id;
return $this;
}
/**
* @ORM\Column(type="integer")
*/
private $receive_contact_messages = 0;
/**
* @ORM\OneToOne(targetEntity=Card::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $card;
public function getReceiveContactMessages(): int
{
return $this->receive_contact_messages;
}
public function setReceiveContactMessages(int $receive_contact_messages): self
{
$this->receive_contact_messages = $receive_contact_messages;
return $this;
}
public function getIsDigitalPremium(): int
{
return $this->is_digital_premium;
}
public function setIsDigitalPremium(int $is_digital_premium): self
{
$this->is_digital_premium = $is_digital_premium;
return $this;
}
/**
* @return Collection|UserOffer[]
*/
public function getUserOffers(): Collection
{
return $this->userOffers;
}
public function addUserOffer(UserOffer $userOffer): self
{
if (!$this->userOffers->contains($userOffer)) {
$this->userOffers[] = $userOffer;
$userOffer->setUser($this);
}
return $this;
}
public function removeUserOffer(UserOffer $userOffer): self
{
if ($this->userOffers->contains($userOffer)) {
$this->userOffers->removeElement($userOffer);
// set the owning side to null (unless already changed)
if ($userOffer->getUser() === $this) {
$userOffer->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserConfidentialDocument[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(UserConfidentialDocument $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setUser($this);
}
return $this;
}
public function removeDocument(UserConfidentialDocument $document): self
{
if ($this->documents->contains($document)) {
$this->documents->removeElement($document);
if ($document->getUser() === $this) {
$document->setUser(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getFacebookId()
{
return $this->facebook_id;
}
/**
* @param mixed $facebook_id
*/
public function setFacebookId($facebook_id): void
{
$this->facebook_id = $facebook_id;
}
/**
* @return mixed
*/
public function getGoogleId()
{
return $this->google_id;
}
/**
* @param mixed $google_id
*/
public function setGoogleId($google_id): void
{
$this->google_id = $google_id;
}
/**
* @return mixed
*/
public function getLinkedinId()
{
return $this->linkedin_id;
}
/**
* @param mixed $linkedin_id
*/
public function setLinkedinId($linkedin_id): void
{
$this->linkedin_id = $linkedin_id;
}
public function getAvatar(): ?Media
{
return $this->avatar;
}
public function setAvatar(?Media $avatar): self
{
$this->avatar = $avatar;
return $this;
}
/**
* @return mixed
*/
public function getBio()
{
return $this->bio;
}
/**
* @param mixed $bio
*/
public function setBio($bio): void
{
$this->bio = $bio;
}
/**
* @return mixed
*/
public function getFacebookUrl()
{
return $this->facebook_url;
}
/**
* @param mixed $facebook_url
*/
public function setFacebookUrl($facebook_url): void
{
$this->facebook_url = $facebook_url;
}
/**
* @return mixed
*/
public function getLinkedinUrl()
{
return $this->linkedin_url;
}
/**
* @param mixed $linkedin_url
*/
public function setLinkedinUrl($linkedin_url): void
{
$this->linkedin_url = $linkedin_url;
}
/**
* @return mixed
*/
public function getTwitterUrl()
{
return $this->twitter_url;
}
/**
* @param mixed $twitter_url
*/
public function setTwitterUrl($twitter_url): void
{
$this->twitter_url = $twitter_url;
}
/**
* @return mixed
*/
public function getInstagramUrl()
{
return $this->instagram_url;
}
/**
* @param mixed $instagram_url
*/
public function setInstagramUrl($instagram_url): void
{
$this->instagram_url = $instagram_url;
}
/**
* @return mixed
*/
public function getJourney()
{
return $this->journey;
}
/**
* @param mixed $journey
*/
public function setJourney($journey): void
{
$this->journey = $journey;
}
/**
* @return Collection|UserCategory[]|null
*/
public function getUserCategories(): ?Collection
{
return $this->userCategories;
}
public function addUserCategory(UserCategory $userCategory): self
{
if ($this->userCategories && !$this->userCategories->contains($userCategory)) {
$this->userCategories[] = $userCategory;
$userCategory->setUser($this);
} elseif (!$this->userCategories) {
$this->userCategories[] = $userCategory;
}
return $this;
}
public function removeUserCategory(UserCategory $userCategory): self
{
if ($this->userCategories->contains($userCategory)) {
$this->userCategories->removeElement($userCategory);
// set the owning side to null (unless already changed)
if ($userCategory->getUser() === $this) {
$userCategory->setUser(null);
}
}
return $this;
}
public function clearFavoriteCategories(): self
{
$this->userCategories = null;
return $this;
}
public function showFavoriteCategories()
{
$categories = [];
if ($this->userCategories) {
foreach ($this->userCategories as $userCategory) {
$categories[] = $userCategory->getCategory();
}
}
return $categories;
}
/**
* @return mixed
*/
public function getSecteur()
{
return $this->secteur;
}
/**
* @param mixed $secteur
*/
public function setSecteur($secteur): void
{
$this->secteur = $secteur;
}
/**
* @return mixed
*/
public function getCompany()
{
return $this->company;
}
/**
* @param mixed $company
*/
public function setCompany($company): void
{
$this->company = $company;
}
/**
* @return mixed
*/
public function getFonction()
{
return $this->fonction;
}
/**
* @param mixed $fonction
*/
public function setFonction($fonction): void
{
$this->fonction = $fonction;
}
/**
* @return mixed
*/
public function getComplementAdresse()
{
return $this->complement_adresse;
}
/**
* @param mixed $complement_adresse
*/
public function setComplementAdresse($complement_adresse): void
{
$this->complement_adresse = $complement_adresse;
}
/**
* @return ArrayCollection
*/
public function getLikes(): Collection
{
return $this->likes;
}
public function addLikes(UserLikes $like): self
{
if (!$this->likes->contains($like)) {
$this->likes[] = $like;
$like->setUser($this);
}
return $this;
}
public function removeLikes(UserLikes $like): self
{
if ($this->likes->contains($like)) {
$this->likes->removeElement($like);
// set the owning side to null (unless already changed)
if ($like->getUser() === $this) {
$like->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Cart>
*/
public function getUsersCart(): Collection
{
return $this->users_cart;
}
public function hasAddedProductCart($product): bool
{
foreach ($this->users_cart as $cart) {
if (\is_array($product)) {
if ($cart->getProduct()->getStripeId() === $product['stripe_id']) {
return true;
}
} else {
if ($cart->getProduct()->getStripeId() === $product->getStripeId()) {
return true;
}
}
}
return false;
}
public function hasAddedProductCardCheck($product): bool
{
if (null !== $this->getCard()) {
foreach ($this->getCard()->getItems() as $cart) {
if (\is_array($product)) {
if ($cart->getMagazines()->getId() === $product['product_database_id']) {
return true;
}
if ($cart->getMagazines()->getStripeId() === $product['stripe_id']) {
return true;
}
}
}
}
return false;
}
/**
* @return Collection<int, Favoris>
*/
public function getUsersFavoris(): Collection
{
return $this->users_favoris;
}
public function hasAddedProductFavorite($product): bool
{
foreach ($this->users_favoris as $favoris) {
if ($product instanceof StripeProduct) {
if ($favoris->getProduct()->getStripeId() === $product->getStripeId()) {
return true;
}
} elseif (\is_array($product)) {
if ($favoris->getProduct()->getStripeId() === $product['stripe_id']) {
return true;
}
}
}
return false;
}
/**
* @return Collection<int, ArticleFavoris>
*/
public function getArticleFavorites(): Collection
{
return $this->user_articles;
}
public function hasAddedArticleFavorite($article): bool
{
foreach ($this->user_articles as $favoris) {
if ($article instanceof Article) {
if ($favoris->getArticle()->getId() === $article->getId()) {
return true;
}
} elseif (\is_array($article)) {
if ($favoris->getArticle()->getId() === $article['id']) {
return true;
}
}
}
return false;
}
public function getDisplayName(int $maxChars = 0): ?string
{
$fullName = '';
if ($this->firstname) {
$fullName = $this->firstname.' '.$this->lastname;
} elseif ($this->pseudo) {
$fullName = $this->pseudo;
} else {
$fullName = $this->email;
}
if ($maxChars > 0 && \mb_strlen($fullName) > $maxChars) {
$fullName = trim(mb_substr($fullName, 0, $maxChars)).'...';
}
return ucfirst($fullName);
}
public function getCard(): ?Card
{
return $this->card;
}
public function setCard(Card $card): self
{
// set the owning side of the relation if necessary
if ($card->getUser() !== $this) {
$card->setUser($this);
}
$this->card = $card;
return $this;
}
/**
* @return mixed
*/
public function getYoutubeUrl()
{
return $this->youtube_url;
}
/**
* @param mixed $youtube_url
*/
public function setYoutubeUrl($youtube_url): void
{
$this->youtube_url = $youtube_url;
}
}