src/Entity/User.php line 26
<?php
namespace App\Entity;
use App\EntityListener\UserListener;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use Serializable;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
#[ORM\HasLifecycleCallbacks]
#[Vich\Uploadable]
#[UniqueEntity(fields: ['username'], message: 'Il existe déjà un compte avec ce nom d\'utilisateur')]
#[ORM\EntityListeners([UserListener::class])]
class User implements UserInterface, PasswordAuthenticatedUserInterface, Serializable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $username = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $firstName = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastName = null;
#[ORM\ManyToOne(inversedBy: 'users')]
#[ORM\JoinColumn(nullable: true)]
private ?Role $role = null;
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $email = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $phone = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, options: [
"default" => null
])]
private ?string $imageName = null;
#[Vich\UploadableField(mapping: 'user_img', fileNameProperty: 'imageName', size: 'imageSize')]
private ?File $imageFile = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $imageSize = null;
#[ORM\Column(type: Types::BOOLEAN, options: ["default" => "0"])]
private bool $isVerified = false;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, options: [
"default" => "CURRENT_TIMESTAMP"
])]
private ?DateTimeImmutable $createdAt = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, options: [
"default" => "CURRENT_TIMESTAMP"
])]
private ?DateTimeImmutable $updatedAt = null;
#[ORM\Column(type: Types::BOOLEAN, options: ["default" => "0"])]
private ?bool $isActivated = false;
#[ORM\Column(type: Types::BOOLEAN, options: ["default" => "0"])]
private ?bool $isDeleted = false;
#[ORM\ManyToOne(inversedBy: 'users')]
private ?GasStation $gasStation = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Order::class)]
private Collection $orders;
#[ORM\OneToMany(mappedBy: 'sender', targetEntity: Message::class)]
private Collection $senders;
#[ORM\OneToMany(mappedBy: 'receiver', targetEntity: Message::class)]
private Collection $receivers;
#[ORM\OneToMany(mappedBy: 'copy', targetEntity: Message::class)]
private Collection $copies;
#[ORM\OneToMany(mappedBy: 'replyTo', targetEntity: Message::class)]
private Collection $repliesTo;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Session::class)]
private Collection $sessions;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->senders = new ArrayCollection();
$this->receivers = new ArrayCollection();
$this->copies = new ArrayCollection();
$this->repliesTo = new ArrayCollection();
$this->sessions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): ?string
{
return (string)$this->username;
}
public function setUsername(?string $username): self
{
$this->username = $username;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string)$this->username;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
if($this->password != null)
return $this->password;
return "";
}
/**
* @param string|null $password
* @return $this
*/
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;
}
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 getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
/**
* @return string|null
*/
public function getImageName(): ?string
{
return $this->imageName;
}
/**
* @param string|null $imageName
*/
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
/**
* @param File|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
$this->updatedAt = new DateTimeImmutable;
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(?bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function isIsActivated(): ?bool
{
return $this->isActivated;
}
public function setIsActivated(bool $isActivated): self
{
$this->isActivated = $isActivated;
return $this;
}
public function isIsDeleted(): ?bool
{
return $this->isDeleted;
}
public function setIsDeleted(bool $isDeleted): self
{
$this->isDeleted = $isDeleted;
return $this;
}
public function getRole(): ?Role
{
return $this->role;
}
public function setRole(?Role $role): self
{
$this->role = $role;
return $this;
}
public function getRoles(): array
{
return [];
}
/** @see \Serializable::serialize() */
public function serialize(): ?string
{
return serialize(array(
$this->id,
$this->username,
$this->firstName,
$this->lastName,
$this->password,
$this->email,
$this->phone,
$this->isVerified,
$this->isActivated,
$this->gasStation,
));
}
/** @param $serialized
* @see \Serializable::unserialize()
*/
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->firstName,
$this->lastName,
$this->password,
$this->email,
$this->phone,
$this->isVerified,
$this->isActivated,
$this->gasStation,
) = unserialize($serialized, array('allowed_classes' => false));
}
public function getGasStation(): ?GasStation
{
return $this->gasStation;
}
public function setGasStation(?GasStation $gasStation): self
{
$this->gasStation = $gasStation;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setUser($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getUser() === $this) {
$order->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Message>
*/
public function getSenders(): Collection
{
return $this->senders;
}
public function addSender(Message $sender): self
{
if (!$this->senders->contains($sender)) {
$this->senders->add($sender);
$sender->setSender($this);
}
return $this;
}
public function removeSender(Message $sender): self
{
if ($this->senders->removeElement($sender)) {
// set the owning side to null (unless already changed)
if ($sender->getSender() === $this) {
$sender->setSender(null);
}
}
return $this;
}
/**
* @return Collection<int, Message>
*/
public function getReceivers(): Collection
{
return $this->receivers;
}
public function addReceiver(Message $receiver): self
{
if (!$this->receivers->contains($receiver)) {
$this->receivers->add($receiver);
$receiver->setReceiver($this);
}
return $this;
}
public function removeReceiver(Message $receiver): self
{
if ($this->receivers->removeElement($receiver)) {
// set the owning side to null (unless already changed)
if ($receiver->getReceiver() === $this) {
$receiver->setReceiver(null);
}
}
return $this;
}
/**
* @return Collection<int, Message>
*/
public function getCopies(): Collection
{
return $this->copies;
}
public function addCopy(Message $copy): self
{
if (!$this->copies->contains($copy)) {
$this->copies->add($copy);
$copy->setCopy($this);
}
return $this;
}
public function removeCopy(Message $copy): self
{
if ($this->copies->removeElement($copy)) {
// set the owning side to null (unless already changed)
if ($copy->getCopy() === $this) {
$copy->setCopy(null);
}
}
return $this;
}
/**
* @return Collection<int, Message>
*/
public function getRepliesTo(): Collection
{
return $this->repliesTo;
}
public function addRepliesTo(Message $repliesTo): self
{
if (!$this->repliesTo->contains($repliesTo)) {
$this->repliesTo->add($repliesTo);
$repliesTo->setReplyTo($this);
}
return $this;
}
public function removeRepliesTo(Message $repliesTo): self
{
if ($this->repliesTo->removeElement($repliesTo)) {
// set the owning side to null (unless already changed)
if ($repliesTo->getReplyTo() === $this) {
$repliesTo->setReplyTo(null);
}
}
return $this;
}
/**
* @return Collection<int, Session>
*/
public function getSessions(): Collection
{
return $this->sessions;
}
public function addSession(Session $session): self
{
if (!$this->sessions->contains($session)) {
$this->sessions->add($session);
$session->setUser($this);
}
return $this;
}
public function removeSession(Session $session): self
{
if ($this->sessions->removeElement($session)) {
// set the owning side to null (unless already changed)
if ($session->getUser() === $this) {
$session->setUser(null);
}
}
return $this;
}
}