413 lines
8.7 KiB
PHP
Executable File
413 lines
8.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
|
|
|
|
/**
|
|
* User
|
|
*
|
|
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
|
|
* @ORM\Table(name="user",indexes={@ORM\Index(name="username", columns={"username"})})
|
|
* @UniqueEntity("username", message="Ce nom d'utilisateur existe dèja")
|
|
*/
|
|
|
|
class User implements UserInterface, \Serializable
|
|
{
|
|
/**
|
|
* @var int
|
|
*
|
|
* @ORM\Column(name="id", type="integer")
|
|
* @ORM\Id
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @var string
|
|
*
|
|
* @ORM\Column(name="username", type="string", length=255)
|
|
*/
|
|
private $username;
|
|
|
|
/**
|
|
* @var string
|
|
*
|
|
* @ORM\Column(name="password", type="string", length=255)
|
|
*/
|
|
private $password;
|
|
|
|
/**
|
|
* @var array
|
|
*
|
|
* @ORM\Column(name="roles", type="array", length=255)
|
|
*/
|
|
private $roles = array();
|
|
|
|
/**
|
|
* @ORM\Column(name="salt", type="string", length=255)
|
|
*/
|
|
private $salt = '';
|
|
|
|
/**
|
|
* @ORM\Column(type="string", length=250, nullable=true)
|
|
*/
|
|
private $firstname;
|
|
|
|
/**
|
|
* @ORM\Column(type="string", length=250)
|
|
*/
|
|
private $lastname;
|
|
private $displayname;
|
|
|
|
/**
|
|
* @ORM\Column(type="string", length=60, nullable=true, options={"default" : 0})
|
|
*/
|
|
private $avatar;
|
|
|
|
/**
|
|
* @ORM\Column(type="string", length=250)
|
|
*/
|
|
private $email;
|
|
|
|
/**
|
|
* @ORM\Column(type="string", length=250, nullable=true)
|
|
*/
|
|
private $apikey;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="Service", inversedBy="users")
|
|
* @ORM\JoinColumn(nullable=true)
|
|
*/
|
|
private $service;
|
|
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="Event", mappedBy="user", cascade={"persist"}, orphanRemoval=false)
|
|
*/
|
|
private $events;
|
|
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="Penalty", mappedBy="user", cascade={"persist"}, orphanRemoval=false)
|
|
*/
|
|
private $penaltys;
|
|
|
|
/**
|
|
* @ORM\ManyToMany(targetEntity="Job", inversedBy="users", cascade={"persist"})
|
|
* @ORM\JoinTable(name="userjob",
|
|
* joinColumns={@ORM\JoinColumn(name="user", referencedColumnName="id")},
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="job", referencedColumnName="id")}
|
|
* )
|
|
*/
|
|
protected $jobs;
|
|
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="Userproject", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
|
|
*/
|
|
private $userprojects;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->services = new ArrayCollection();
|
|
$this->events = new ArrayCollection();
|
|
$this->penaltys = new ArrayCollection();
|
|
$this->jobs = new ArrayCollection();
|
|
$this->userprojects = new ArrayCollection();
|
|
}
|
|
|
|
public function getUsername(): ?string
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
public function getSalt(): ?string
|
|
{
|
|
return $this->salt;
|
|
}
|
|
|
|
public function setPassword($password): self
|
|
{
|
|
if($password!=$this->password&&$password!=""&&!is_null($password)){
|
|
$this->salt = uniqid(mt_rand(), true);
|
|
$hash = "{SSHA}" . base64_encode(pack("H*", sha1($password . $this->salt)) . $this->salt);
|
|
|
|
$this->password = $hash;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPassword(): ?string
|
|
{
|
|
return $this->password;
|
|
}
|
|
|
|
public function getRoles(): ?array
|
|
{
|
|
return $this->roles;
|
|
}
|
|
|
|
public function eraseCredentials()
|
|
{
|
|
}
|
|
|
|
public function serialize()
|
|
{
|
|
return serialize(array(
|
|
$this->id,
|
|
$this->username,
|
|
$this->password,
|
|
$this->salt,
|
|
));
|
|
}
|
|
|
|
public function unserialize($serialized)
|
|
{
|
|
list (
|
|
$this->id,
|
|
$this->username,
|
|
$this->password,
|
|
$this->salt
|
|
) = unserialize($serialized, array('allowed_classes' => false));
|
|
}
|
|
|
|
public function getDisplayname()
|
|
{
|
|
return $this->firstname." ".$this->lastname;
|
|
}
|
|
|
|
public function setId(int $id): self
|
|
{
|
|
$this->id = $id;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function setUsername(string $username): self
|
|
{
|
|
$this->username = $username;
|
|
|
|
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 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 getAvatar(): ?string
|
|
{
|
|
if($this->avatar)
|
|
return $this->avatar;
|
|
else
|
|
return "noavatar.png";
|
|
}
|
|
|
|
public function setAvatar(?string $avatar): self
|
|
{
|
|
$this->avatar = $avatar;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getEmail(): ?string
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function setEmail(string $email): self
|
|
{
|
|
$this->email = $email;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getService(): ?Service
|
|
{
|
|
return $this->service;
|
|
}
|
|
|
|
public function setService(?Service $service): self
|
|
{
|
|
$this->service = $service;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|Event[]
|
|
*/
|
|
public function getEvents(): Collection
|
|
{
|
|
return $this->events;
|
|
}
|
|
|
|
public function addEvent(Event $event): self
|
|
{
|
|
if (!$this->events->contains($event)) {
|
|
$this->events[] = $event;
|
|
$event->setUser($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeEvent(Event $event): self
|
|
{
|
|
if ($this->events->contains($event)) {
|
|
$this->events->removeElement($event);
|
|
// set the owning side to null (unless already changed)
|
|
if ($event->getUser() === $this) {
|
|
$event->setUser(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|Penalty[]
|
|
*/
|
|
public function getPenaltys(): Collection
|
|
{
|
|
return $this->penaltys;
|
|
}
|
|
|
|
public function addPenalty(Penalty $penalty): self
|
|
{
|
|
if (!$this->penaltys->contains($penalty)) {
|
|
$this->penaltys[] = $penalty;
|
|
$penalty->setUser($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removePenalty(Penalty $penalty): self
|
|
{
|
|
if ($this->penaltys->contains($penalty)) {
|
|
$this->penaltys->removeElement($penalty);
|
|
// set the owning side to null (unless already changed)
|
|
if ($penalty->getUser() === $this) {
|
|
$penalty->setUser(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getApikey(): ?string
|
|
{
|
|
return $this->apikey;
|
|
}
|
|
|
|
public function setApikey(?string $apikey): self
|
|
{
|
|
$this->apikey = $apikey;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|Job[]
|
|
*/
|
|
public function getJobs(): Collection
|
|
{
|
|
return $this->jobs;
|
|
}
|
|
|
|
public function addJob(Job $job): self
|
|
{
|
|
if (!$this->jobs->contains($job)) {
|
|
$this->jobs[] = $job;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeJob(Job $job): self
|
|
{
|
|
if ($this->jobs->contains($job)) {
|
|
$this->jobs->removeElement($job);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|Userproject[]
|
|
*/
|
|
public function getUserprojects(): Collection
|
|
{
|
|
return $this->userprojects;
|
|
}
|
|
|
|
public function addUserproject(Userproject $userproject): self
|
|
{
|
|
if (!$this->userprojects->contains($userproject)) {
|
|
$this->userprojects[] = $userproject;
|
|
$userproject->setUser($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeUserproject(Userproject $userproject): self
|
|
{
|
|
if ($this->userprojects->contains($userproject)) {
|
|
$this->userprojects->removeElement($userproject);
|
|
// set the owning side to null (unless already changed)
|
|
if ($userproject->getUser() === $this) {
|
|
$userproject->setUser(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
|
|
}
|