<?php
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
#[UniqueEntity(fields: ['nom'], message: 'There is already an account with this name')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180)]
#[Groups(['show_search'])]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\Column(length: 255, nullable: false, unique: true)]
#[Groups(['show_search'])]
private ?string $nom = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['show_search'])]
private ?string $prenom = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['show_search'])]
private ?string $image_profie = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $date_creation = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $date_modification = null;
#[ORM\Column]
private ?bool $active = null;
#[ORM\ManyToMany(targetEntity: Roles::class, inversedBy: 'users')]
private Collection $roles_user;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Session::class)]
private Collection $sessions;
#[ORM\OneToMany(mappedBy: 'creer_par', targetEntity: OrderFabrication::class)]
private Collection $orderFabrications;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Opportunity::class)]
private Collection $opportunities;
#[ORM\Column(length: 255, nullable: true)]
private ?string $company_name = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $identifiant_odoo = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $display_name = null;
#[ORM\OneToMany(mappedBy: 'created_by', targetEntity: OrderFabricationTypes::class)]
private Collection $orderFabricationTypes;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: OrderHistory::class)]
private Collection $orderHistories;
public function __construct()
{
$this->roles = ['ROLE_USER'];
$this->roles_user = new ArrayCollection();
$this->sessions = new ArrayCollection();
$this->orderFabrications = new ArrayCollection();
$this->opportunities = new ArrayCollection();
$this->orderFabricationTypes = new ArrayCollection();
$this->orderHistories = new ArrayCollection();
}
/**
* fill all class properties from array
*
* @param array $row => array of properties
* @return self
*/
public static function withRow( array $row , $instance = null) {
if(empty($instance))
$instance = new self();
$instance->fill($row);
return $instance;
}
protected function fill( array $row ) {
// fill all properties from array
foreach($row as $key=>$value)
{
$this->$key = $value;
}
}
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;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(?string $prenom): self
{
$this->prenom = $prenom;
return $this;
}
public function getImageProfie(): ?string
{
return $this->image_profie;
}
public function setImageProfie(?string $image_profie): self
{
$this->image_profie = $image_profie;
return $this;
}
public function getDateCreation(): ?\DateTimeInterface
{
return $this->date_creation;
}
public function setDateCreation(\DateTimeInterface $date_creation): self
{
$this->date_creation = $date_creation;
return $this;
}
public function getDateModification(): ?\DateTimeInterface
{
return $this->date_modification;
}
public function setDateModification(\DateTimeInterface $date_modification): self
{
$this->date_modification = $date_modification;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
/**
* @return Collection<int, Roles>
*/
public function getRolesUser(): Collection
{
return $this->roles_user;
}
public function addRolesUser(Roles $rolesUser): self
{
if (!$this->roles_user->contains($rolesUser)) {
$this->roles_user->add($rolesUser);
}
return $this;
}
public function removeRolesUser(Roles $rolesUser): self
{
$this->roles_user->removeElement($rolesUser);
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;
}
/**
* @return Collection<int, OrderFabrication>
*/
public function getOrderFabrications(): Collection
{
return $this->orderFabrications;
}
public function addOrderFabrication(OrderFabrication $orderFabrication): self
{
if (!$this->orderFabrications->contains($orderFabrication)) {
$this->orderFabrications->add($orderFabrication);
$orderFabrication->setCreerPar($this);
}
return $this;
}
/*
* @return Collection<int, Opportunity>
*/
public function getOpportunities(): Collection
{
return $this->opportunities;
}
public function addOpportunity(Opportunity $opportunity): self
{
if (!$this->opportunities->contains($opportunity)) {
$this->opportunities->add($opportunity);
$opportunity->setUser($this);
}
return $this;
}
public function removeOrderFabrication(OrderFabrication $orderFabrication): self
{
if ($this->orderFabrications->removeElement($orderFabrication)) {
// set the owning side to null (unless already changed)
if ($orderFabrication->getCreerPar() === $this) {
$orderFabrication->setCreerPar(null);
}
}
return $this;
}
public function removeOpportunity(Opportunity $opportunity): self
{
if ($this->opportunities->removeElement($opportunity)) {
// set the owning side to null (unless already changed)
if ($opportunity->getUser() === $this) {
$opportunity->setUser(null);
}
}
return $this;
}
public function getCompanyName(): ?string
{
return $this->company_name;
}
public function setCompanyName(?string $company_name): self
{
$this->company_name = $company_name;
return $this;
}
public function getIdentifiantOdoo(): ?string
{
return $this->identifiant_odoo;
}
public function setIdentifiantOdoo(?string $identifiant_odoo): self
{
$this->identifiant_odoo = $identifiant_odoo;
return $this;
}
public function getDisplayName(): ?string
{
return $this->display_name;
}
public function setDisplayName(?string $display_name): self
{
$this->display_name = $display_name;
return $this;
}
// when print object, it tansforme it to string
public function __toString()
{
return $this->display_name;
}
/*
* @return Collection<int, OrderFabricationTypes>
*/
public function getOrderFabricationTypes(): Collection
{
return $this->orderFabricationTypes;
}
public function addOrderFabricationType(OrderFabricationTypes $orderFabricationType): self
{
if (!$this->orderFabricationTypes->contains($orderFabricationType)) {
$this->orderFabricationTypes->add($orderFabricationType);
$orderFabricationType->setCreatedBy($this);
}
return $this;
}
public function removeOrderFabricationType(OrderFabricationTypes $orderFabricationType): self
{
if ($this->orderFabricationTypes->removeElement($orderFabricationType)) {
// set the owning side to null (unless already changed)
if ($orderFabricationType->getCreatedBy() === $this) {
$orderFabricationType->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, OrderHistory>
*/
public function getOrderHistories(): Collection
{
return $this->orderHistories;
}
public function addOrderHistory(OrderHistory $orderHistory): self
{
if (!$this->orderHistories->contains($orderHistory)) {
$this->orderHistories->add($orderHistory);
$orderHistory->setUser($this);
}
return $this;
}
public function removeOrderHistory(OrderHistory $orderHistory): self
{
if ($this->orderHistories->removeElement($orderHistory)) {
// set the owning side to null (unless already changed)
if ($orderHistory->getUser() === $this) {
$orderHistory->setUser(null);
}
}
return $this;
}
}