src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10.  * @ORM\Entity(repositoryClass=UserRepository::class)
  11.  * @ORM\Table(name="user")
  12.  * @ORM\HasLifecycleCallbacks
  13.  */
  14. class User implements UserInterface PasswordAuthenticatedUserInterface
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, nullable=false)
  24.      */
  25.     private $email;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      */
  29.     private $name;
  30.     /**
  31.      * @var string The hashed password
  32.      * @ORM\Column(type="string", length=5000)
  33.      */
  34.     private $password;
  35.     /**
  36.      *
  37.      * @ORM\Column(type="text", nullable=true )
  38.      *
  39.      */
  40.     private $avatar;
  41.     /**
  42.      * @var \DateTime $createdAt
  43.      *
  44.      *
  45.      * @ORM\Column(type="datetime", nullable=true )
  46.      */
  47.     protected $createdAt;
  48.     /**
  49.      * @var \DateTime $createdAt
  50.      *
  51.      *
  52.      * @ORM\Column(type="datetime", nullable=true )
  53.      */
  54.     protected $updateAt;
  55.     /**
  56.      * @var boolean
  57.      *
  58.      * @ORM\Column( type="boolean" , options={"default":"1"})
  59.      */
  60.     private $active 1;
  61.     /**
  62.      * @ORM\ManyToMany(targetEntity="Role", inversedBy="user")
  63.      * @ORM\JoinTable(
  64.      *     name="user_role",
  65.      *     joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
  66.      *     inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
  67.      * )
  68.      */
  69.     protected $roles;
  70.     /**
  71.      * @ORM\OneToMany(targetEntity="Supplier", mappedBy="user")
  72.      */
  73.     protected $supplier;
  74.     /**
  75.      * @ORM\OneToMany(targetEntity="EventLog", mappedBy="user")
  76.      */
  77.     protected $eventLog;
  78.     /**
  79.      * @ORM\OneToMany(targetEntity="Documentation", mappedBy="user")
  80.      */
  81.     protected $documentation;
  82.     /**
  83.      * @ORM\ManyToOne(targetEntity="Plant", inversedBy="user")
  84.      * @ORM\JoinColumn(name="plant_id", referencedColumnName="id" )
  85.      */
  86.     protected $plant;
  87.     /**
  88.      * @ORM\ManyToOne(targetEntity="Position", inversedBy="user")
  89.      * @ORM\JoinColumn(name="position_id", referencedColumnName="id" )
  90.      */
  91.     protected $position;
  92.     /**
  93.      * @ORM\OneToMany(targetEntity="Evaluation", mappedBy="user")
  94.      */
  95.     protected $evaluation;
  96.     /**
  97.      * @ORM\OneToMany(targetEntity="Tender", mappedBy="user")
  98.      */
  99.     protected $tender;
  100.     /**
  101.      * @ORM\OneToMany(targetEntity="DocumentType", mappedBy="qualityUser")
  102.      */
  103.     protected $documentType;
  104.     /**
  105.      * @ORM\OneToMany(targetEntity="EvaluationUser", mappedBy="qualityUser")
  106.      */
  107.     protected $evaluationUser;
  108.     /**
  109.      * @ORM\OneToMany(targetEntity="DescriptorType", mappedBy="qualityUser")
  110.      */
  111.     protected $descriptorType;
  112.     /**
  113.      * @ORM\OneToMany(targetEntity="SupplierData", mappedBy="user")
  114.      */
  115.     protected $supplierData;
  116.     /**
  117.      * @ORM\OneToMany(targetEntity="UserSupervisor", mappedBy="user")
  118.      */
  119.     private $supervisedUsers;
  120.     /**
  121.      * @ORM\OneToMany(targetEntity="UserSupervisor", mappedBy="supervisor")
  122.      */
  123.     private $supervisors;
  124.     /**
  125.      * Constructor
  126.      */
  127.     public function __construct()
  128.     {
  129.         $this->roles = new ArrayCollection();
  130.     }
  131.     public function getId(): ?int
  132.     {
  133.         return $this->id;
  134.     }
  135.     /**
  136.      * @return mixed
  137.      */
  138.     public function getEmail()
  139.     {
  140.         return $this->email;
  141.     }
  142.     /**
  143.      * @param mixed $email
  144.      */
  145.     public function setEmail($email): void
  146.     {
  147.         $this->email $email;
  148.     }
  149.     /**
  150.      * A visual identifier that represents this user.
  151.      *
  152.      * @see UserInterface
  153.      */
  154.     public function getUsername(): string
  155.     {
  156.         return (string)$this->email;
  157.     }
  158.     /**
  159.      * @see UserInterface
  160.      * @return \Doctrine\Common\Collections\Collection
  161.      */
  162.     public function getRolesArray(): array
  163.     {
  164.         // guarantee every user at least has ROLE_USER
  165.         $rolesArray = [];
  166.         foreach ($this->roles->toArray() as $role) {
  167.             $rolesArray[] = $role;
  168.         }
  169.         return array_unique($rolesArray);
  170.     }
  171.     /**
  172.      * @see UserInterface
  173.      * @return \Doctrine\Common\Collections\Collection
  174.      */
  175.     public function getRoles(): array
  176.     {
  177.         // guarantee every user at least has ROLE_USER
  178.         $rolesArray = [];
  179.         foreach ($this->roles->toArray() as $role) {
  180.             $rolesArray[] = $role->getName();
  181.         }
  182.         return array_unique($rolesArray);
  183.     }
  184.     /**
  185.      * @see UserInterface
  186.      * @return \Doctrine\Common\Collections\Collection
  187.      */
  188.     public function getRolesId(): array
  189.     {
  190.         // guarantee every user at least has ROLE_USER
  191.         $rolesArray = [];
  192.         foreach ($this->roles->toArray() as $role) {
  193.             $rolesArray[] = $role->getId();
  194.         }
  195.         return array_unique($rolesArray);
  196.     }
  197.     /**
  198.      * @see UserInterface
  199.      * @return \Doctrine\Common\Collections\Collection
  200.      */
  201.     public function getRolesString(): array
  202.     {
  203.         // guarantee every user at least has ROLE_USER
  204.         $rolesArray = [];
  205.         foreach ($this->roles->toArray() as $role) {
  206.             $rolesArray[] = $role->getTextName();
  207.         }
  208.         return array_unique($rolesArray);
  209.     }
  210.     /**
  211.      * @see UserInterface
  212.      * @return \Doctrine\Common\Collections\Collection
  213.      */
  214.     public function getRolesIcon(): array
  215.     {
  216.         $rolesArray = [];
  217.         foreach ($this->roles  as $key => $role) {
  218.             $rolesArray[$key]['name'] = $role->getTextName();
  219.             $rolesArray[$key]['icon'] = $role->getIcon();
  220.         }
  221.         return  $rolesArray ;
  222.     }
  223.     /**
  224.      * Add roles
  225.      *
  226.      * @param Role $roles
  227.      *
  228.      */
  229.     public function addRole(Role $roles)
  230.     {
  231.         $this->roles[] = $roles;
  232.         return $this;
  233.     }
  234.     /**
  235.      * @param Role $roles
  236.      */
  237.     public function removeRole(Role $roles)
  238.     {
  239.         $this->roles->removeElement($roles);
  240.     }
  241.     public function getPassword(): string
  242.     {
  243.         return $this->password;
  244.     }
  245.     public function setPassword(string $password): void
  246.     {
  247.         $this->password $password;
  248.     }
  249.     /**
  250.      * Returning a salt is only needed, if you are not using a modern
  251.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  252.      *
  253.      * @see UserInterface
  254.      */
  255.     public function getSalt(): ?string
  256.     {
  257.         return null;
  258.     }
  259.     /**
  260.      * @see UserInterface
  261.      */
  262.     public function eraseCredentials()
  263.     {
  264.         // If you store any temporary, sensitive data on the user, clear it here
  265.         // $this->plainPassword = null;
  266.     }
  267.     /**
  268.      * Get isAdmin
  269.      *
  270.      * @return boolean
  271.      */
  272.     public function getIsSuperAdmin()
  273.     {
  274.         foreach ($this->roles->toArray() as $role) {
  275.             if ($role->getName() == 'ROLE_SUPER_ADMIN') {
  276.                 return true;
  277.             }
  278.         }
  279.         return false;
  280.     }
  281.     /**
  282.      * @return mixed
  283.      */
  284.     public function getAvatar()
  285.     {
  286.         return   $this->avatar;
  287.     }
  288.     /**
  289.      * @param mixed $avatar
  290.      */
  291.     public function setAvatar($avatar): void
  292.     {
  293.         $this->avatar $avatar;
  294.     }
  295.     /**
  296.      * @param \DateTime $createdAt
  297.      *
  298.      * @ORM\PrePersist
  299.      */
  300.     public function setCreatedAt()
  301.     {
  302.         $this->createdAt = new \DateTime(date('Y-m-d H:i:s'));
  303.     }
  304.     /**
  305.      * @return \DateTime
  306.      */
  307.     public function getCreatedAt()
  308.     {
  309.         return $this->createdAt;
  310.     }
  311.     /**
  312.      * @param \DateTime $updateAt
  313.      *
  314.      * @ORM\PreUpdate
  315.      */
  316.     public function setUpdateAt()
  317.     {
  318.         $this->updateAt = new \DateTime(date('Y-m-d H:i:s'));
  319.     }
  320.     /**
  321.      * @return \DateTime
  322.      */
  323.     public function getUpdateAt()
  324.     {
  325.         return $this->updateAt;
  326.     }
  327.     /**
  328.      * @return bool
  329.      */
  330.     public function isActive(): bool
  331.     {
  332.         return $this->active;
  333.     }
  334.     /**
  335.      * @param bool $active
  336.      */
  337.     public function setActive(bool $active): void
  338.     {
  339.         $this->active $active;
  340.     }
  341.     /**
  342.      * @return mixed
  343.      */
  344.     public function getName()
  345.     {
  346.         return $this->name;
  347.     }
  348.     /**
  349.      * @param mixed $name
  350.      */
  351.     public function setName($name): void
  352.     {
  353.         $this->name $name;
  354.     }
  355.     public function __toString() {
  356.         return $this->name;
  357.     }
  358.     /**
  359.      */
  360.     public function getUserIdentifier(): string
  361.     {
  362.         return $this->id;
  363.     }
  364.     /**
  365.      * @return mixed
  366.      */
  367.     public function getSupplier()
  368.     {
  369.         return $this->supplier;
  370.     }
  371.     /**
  372.      * @param mixed $supplier
  373.      */
  374.     public function setSupplier($supplier): void
  375.     {
  376.         $this->supplier $supplier;
  377.     }
  378.     /**
  379.      * @return mixed
  380.      */
  381.     public function getEventLog()
  382.     {
  383.         return $this->eventLog;
  384.     }
  385.     /**
  386.      * @param mixed $eventLog
  387.      */
  388.     public function setEventLog($eventLog): void
  389.     {
  390.         $this->eventLog $eventLog;
  391.     }
  392.     /**
  393.      * @return mixed
  394.      */
  395.     public function getDocumentation()
  396.     {
  397.         return $this->documentation;
  398.     }
  399.     /**
  400.      * @param mixed $documentation
  401.      */
  402.     public function setDocumentation($documentation): void
  403.     {
  404.         $this->documentation $documentation;
  405.     }
  406.     /**
  407.      * @return mixed
  408.      */
  409.     public function getPlant()
  410.     {
  411.         return $this->plant;
  412.     }
  413.     /**
  414.      * @param mixed $plant
  415.      */
  416.     public function setPlant($plant): void
  417.     {
  418.         $this->plant $plant;
  419.     }
  420.     /**
  421.      * @return mixed
  422.      */
  423.     public function getPosition()
  424.     {
  425.         return $this->position;
  426.     }
  427.     /**
  428.      * @param mixed $position
  429.      */
  430.     public function setPosition($position): void
  431.     {
  432.         $this->position $position;
  433.     }
  434.     /**
  435.      * @return mixed
  436.      */
  437.     public function getEvaluation()
  438.     {
  439.         return $this->evaluation;
  440.     }
  441.     /**
  442.      * @param mixed $evaluation
  443.      */
  444.     public function setEvaluation($evaluation): void
  445.     {
  446.         $this->evaluation $evaluation;
  447.     }
  448.     /**
  449.      * @return mixed
  450.      */
  451.     public function getTender()
  452.     {
  453.         return $this->tender;
  454.     }
  455.     /**
  456.      * @param mixed $tender
  457.      */
  458.     public function setTender($tender): void
  459.     {
  460.         $this->tender $tender;
  461.     }
  462.     /**
  463.      * @return mixed
  464.      */
  465.     public function getDocumentType()
  466.     {
  467.         return $this->documentType;
  468.     }
  469.     /**
  470.      * @param mixed $documentType
  471.      */
  472.     public function setDocumentType($documentType): void
  473.     {
  474.         $this->documentType $documentType;
  475.     }
  476.     /**
  477.      * @return mixed
  478.      */
  479.     public function getDescriptorType()
  480.     {
  481.         return $this->descriptorType;
  482.     }
  483.     /**
  484.      * @param mixed $descriptorType
  485.      */
  486.     public function setDescriptorType($descriptorType): void
  487.     {
  488.         $this->descriptorType $descriptorType;
  489.     }
  490.     /**
  491.      * @return mixed
  492.      */
  493.     public function getSupplierData()
  494.     {
  495.         return $this->supplierData;
  496.     }
  497.     /**
  498.      * @param mixed $supplierData
  499.      */
  500.     public function setSupplierData($supplierData): void
  501.     {
  502.         $this->supplierData $supplierData;
  503.     }
  504. }