<?php
/**
* Created by PhpStorm.
* User: sbrun
* Date: 2018-03-16
* Time: 11:09
*/
namespace App\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Imprimante;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use App\Entity\ClientsContacts;
/**
* @ORM\Entity
* @ORM\Table(name="laralivre_sys_users")
* @ORM\Entity(repositoryClass="App\Repository\SysUsersRepository")
* @UniqueEntity("email")
* @UniqueEntity(
* fields={"codeCaissier"},
* errorPath="codeCaissier",
* message="Ce code caissier existe déjà"
* )
*/
class SysUsers extends BaseUser
{
const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
const ROLE_GERANT = 'ROLE_GERANT';
const ROLE_LIBRAIRE = 'ROLE_LIBRAIRE';
const ROLE_CLIENT = 'ROLE_CLIENT';
const ROLE_RETOUR = 'ROLE_RETOUR';
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="user_name", type="string", length=75)
*/
protected $name;
/**
* @ORM\Column(name="user_lastname", type="string", length=75)
*/
protected $lastname;
/**
* @ORM\Column(name="code_caissier", type="string", length=50, unique=true, nullable=true)
*/
protected $codeCaissier;
/**
* @ORM\Column(name="ip_external", type="boolean")
*/
protected $externalIp;
/**
* Many SysUser has one Company
*
* @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="sysUsers")
* @ORM\JoinColumn(nullable=true)
*/
protected $company;
/**
* Many Users have Many ClientsType.
* @ORM\ManyToMany(targetEntity="ClientsType", inversedBy="users")
* @ORM\JoinTable(name="users_clients_type")
*/
protected $clientsTypes;
/**
* One User has Many Imprimantes.
* @ORM\OneToMany(targetEntity="ImprimantesUsers", mappedBy="user")
*/
protected $imprimantesUsers;
/**
* One User has Many history.
* @ORM\OneToMany(targetEntity="History", mappedBy="user")
*/
protected $history;
/**
* One User has Many mailHistory.
* @ORM\OneToMany(targetEntity="Mail", mappedBy="userSender")
*/
protected $mailHistory;
/**
* One User has One clientContact.
* @ORM\OneToOne(targetEntity="ClientsContacts", mappedBy="user")
*/
protected $clientsContacts;
/**
* SysUsers constructor.
*/
public function __construct()
{
parent::__construct();
$this->clientsTypes = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param $email
* @return SysUsers
*/
public function setEmail($email)
{
$email = is_null($email) ? '' : $email;
parent::setEmail($email);
$this->setUsername($email);
return $this;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return mixed
*/
public function getLastname()
{
return $this->lastname;
}
/**
* @param mixed $lastname
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
}
/**
* Set company
*
* @param \App\Entity\Company $company
* @return SysUsers
*/
public function setCompany(\App\Entity\Company $company)
{
$this->company = $company;
return $this;
}
/**
* Get Company
*
* @return \App\Entity\Company
*/
public function getCompany()
{
return $this->company;
}
/**
* @return mixed
*/
public function getFullName()
{
return $this->getName().' '.$this->getLastname();
}
/**
* @return mixed
*/
public function getCodeCaissier()
{
return $this->codeCaissier;
}
/**
* @param mixed $codeCaissier
*/
public function setCodeCaissier($codeCaissier)
{
$this->codeCaissier = $codeCaissier;
}
/**
* @return mixed
*/
public function getClientsTypes()
{
return $this->clientsTypes;
}
/**
* @param mixed $clientsTypes
*/
public function setClientsTypes($clientsTypes)
{
$this->clientsTypes = $clientsTypes;
}
/**
* @param ClientsType $type
*/
public function addClientsType(ClientsType $type)
{
$this->clientsTypes->add($type);
}
/**
* @return mixed
*/
public function getImprimantesUsers()
{
return $this->imprimantesUsers;
}
/**
* @param mixed $imprimantesUsers
*/
public function setImprimantesUsers($imprimantesUsers)
{
$this->imprimantesUsers = $imprimantesUsers;
}
/**
* @return mixed
*/
public function getMailHistory()
{
return $this->mailHistory;
}
/**
* @param mixed $mailHistory
*/
public function setMailHistory($mailHistory)
{
$this->mailHistory = $mailHistory;
}
/**
* @return mixed
*/
public function getClientsContacts()
{
return $this->clientsContacts;
}
/**
* @param mixed $clientsContacts
*/
public function setClientsContacts($clientsContacts)
{
$this->clientsContacts = $clientsContacts;
}
/**
* @return mixed
*/
public function getExternalIp()
{
return $this->externalIp;
}
/**
* @param mixed $externalIp
*/
public function setExternalIp($externalIp)
{
$this->externalIp = $externalIp;
}
/**
* @return mixed
*/
public function getHistory()
{
return $this->history;
}
/**
* @param mixed $history
*/
public function setHistory($history): void
{
$this->history = $history;
}
public function getRoles(): array
{
$roles = parent::getRoles();
$kDefault = array_keys($roles, 'ROLE_USER', true);
if (!empty($kDefault)) {
unset($roles[$kDefault[0]]);
}
return $roles; // TODO: Change the autogenerated stub
}
public function getFirstRoleInText()
{
$roles = $this->getRoles();
if (in_array(SysUsers::ROLE_SUPER_ADMIN, $roles)) {
return "Super administrateur";
}
if (in_array(SysUsers::ROLE_GERANT, $roles)) {
return "Gérant";
}
if (in_array(SysUsers::ROLE_LIBRAIRE, $roles)) {
return "Libraire";
}
if (in_array(SysUsers::ROLE_CLIENT, $roles)) {
return "Client";
}
if (in_array(SysUsers::ROLE_RETOUR, $roles)) {
return "Retour";
}
}
}