src/Entity/Employee.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\EmployeeRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use JMS\Serializer\Annotation as Serializer;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Tionvel\ImporterBundle\Validator as TionvelAssert;
  9. /**
  10.  * @Serializer\ExclusionPolicy("ALL")
  11.  */
  12. #[UniqueEntity(fields"username",message"Ya existe un usuario o proveedor con este nombre")]
  13. #[UniqueEntity(fields"rut",message"Ya existe un usuario o proveedor con este RUT")]
  14. #[UniqueEntity(fields"email",message"Ya existe un usuario o proveedor con este email")]
  15. #[ORM\Entity(repositoryClassEmployeeRepository::class)]
  16. #[ORM\Table(name'`employee`')]
  17. class Employee
  18. {
  19.     /**
  20.      * @Serializer\Expose()
  21.      */
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue(strategy:"AUTO")]
  24.     #[ORM\Column(type"integer")]
  25.     protected ?int $id null;
  26.     #[ORM\OneToOne(mappedBy"employee"targetEntity"User"cascade: ['persist''remove'], fetch"EAGER")]
  27.     #[ORM\JoinColumn(name"user_id"referencedColumnName"id"onDelete"CASCADE")]
  28.     protected $user;
  29.     /**
  30.      * @Serializer\Expose()
  31.      */
  32.     #[Assert\NotBlank(message'El Nombre no puede estar en blanco')]
  33.     #[ORM\Column(type"string")]
  34.     protected $name;
  35.     /**
  36.      * @Serializer\Expose()
  37.      */
  38.     #[Assert\NotBlank(message'El Apellido no puede estar en blanco')]
  39.     #[ORM\Column(type"string")]
  40.     protected $lastName;
  41.     /**
  42.      * @Serializer\Expose()
  43.      */
  44.     #[ORM\Column(type"string"nullabletrue)]
  45.     protected $secondLastName;
  46.     /**
  47.      * @Serializer\Expose()
  48.      */
  49.     #[TionvelAssert\Rut]
  50.     #[Assert\NotBlank(message'El Rut no puede estar en blanco')]
  51.     #[ORM\Column(type"string"length100uniquetrue )]
  52.     protected $rut;
  53.     #[Assert\NotBlank(message'La sucursal no puede estar en blanco')]
  54.     #[ORM\ManyToOne(targetEntity:"Office"inversedBy:"employees")]
  55.     #[ORM\JoinColumn(name"office_id"referencedColumnName"id"nullabletrueonDelete"SET NULL")]
  56.     protected $office;
  57.     /**
  58.      * @Serializer\Expose()
  59.      */
  60.     #[Assert\Length(max32,maxMessage'Este campo no puede exceder los {{ limit }} caaracteres.')]
  61.     #[ORM\Column(type"string"nullabletrue)]
  62.     protected $phone;
  63.     #[Assert\Email(message'Ingresa un email vĂ¡lido.')]
  64.     #[Assert\NotBlank(message'El email no puede estar en blanco.')]
  65.     #[ORM\Column(type"string"uniquetrue)]
  66.     protected $email;
  67.     #[Assert\NotBlank(message'El nombre de usuario no puede estar en blanco.')]
  68.     #[ORM\Column(type"string"uniquetrue)]
  69.     protected $username;
  70.     #[ORM\Column(type"string"nullabletrue)]
  71.     protected $position;
  72.     #[ORM\Column(type"boolean")]
  73.     protected $isAdmin false;
  74.     #[ORM\Column(type"boolean")]
  75.     protected $isFinances false;
  76.     #[ORM\Column(type"boolean")]
  77.     protected $isAcquisitions false;
  78.     #[ORM\Column(type"boolean")]
  79.     protected $isAcquisitionManager false;
  80.     #[ORM\Column(type"boolean")]
  81.     protected $isViewer false;
  82.     #[ORM\Column(type"boolean")]
  83.     protected $isRequester false;
  84.     #[ORM\Column(type"boolean")]
  85.     protected $isLegal false;
  86.     #[ORM\Column(type"boolean")]
  87.     protected $isCompras false;
  88.     #[ORM\Column(type"boolean")]
  89.     protected $isContractsViewer false;
  90.     public function getId()
  91.     {
  92.         return $this->id;
  93.     }
  94.     public function setName($name)
  95.     {
  96.         $this->name $name;
  97.     }
  98.     public function getName()
  99.     {
  100.         return $this->name;
  101.     }
  102.     public function setLastName($lastName)
  103.     {
  104.         $this->lastName $lastName;
  105.     }
  106.     public function getLastName()
  107.     {
  108.         return $this->lastName;
  109.     }
  110.     public function setSecondLastName($secondLastName)
  111.     {
  112.         $this->secondLastName $secondLastName;
  113.     }
  114.     public function getSecondLastName()
  115.     {
  116.         return $this->secondLastName;
  117.     }
  118.     public function setRut($rut)
  119.     {
  120.         $this->rut $rut;
  121.     }
  122.     public function getRut()
  123.     {
  124.         return $this->rut;
  125.     }
  126.     public function setPhone($phone)
  127.     {
  128.         $this->phone $phone;
  129.     }
  130.     public function getPhone()
  131.     {
  132.         return $this->phone;
  133.     }
  134.     public function getUser()
  135.     {
  136.         return $this->user;
  137.     }
  138.     public function getFullName()
  139.     {
  140.         return mb_convert_case(sprintf('%s %s %s'$this->name$this->lastName$this->secondLastName), MB_CASE_TITLE);
  141.     }
  142.     public function __toString()
  143.     {
  144.         return sprintf('%s %s'$this->rut$this->getFullName());
  145.     }
  146.     public function setUser(User $user null)
  147.     {
  148.         $this->user $user;
  149.     }
  150.     public function setOffice(Office $office null)
  151.     {
  152.         if ($this->office === $office) {
  153.             return;
  154.         }
  155.         $this->office $office;
  156.         if (! is_null($office)) {
  157.             $office->addEmployee($this);
  158.         }
  159.     }
  160.     public function getOffice()
  161.     {
  162.         return $this->office;
  163.     }
  164.     public function getPosition()
  165.     {
  166.         return $this->position;
  167.     }
  168.     public function setPosition($position)
  169.     {
  170.         $this->position $position;
  171.     }
  172.     public function getEmail()
  173.     {
  174.         return $this->email;
  175.     }
  176.     public function setEmail($email)
  177.     {
  178.         $this->email $email;
  179.     }
  180.     public function getUsername()
  181.     {
  182.         return $this->username;
  183.     }
  184.     public function setUsername($username)
  185.     {
  186.         $this->username $username;
  187.     }
  188.     public function isAdmin(): bool
  189.     {
  190.         return $this->isAdmin;
  191.     }
  192.     public function setIsAdmin(bool $isAdmin)
  193.     {
  194.         $this->isAdmin $isAdmin;
  195.     }
  196.     public function isFinances(): bool
  197.     {
  198.         return $this->isFinances;
  199.     }
  200.     public function setIsFinances(bool $isFinances)
  201.     {
  202.         $this->isFinances $isFinances;
  203.     }
  204.     public function isAcquisitions(): bool
  205.     {
  206.         return $this->isAcquisitions;
  207.     }
  208.     public function setIsAcquisitions(bool $isAcquisitions)
  209.     {
  210.         $this->isAcquisitions $isAcquisitions;
  211.     }
  212.     public function isAcquisitionManager(): bool
  213.     {
  214.         return $this->isAcquisitionManager;
  215.     }
  216.     public function setIsAcquisitionManager(bool $isAm)
  217.     {
  218.         $this->isAcquisitionManager $isAm;
  219.     }
  220.     public function isRequester(): bool
  221.     {
  222.         return $this->isRequester;
  223.     }
  224.     public function setIsRequester(bool $isRequester)
  225.     {
  226.         $this->isRequester $isRequester;
  227.     }
  228.     public function isViewer(): bool
  229.     {
  230.         return $this->isViewer;
  231.     }
  232.     public function setIsViewer(bool $isViewer)
  233.     {
  234.         $this->isViewer $isViewer;
  235.     }
  236.     /**
  237.      * @return bool
  238.      */
  239.     public function isLegal(): bool
  240.     {
  241.         return $this->isLegal;
  242.     }
  243.     /**
  244.      * @param bool $isLegal
  245.      */
  246.     public function setIsLegal(bool $isLegal)
  247.     {
  248.         $this->isLegal $isLegal;
  249.     }
  250.     public function isCompras(): bool
  251.     {
  252.         return $this->isCompras;
  253.     }
  254.     public function setIsCompras(bool $isCompras): void
  255.     {
  256.         $this->isCompras $isCompras;
  257.     }
  258.     public function isContractsViewer(): bool
  259.     {
  260.         return $this->isContractsViewer;
  261.     }
  262.     public function setIsContractsViewer(bool $isContractsViewer): void
  263.     {
  264.         $this->isContractsViewer $isContractsViewer;
  265.     }
  266. }