src/Entity/SysUsers.php line 28

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: sbrun
  5.  * Date: 2018-03-16
  6.  * Time: 11:09
  7.  */
  8. namespace App\Entity;
  9. use FOS\UserBundle\Model\User as BaseUser;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use App\Entity\Imprimante;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. use App\Entity\ClientsContacts;
  15. /**
  16.  * @ORM\Entity
  17.  * @ORM\Table(name="laralivre_sys_users")
  18.  * @ORM\Entity(repositoryClass="App\Repository\SysUsersRepository")
  19.  * @UniqueEntity("email")
  20.  * @UniqueEntity(
  21.  *     fields={"codeCaissier"},
  22.  *     errorPath="codeCaissier",
  23.  *     message="Ce code caissier existe déjà"
  24.  * )
  25.  */
  26. class SysUsers extends BaseUser
  27. {
  28.     const ROLE_SUPER_ADMIN 'ROLE_SUPER_ADMIN';
  29.     const ROLE_GERANT 'ROLE_GERANT';
  30.     const ROLE_LIBRAIRE 'ROLE_LIBRAIRE';
  31.     const ROLE_CLIENT 'ROLE_CLIENT';
  32.     const ROLE_RETOUR 'ROLE_RETOUR';
  33.     /**
  34.      * @ORM\Column(type="integer")
  35.      * @ORM\Id
  36.      * @ORM\GeneratedValue(strategy="AUTO")
  37.      */
  38.     protected $id;
  39.     /**
  40.      * @ORM\Column(name="user_name", type="string", length=75)
  41.      */
  42.     protected $name;
  43.     /**
  44.      * @ORM\Column(name="user_lastname", type="string", length=75)
  45.      */
  46.     protected $lastname;
  47.     /**
  48.      * @ORM\Column(name="code_caissier", type="string", length=50, unique=true, nullable=true)
  49.      */
  50.     protected $codeCaissier;
  51.     /**
  52.      * @ORM\Column(name="ip_external", type="boolean")
  53.      */
  54.     protected $externalIp;
  55.     /**
  56.      * Many SysUser has one Company
  57.      *
  58.      * @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="sysUsers")
  59.      * @ORM\JoinColumn(nullable=true)
  60.      */
  61.     protected $company;
  62.     /**
  63.      * Many Users have Many ClientsType.
  64.      * @ORM\ManyToMany(targetEntity="ClientsType", inversedBy="users")
  65.      * @ORM\JoinTable(name="users_clients_type")
  66.      */
  67.     protected $clientsTypes;
  68.     /**
  69.      * One User has Many Imprimantes.
  70.      * @ORM\OneToMany(targetEntity="ImprimantesUsers", mappedBy="user")
  71.      */
  72.     protected $imprimantesUsers;
  73.     /**
  74.      * One User has Many history.
  75.      * @ORM\OneToMany(targetEntity="History", mappedBy="user")
  76.      */
  77.     protected $history;
  78.     /**
  79.      * One User has Many mailHistory.
  80.      * @ORM\OneToMany(targetEntity="Mail", mappedBy="userSender")
  81.      */
  82.     protected $mailHistory;
  83.     /**
  84.      * One User has One clientContact.
  85.      * @ORM\OneToOne(targetEntity="ClientsContacts", mappedBy="user")
  86.      */
  87.     protected $clientsContacts;
  88.     /**
  89.      * SysUsers constructor.
  90.      */
  91.     public function __construct()
  92.     {
  93.         parent::__construct();
  94.         $this->clientsTypes = new \Doctrine\Common\Collections\ArrayCollection();
  95.     }
  96.     /**
  97.      * @return mixed
  98.      */
  99.     public function getId()
  100.     {
  101.         return $this->id;
  102.     }
  103.     /**
  104.      * @param $email
  105.      * @return SysUsers
  106.      */
  107.     public function setEmail($email)
  108.     {
  109.         $email is_null($email) ? '' $email;
  110.         parent::setEmail($email);
  111.         $this->setUsername($email);
  112.         return $this;
  113.     }
  114.     /**
  115.      * @return mixed
  116.      */
  117.     public function getName()
  118.     {
  119.         return $this->name;
  120.     }
  121.     /**
  122.      * @param mixed $name
  123.      */
  124.     public function setName($name)
  125.     {
  126.         $this->name $name;
  127.     }
  128.     /**
  129.      * @return mixed
  130.      */
  131.     public function getLastname()
  132.     {
  133.         return $this->lastname;
  134.     }
  135.     /**
  136.      * @param mixed $lastname
  137.      */
  138.     public function setLastname($lastname)
  139.     {
  140.         $this->lastname $lastname;
  141.     }
  142.     /**
  143.      * Set company
  144.      *
  145.      * @param \App\Entity\Company $company
  146.      * @return SysUsers
  147.      */
  148.     public function setCompany(\App\Entity\Company $company)
  149.     {
  150.         $this->company $company;
  151.         return $this;
  152.     }
  153.     /**
  154.      * Get Company
  155.      *
  156.      * @return \App\Entity\Company
  157.      */
  158.     public function getCompany()
  159.     {
  160.         return $this->company;
  161.     }
  162.     /**
  163.      * @return mixed
  164.      */
  165.     public function getFullName()
  166.     {
  167.         return $this->getName().' '.$this->getLastname();
  168.     }
  169.     /**
  170.      * @return mixed
  171.      */
  172.     public function getCodeCaissier()
  173.     {
  174.         return $this->codeCaissier;
  175.     }
  176.     /**
  177.      * @param mixed $codeCaissier
  178.      */
  179.     public function setCodeCaissier($codeCaissier)
  180.     {
  181.         $this->codeCaissier $codeCaissier;
  182.     }
  183.     /**
  184.      * @return mixed
  185.      */
  186.     public function getClientsTypes()
  187.     {
  188.         return $this->clientsTypes;
  189.     }
  190.     /**
  191.      * @param mixed $clientsTypes
  192.      */
  193.     public function setClientsTypes($clientsTypes)
  194.     {
  195.         $this->clientsTypes $clientsTypes;
  196.     }
  197.     /**
  198.      * @param ClientsType $type
  199.      */
  200.     public function addClientsType(ClientsType $type)
  201.     {
  202.         $this->clientsTypes->add($type);
  203.     }
  204.     /**
  205.      * @return mixed
  206.      */
  207.     public function getImprimantesUsers()
  208.     {
  209.         return $this->imprimantesUsers;
  210.     }
  211.     /**
  212.      * @param mixed $imprimantesUsers
  213.      */
  214.     public function setImprimantesUsers($imprimantesUsers)
  215.     {
  216.         $this->imprimantesUsers $imprimantesUsers;
  217.     }
  218.     /**
  219.      * @return mixed
  220.      */
  221.     public function getMailHistory()
  222.     {
  223.         return $this->mailHistory;
  224.     }
  225.     /**
  226.      * @param mixed $mailHistory
  227.      */
  228.     public function setMailHistory($mailHistory)
  229.     {
  230.         $this->mailHistory $mailHistory;
  231.     }
  232.     /**
  233.      * @return mixed
  234.      */
  235.     public function getClientsContacts()
  236.     {
  237.         return $this->clientsContacts;
  238.     }
  239.     /**
  240.      * @param mixed $clientsContacts
  241.      */
  242.     public function setClientsContacts($clientsContacts)
  243.     {
  244.         $this->clientsContacts $clientsContacts;
  245.     }
  246.     /**
  247.      * @return mixed
  248.      */
  249.     public function getExternalIp()
  250.     {
  251.         return $this->externalIp;
  252.     }
  253.     /**
  254.      * @param mixed $externalIp
  255.      */
  256.     public function setExternalIp($externalIp)
  257.     {
  258.         $this->externalIp $externalIp;
  259.     }
  260.     /**
  261.      * @return mixed
  262.      */
  263.     public function getHistory()
  264.     {
  265.         return $this->history;
  266.     }
  267.     /**
  268.      * @param mixed $history
  269.      */
  270.     public function setHistory($history): void
  271.     {
  272.         $this->history $history;
  273.     }
  274.     public function getRoles(): array
  275.     {
  276.         $roles parent::getRoles();
  277.         $kDefault array_keys($roles'ROLE_USER'true);
  278.         if (!empty($kDefault)) {
  279.             unset($roles[$kDefault[0]]);
  280.         }
  281.         return $roles// TODO: Change the autogenerated stub
  282.     }
  283.     public function getFirstRoleInText()
  284.     {
  285.         $roles $this->getRoles();
  286.         if (in_array(SysUsers::ROLE_SUPER_ADMIN$roles)) {
  287.             return "Super administrateur";
  288.         }
  289.         if (in_array(SysUsers::ROLE_GERANT$roles)) {
  290.             return "Gérant";
  291.         }
  292.         if (in_array(SysUsers::ROLE_LIBRAIRE$roles)) {
  293.             return "Libraire";
  294.         }
  295.         if (in_array(SysUsers::ROLE_CLIENT$roles)) {
  296.             return "Client";
  297.         }
  298.         if (in_array(SysUsers::ROLE_RETOUR$roles)) {
  299.             return "Retour";
  300.         }
  301.     }
  302. }