<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Serializable;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @UniqueEntity("EmailUser",message="Cette email est déjà utilisé")
* @Vich\Uploadable()
* @method string getUserIdentifier()*/
class User implements UserInterface, Serializable
{
const TypeCompte = [
//0 => 'Signature',
1 => 'parc'
];
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* Nom du user
* @ORM\Column(type="string", length=255)
* @Assert\Length(min="1", minMessage="Champ obligatoire")
*/
private $NomUser;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Length(min=5,max=255)
*/
private $EmailUser;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Length(
* min=8,
* minMessage="Mot de passe courte, au moins 8 caractères"
* )
*/
private $PasswordUser;
/**
* @Assert\EqualTo(propertyPath="PasswordUser",message="Ne correspond pas au mot de passe")
*/
private $ConfirmationPassword;
private $AncienPassword;
private $AncienPasswordConfirem;
/**
* @ORM\Column(type="datetime")
*/
private $Created_at;
/**
* @ORM\Column(type="integer")
*/
private $TypeCompteUser;
/**
* @ORM\Column(type="integer")
*/
private $EtatCompteUser;
/**
* @ORM\Column(type="integer")
* @Assert\Type(type="integer",message="Champs de type Entier")
*/
private $NumTelUser;
/**
* @ORM\Column(type="string", length=255)
*/
private $ImageFile;
/**
* @ORM\Column(type="string", length=500)
*/
private $FirebaseToken;
/**
* @ORM\Column(type="string", length=500)
*/
private $textDePrifil;
/**
* @var File|null
* @Assert\File(
* maxSize="5242880",
* mimeTypes = {
* "image/png",
* "image/jpeg",
* "image/jpg"
* },
* mimeTypesMessage = "Ce fichier doit être une image")
* )
*/
private $fileName;
/**
* @var
*/
private $base64img;
/**
* @var
*/
private $flag;
/**
* @ORM\Column(type="datetime")
*/
private $Connected_at;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Eglise", inversedBy="users")
*/
private $eglise;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Clan", inversedBy="users")
*/
private $clan;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ImageUser", mappedBy="user")
*/
private $image;
/**
* @ORM\OneToMany(targetEntity="App\Entity\PostLike", mappedBy="user")
*/
private $likes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\PostComment", mappedBy="user")
*/
private $postComments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\PostLikeComment", mappedBy="user")
*/
private $postLikeComments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Media", mappedBy="user_pub")
*/
private $media;
/**
* @var
*/
private $codeValidation;
/**
* @Assert\EqualTo(propertyPath="codeValidation",message="Code invalide; Réessayer à nouveau")
*/
private $ConfirCodeValidation;
/**
* @ORM\Column(type="string", length=255)
*/
private $image_file_signature;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserPreference", mappedBy="userPrefere")
*/
private $userPreferences;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserPreference", mappedBy="userPreferer")
*/
private $userPreferer;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserLike", mappedBy="userQuiEstLiked")
*/
private $userQuiEstLiker;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserLike", mappedBy="userQuiLiked")
*/
private $userQuiLike;
/**
* @ORM\Column(type="string", length=255)
*/
private $roles;
public function __toString()
{
return $this->NomUser;
}
public function __construct()
{
$this->Created_at = new \DateTime();
$this->Connected_at = new \DateTime();
$this->EtatCompteUser = 0;
$this->textDePrifil = 'Je suis, Par ce que nous sommes 🎹🎤🪗🪘🎻🎸';
$this->ImageFile = '0';
$this->image_file_signature = '0';
$this->image = new ArrayCollection();
$this->likes = new ArrayCollection();
//$this->comments = new ArrayCollection();
$this->postComments = new ArrayCollection();
$this->postLikeComments = new ArrayCollection();
$this->media = new ArrayCollection();
$this->userPreferences = new ArrayCollection();
$this->userPreferer = new ArrayCollection();
$this->userQuiEstLiker = new ArrayCollection();
$this->userQuiLike = new ArrayCollection();
$this->FirebaseToken = '';
$this->TypeCompteUser = '1';
}
public function getId(): ?int
{
return $this->id;
}
public function getId_(): ?int
{
return $this->id;
}
public function getSlugId(): ?string
{
// return (new Slugify())->slugify((string)$this->PasswordUser);
return $this->PasswordUser;
}
public function getNomUser(): ?string
{
return $this->NomUser;
}
public function setNomUser(string $NomUser): self
{
$this->NomUser = $NomUser;
return $this;
}
/**
* @return mixed
*/
public function getTextDePrifil(): ?string
{
return $this->textDePrifil;
}
public function setTextDePrifil(String $textDePrifil)
{
$this->textDePrifil = $textDePrifil;
return $this;
}
public function getFirebaseToken(): ?string
{
return $this->FirebaseToken;
}
public function setFirebaseToken(String $FirebaseToken)
{
$this->FirebaseToken = $FirebaseToken;
return $this;
}
public function getEmailUser(): ?string
{
return $this->EmailUser;
}
public function setEmailUser(string $EmailUser): self
{
$this->EmailUser = $EmailUser;
return $this;
}
public function getPasswordUser(): ?string
{
return $this->PasswordUser;
}
public function setPasswordUser(string $PasswordUser): self
{
$this->PasswordUser = $PasswordUser;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->Created_at;
}
public function setCreatedAt(\DateTimeInterface $Created_at): self
{
$this->Created_at = $Created_at;
return $this;
}
public function getTypeCompteUser(): ?int
{
return $this->TypeCompteUser;
}
public function setTypeCompteUser(int $TypeCompteUser): self
{
$this->TypeCompteUser = $TypeCompteUser;
return $this;
}
public function getEtatCompteUser(): ?int
{
return $this->EtatCompteUser;
}
public function setEtatCompteUser(int $EtatCompteUser): self
{
$this->EtatCompteUser = $EtatCompteUser;
return $this;
}
public function getNumTelUser(): ?int
{
return $this->NumTelUser;
}
public function setNumTelUser(int $NumTelUser): self
{
$this->NumTelUser = $NumTelUser;
return $this;
}
public function getImageFile()
{
return $this->ImageFile;
}
public function setImageFile($ImageFile): void
{
$this->ImageFile = $ImageFile;
}
public function getConfirmationPassword()
{
return $this->ConfirmationPassword;
}
public function setConfirmationPassword($ConfirmationPassword): void
{
$this->ConfirmationPassword = $ConfirmationPassword;
}
public function getFlag()
{
return $this->flag;
}
public function setFlag($flag): void
{
$this->flag = $flag;
}
public function eraseCredentials(){
}
public function getSalt(){
return null;
}
public function getRoles(){
return [$this->roles];
// return $this->roles;
}
public function setRoles(string $roles): self
{
$this->roles = $roles;
return $this;
}
public function getPassword(){
return $this->PasswordUser;
}
public function getUsername(){
return $this->NomUser;
}
public function getConnectedAt(): ?\DateTime
{
return $this->Connected_at;
}
public function setConnectedAt(\DateTime $Connected_at): self
{
$this->Connected_at = $Connected_at;
return $this;
}
public function getEglise(): ?Eglise
{
return $this->eglise;
}
public function setEglise(?Eglise $eglise): self
{
$this->eglise = $eglise;
return $this;
}
public function getClan(): ?Clan
{
return $this->clan;
}
public function setClan(?Clan $clan): self
{
$this->clan = $clan;
return $this;
}
/**
* @return Collection|ImageUser[]
*/
public function getImage(): Collection
{
return $this->image;
}
public function addImage(ImageUser $image): self
{
if (!$this->image->contains($image)) {
$this->image[] = $image;
$image->setUser($this);
}
return $this;
}
public function removeImage(ImageUser $image): self
{
if ($this->image->contains($image)) {
$this->image->removeElement($image);
// set the owning side to null (unless already changed)
if ($image->getUser() === $this) {
$image->setUser(null);
}
}
return $this;
}
/**
* @return null|File
*/
public function getFileName(): ?File
{
return $this->fileName;
}
/**
* @param null|File $fileName
*/
public function setFileName(?File $fileName): void
{
$this->fileName = $fileName;
}
/**
* @return mixed
*/
public function getBase64img()
{
return $this->base64img;
}
/**
* @param mixed $base64img
*/
public function setBase64img($base64img): void
{
$this->base64img = $base64img;
}
public function getSlug(): ?string
{
//return (new Slugify())->slugify($this->id);
return $this->id;
}
/**
* String representation of object
* @link http://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
* @since 5.1.0
*/
public function serialize()
{
return serialize([
$this->id,
$this->NomUser,
$this->EmailUser,
$this->PasswordUser,
$this->clan,
$this->eglise
]);
}
/**
* Constructs the object
* @link http://php.net/manual/en/serializable.unserialize.php
* @param string $serialized <p>
* The string representation of the object.
* </p>
* @return void
* @since 5.1.0
*/
public function unserialize($serialized)
{
list(
$this->id,
$this->NomUser,
$this->EmailUser,
$this->PasswordUser,
$this->clan,
$this->eglise
) = unserialize($serialized,['allowed_classes' => false]);
}
/**
* @return Collection|PostLike[]
*/
public function getLikes(): Collection
{
return $this->likes;
}
public function addLike(PostLike $like): self
{
if (!$this->likes->contains($like)) {
$this->likes[] = $like;
$like->setUser($this);
}
return $this;
}
public function removeLike(PostLike $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|PostComment[]
*/
public function getPostComments(): Collection
{
return $this->postComments;
}
public function addPostComment(PostComment $postComment): self
{
if (!$this->postComments->contains($postComment)) {
$this->postComments[] = $postComment;
$postComment->setUser($this);
}
return $this;
}
public function removePostComment(PostComment $postComment): self
{
if ($this->postComments->contains($postComment)) {
$this->postComments->removeElement($postComment);
// set the owning side to null (unless already changed)
if ($postComment->getUser() === $this) {
$postComment->setUser(null);
}
}
return $this;
}
/**
* @return Collection|PostLikeComment[]
*/
public function getPostLikeComments(): Collection
{
return $this->postLikeComments;
}
public function addPostLikeComment(PostLikeComment $postLikeComment): self
{
if (!$this->postLikeComments->contains($postLikeComment)) {
$this->postLikeComments[] = $postLikeComment;
$postLikeComment->setUser($this);
}
return $this;
}
public function removePostLikeComment(PostLikeComment $postLikeComment): self
{
if ($this->postLikeComments->contains($postLikeComment)) {
$this->postLikeComments->removeElement($postLikeComment);
// set the owning side to null (unless already changed)
if ($postLikeComment->getUser() === $this) {
$postLikeComment->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Media[]
*/
public function getMedia(): Collection
{
return $this->media;
}
public function addMedium(Media $medium): self
{
if (!$this->media->contains($medium)) {
$this->media[] = $medium;
$medium->setUserPub($this);
}
return $this;
}
public function removeMedium(Media $medium): self
{
if ($this->media->contains($medium)) {
$this->media->removeElement($medium);
// set the owning side to null (unless already changed)
if ($medium->getUserPub() === $this) {
$medium->setUserPub(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getCodeValidation()
{
return $this->codeValidation;
}
/**
* @param mixed $codeValidation
*/
public function setCodeValidation($codeValidation): void
{
$this->codeValidation = $codeValidation;
}
/**
* @return mixed
*/
public function getConfirCodeValidation()
{
return $this->ConfirCodeValidation;
}
/**
* @param mixed $ConfirCodeValidation
*/
public function setConfirCodeValidation($ConfirCodeValidation): void
{
$this->ConfirCodeValidation = $ConfirCodeValidation;
}
public function getImageFileSignature(): ?string
{
return $this->image_file_signature;
}
public function setImageFileSignature(string $image_file_signature): self
{
$this->image_file_signature = $image_file_signature;
return $this;
}
/**
* @return Collection|UserPreference[]
*/
public function getUserPreferences()
{
return $this->id;
}
public function addUserPreference(UserPreference $userPreference): self
{
if (!$this->userPreferences->contains($userPreference)) {
$this->userPreferences[] = $userPreference;
$userPreference->setUserPrefere($this);
}
return $this;
}
public function removeUserPreference(UserPreference $userPreference): self
{
if ($this->userPreferences->contains($userPreference)) {
$this->userPreferences->removeElement($userPreference);
// set the owning side to null (unless already changed)
if ($userPreference->getUserPrefere() === $this) {
$userPreference->setUserPrefere(null);
}
}
return $this;
}
/**
* @return Collection|UserPreference[]
*/
public function getUserPreferer()
{
return $this->userPreferer;
}
public function addUserPreferer(UserPreference $userPreferer): self
{
if (!$this->userPreferer->contains($userPreferer)) {
$this->userPreferer[] = $userPreferer;
$userPreferer->setUserPreferer($this);
}
return $this;
}
public function removeUserPreferer(UserPreference $userPreferer): self
{
if ($this->userPreferer->contains($userPreferer)) {
$this->userPreferer->removeElement($userPreferer);
// set the owning side to null (unless already changed)
if ($userPreferer->getUserPreferer() === $this) {
$userPreferer->setUserPreferer(null);
}
}
return $this;
}
/**
* Choeur déjà préféré par un user
* @param User $user
* @return bool
*/
public function isPreferedBy(User $user):bool {
foreach ($this->getUserPreferer() as $prefere){
if($prefere->getUserPrefere() == $user) return true;
}
return false;
}
/**
* @return mixed
*/
public function getAncienPassword()
{
return $this->AncienPassword;
}
/**
* @param mixed $AncienPassword
*/
public function setAncienPassword($AncienPassword): void
{
$this->AncienPassword = $AncienPassword;
}
/**
* @return mixed
*/
public function getAncienPasswordConfirem()
{
return $this->AncienPasswordConfirem;
}
/**
* @param mixed $AncienPasswordConfirem
*/
public function setAncienPasswordConfirem($AncienPasswordConfirem): void
{
$this->AncienPasswordConfirem = $AncienPasswordConfirem;
}
public function __call($name, $arguments)
{
// TODO: Implement @method string getUserIdentifier()
}
/**
* @return Collection|UserLike[]
*/
public function getUserQuiEstLiker(): Collection
{
return $this->userQuiEstLiker;
}
public function addUserQuiEstLiker(UserLike $userLike): self
{
if (!$this->userQuiEstLiker->contains($userLike)) {
$this->userQuiEstLiker[] = $userLike;
$userLike->setUserQuiEstLiked($this);
}
return $this;
}
public function removeUserQuiEstLiker(UserLike $userLike): self
{
if ($this->userQuiEstLiker->contains($userLike)) {
$this->userQuiEstLiker->removeElement($userLike);
// set the owning side to null (unless already changed)
if ($userLike->getUserQuiEstLiked() === $this) {
$userLike->setUserQuiEstLiked(null);
}
}
return $this;
}
/**
* @return Collection|UserLike[]
*/
public function getUserQuiLike(): Collection
{
return $this->userQuiLike;
}
public function addUserQuiLike(UserLike $userLike): self
{
if (!$this->userQuiLike->contains($userLike)) {
$this->userQuiLike[] = $userLike;
$userLike->setUserQuiLiked($this);
}
return $this;
}
public function removeUserQuiLike(UserLike $userLike): self
{
if ($this->userQuiLike->contains($userLike)) {
$this->userQuiLike->removeElement($userLike);
if ($userLike->getUserQuiLiked() === $this) {
$userLike->setUserQuiLiked(null);
}
}
return $this;
}
/**
* Choeur déjà préféré par un user
* @param User $user
* @return bool
*/
public function isLikedBy(User $user):bool {
foreach ($this->getUserQuiEstLiker() as $liked){
if($liked->getUserQuiLiked() == $user) return true;
}
return false;
}
}