nineskeletor/src/Entity/User.php

681 lines
14 KiB
PHP

<?php
namespace App\Entity;
use App\Validator;
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\LegacyPasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity
* @ORM\Table(name="useraccount")
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
*
* @UniqueEntity(fields="username", message="Un utilisateur existe déjà avec ce login.")
* @UniqueEntity(fields="email", message="Un utilisateur existe déjà avec ce mail.")
*/
class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=128, unique=true)
* @Validator\Userusername()
*/
private $username;
/**
* @ORM\Column(type="string")
*/
private $apikey;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $lastname;
/**
* @var array
*
* @ORM\Column(type="array", length=255)
*/
private $roles = [];
/**
* @ORM\Column(type="string", length=250)
*/
private $password;
/**
* @Validator\Password()
*/
private $passwordplain;
/**
* @ORM\Column(type="string", length=250)
*/
private $salt;
/**
* @ORM\Column(type="boolean")
*/
protected $isactive;
/**
* @ORM\Column(type="string", length=128, unique=true)
*/
private $email;
/**
* @ORM\Column(type="string", length=250, nullable=true, options={"default" : 0})
*/
private $avatar;
/**
* @ORM\Column(type="boolean")
*/
protected $isvisible;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $postaladress;
/**
* @ORM\Column(type="string", length=60, nullable=true)
*/
private $telephonenumber;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $job;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $position;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $motivation;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $note;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $preference;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $keyexpire;
/**
* @ORM\Column(type="string", length=60, nullable=true)
*/
private $keyvalue;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $visitedate;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $visitecpt;
/**
* @ORM\ManyToOne(targetEntity="Niveau01", inversedBy="users")
* @ORM\JoinColumn(nullable=false)
*/
private $niveau01;
/**
* @ORM\ManyToOne(targetEntity="Niveau02", inversedBy="users")
*/
private $niveau02;
/**
* @ORM\ManyToOne(targetEntity="Niveau03", inversedBy="users")
*/
private $niveau03;
/**
* @ORM\ManyToOne(targetEntity="Niveau04", inversedBy="users")
*/
private $niveau04;
/**
* @var ArrayCollection
* @var UserGroup
*
* @ORM\OneToMany(targetEntity="UserGroup", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
*/
private $groups;
/**
* @var ArrayCollection
* @var Group
*
* @ORM\OneToMany(targetEntity="Group", mappedBy="owner", cascade={"persist"}, orphanRemoval=false)
*/
private $ownergroups;
/**
* @var ArrayCollection
* @var UserGroup
*
* @ORM\OneToMany(targetEntity="UserModo", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
*/
private $modos;
public function __construct()
{
$this->groups = new ArrayCollection();
$this->ownergroups = new ArrayCollection();
$this->modos = new ArrayCollection();
}
// == CODE A NE PAS REGENERER
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getUserIdentifier(): string
{
return $this->username;
}
public function setPasswordDirect($password)
{
// Permet de setter le password généré lors de l'inscription
$this->password = $password;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword($password): self
{
if ($password != $this->password && '' != $password) {
// Placer le password non encodé dans une variable tempo sur laquel on va appliquer la contraite de form
$this->passwordplain = $password;
// Password encrypté format openldap
$this->salt = uniqid(mt_rand(), true);
$hash = '{SSHA}'.base64_encode(pack('H*', sha1($password.$this->salt)).$this->salt);
$this->password = $hash;
}
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 $this->salt;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
$this->passwordplain = null;
}
public function getRoles(): array
{
return $this->roles;
}
public function hasRole(string $role): ?bool
{
return in_array($role, $this->getRoles());
}
public function setRole(string $role): self
{
if (!$this->hasRole($role)) {
array_push($this->roles, $role);
}
return $this;
}
public function getDisplayname()
{
return $this->firstname.' '.$this->lastname.(!$this->isactive ? ' (inactif)' : '');
}
public function getFullname()
{
return $this->username.' = '.$this->firstname.' '.$this->lastname.(!$this->isactive ? ' (inactif)' : '');
}
// == FIN DU CODE A NE PAS REGENERER
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getApikey(): ?string
{
return $this->apikey;
}
public function setApikey(string $apikey): self
{
$this->apikey = $apikey;
return $this;
}
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 setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function setSalt(string $salt): self
{
$this->salt = $salt;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getAvatar(): ?string
{
return $this->avatar;
}
public function setAvatar(?string $avatar): self
{
$this->avatar = $avatar;
return $this;
}
public function isIsvisible(): ?bool
{
return $this->isvisible;
}
public function setIsvisible(bool $isvisible): self
{
$this->isvisible = $isvisible;
return $this;
}
public function getPostaladress(): ?string
{
return $this->postaladress;
}
public function setPostaladress(?string $postaladress): self
{
$this->postaladress = $postaladress;
return $this;
}
public function getTelephonenumber(): ?string
{
return $this->telephonenumber;
}
public function setTelephonenumber(?string $telephonenumber): self
{
$this->telephonenumber = $telephonenumber;
return $this;
}
public function getJob(): ?string
{
return $this->job;
}
public function setJob(?string $job): self
{
$this->job = $job;
return $this;
}
public function getPosition(): ?string
{
return $this->position;
}
public function setPosition(?string $position): self
{
$this->position = $position;
return $this;
}
public function getMotivation(): ?string
{
return $this->motivation;
}
public function setMotivation(?string $motivation): self
{
$this->motivation = $motivation;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
public function getPreference(): ?array
{
return $this->preference;
}
public function setPreference(?array $preference): self
{
$this->preference = $preference;
return $this;
}
public function getKeyexpire(): ?\DateTimeInterface
{
return $this->keyexpire;
}
public function setKeyexpire(?\DateTimeInterface $keyexpire): self
{
$this->keyexpire = $keyexpire;
return $this;
}
public function getKeyvalue(): ?string
{
return $this->keyvalue;
}
public function setKeyvalue(?string $keyvalue): self
{
$this->keyvalue = $keyvalue;
return $this;
}
public function getVisitedate(): ?\DateTimeInterface
{
return $this->visitedate;
}
public function setVisitedate(?\DateTimeInterface $visitedate): self
{
$this->visitedate = $visitedate;
return $this;
}
public function getVisitecpt(): ?int
{
return $this->visitecpt;
}
public function setVisitecpt(?int $visitecpt): self
{
$this->visitecpt = $visitecpt;
return $this;
}
public function getNiveau01(): ?Niveau01
{
return $this->niveau01;
}
public function setNiveau01(?Niveau01 $niveau01): self
{
$this->niveau01 = $niveau01;
return $this;
}
public function getNiveau02(): ?Niveau02
{
return $this->niveau02;
}
public function setNiveau02(?Niveau02 $niveau02): self
{
$this->niveau02 = $niveau02;
return $this;
}
/**
* @return Collection<int, UserGroup>
*/
public function getGroups(): Collection
{
return $this->groups;
}
public function addGroup(UserGroup $group): self
{
if (!$this->groups->contains($group)) {
$this->groups[] = $group;
$group->setUser($this);
}
return $this;
}
public function removeGroup(UserGroup $group): self
{
if ($this->groups->removeElement($group)) {
// set the owning side to null (unless already changed)
if ($group->getUser() === $this) {
$group->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Group>
*/
public function getOwnergroups(): Collection
{
return $this->ownergroups;
}
public function addOwnergroup(Group $ownergroup): self
{
if (!$this->ownergroups->contains($ownergroup)) {
$this->ownergroups[] = $ownergroup;
$ownergroup->setOwner($this);
}
return $this;
}
public function removeOwnergroup(Group $ownergroup): self
{
if ($this->ownergroups->removeElement($ownergroup)) {
// set the owning side to null (unless already changed)
if ($ownergroup->getOwner() === $this) {
$ownergroup->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, UserModo>
*/
public function getModos(): Collection
{
return $this->modos;
}
public function addModo(UserModo $modo): self
{
if (!$this->modos->contains($modo)) {
$this->modos[] = $modo;
$modo->setUser($this);
}
return $this;
}
public function removeModo(UserModo $modo): self
{
if ($this->modos->removeElement($modo)) {
// set the owning side to null (unless already changed)
if ($modo->getUser() === $this) {
$modo->setUser(null);
}
}
return $this;
}
public function getNiveau03(): ?Niveau03
{
return $this->niveau03;
}
public function setNiveau03(?Niveau03 $niveau03): self
{
$this->niveau03 = $niveau03;
return $this;
}
public function getNiveau04(): ?Niveau04
{
return $this->niveau04;
}
public function setNiveau04(?Niveau04 $niveau04): self
{
$this->niveau04 = $niveau04;
return $this;
}
public function isIsactive(): ?bool
{
return $this->isactive;
}
public function setIsactive(bool $isactive): self
{
$this->isactive = $isactive;
return $this;
}
}