src/Entity/Kernel/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Kernel;
  3. use App\Repository\Kernel\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use App\Entity\Kernel\UserFunction;
  11. use App\Entity\HR\Employee;
  12. /**
  13.  * @ORM\Entity(repositoryClass=UserRepository::class)
  14.  */
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=255, unique=true)
  25.      */
  26.     private $uuid;
  27.     
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      */
  31.     private $email;
  32.     
  33.         /**
  34.      * @ORM\Column(type="string", length=255)
  35.      */
  36.     private $firstName;
  37.     
  38.             /**
  39.      * @ORM\Column(type="string", length=255)
  40.      */
  41.     private $lastName;
  42.     
  43.           /**
  44.     * @ORM\OneToOne(targetEntity=KernelFile::class, cascade={"remove"})
  45.     * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  46.     */    
  47.    private $picture;
  48.     
  49.     
  50.      /**
  51.      * @ORM\Column(type="string", length=55, nullable=true)
  52.      */
  53.     private $phone;
  54.     
  55.         /**
  56.      * 
  57.      * @ORM\Column(type="integer", nullable=true)
  58.      */
  59.     private $type//0 normal user, 1 azure user, 2 facebook user
  60.     
  61.     /**
  62.      * 
  63.      * @ORM\Column(type="datetime", nullable=true)
  64.      */
  65.     private $lastLogin;
  66.     
  67.     /**
  68.      * 
  69.      * @ORM\Column(type="integer")
  70.      */
  71.     private $failedLoginAttempts;
  72.     
  73.     /**
  74.     * @ORM\Column(type="boolean")
  75.     */
  76.     private $enabled;
  77.     
  78.     /**
  79.     * @ORM\Column(type="boolean")
  80.     */
  81.     private $locked;
  82.     
  83.     /**
  84.      * @ORM\Column(type="json")
  85.      */
  86.     private $roles = [];
  87.     /**
  88.      * @var string The hashed password
  89.      * @ORM\Column(type="string")
  90.      */
  91.     private $password;
  92.     
  93.     /**
  94.      * @ORM\ManyToOne(targetEntity=UserFunction::class)
  95.      */
  96.     private $userfunction;
  97.     
  98.         /**
  99.      * @ORM\ManyToOne(targetEntity=ListItem::class)
  100.      */
  101.     private $timezone;
  102.     
  103.     /**
  104.      * @ORM\ManyToOne(targetEntity=ListItem::class)
  105.      */
  106.     private $locale;
  107.     
  108.     /**
  109.      * @ORM\OneToOne(targetEntity=Employee::class, inversedBy="user")
  110.      */
  111.     private $employee;
  112.     
  113.         /**
  114.      * @ORM\ManyToMany(targetEntity=App\Entity\Kernel\Contact::class, mappedBy="users")
  115.      */
  116.     private $contacts;
  117.     
  118.     /**
  119.      * @ORM\Column(type="integer")
  120.      */
  121.     private $state;
  122.     
  123.         /**
  124.      * @var datetime $created
  125.      *
  126.      * @Gedmo\Timestampable(on="create")
  127.      * @ORM\Column(type="datetime")
  128.      */
  129.     private $created;
  130.     
  131.     /**
  132.      * @ORM\ManyToOne(targetEntity=Organization::class)
  133.      */
  134.     private $organization;
  135.     /**
  136.      * @var string $createdBy
  137.      *
  138.      * @Gedmo\Blameable(on="create")
  139.      * @ORM\ManyToOne(targetEntity="App\Entity\Kernel\User")
  140.      * @ORM\JoinColumn(name="created_by", referencedColumnName="id")
  141.      */
  142.     private $createdBy;
  143.     /**
  144.      * @var datetime $updated
  145.      *
  146.      * @ORM\Column(type="datetime")
  147.      * @Gedmo\Timestampable(on="update")
  148.      */
  149.     private $updated;
  150.     /**
  151.      * @var string $updatedBy
  152.      *
  153.      * @Gedmo\Blameable(on="update")
  154.      * @ORM\ManyToOne(targetEntity="App\Entity\Kernel\User")
  155.      * @ORM\JoinColumn(name="updated_by", referencedColumnName="id")
  156.      */
  157.     private $updatedBy;
  158.     
  159.     public function getUserIdentifier():string
  160.     {
  161.         return $this->uuid;
  162.     }
  163.     public function __construct()
  164.     {
  165.         $this->users = new ArrayCollection();
  166.         $this->contacts = new ArrayCollection();
  167.     }
  168.     
  169.     public function getName()
  170.     {
  171.         return "".$this->firstName" " .$this->lastName;
  172.     }
  173.     
  174.     public function __toString()
  175.     {
  176.         return "".$this->email;
  177.     }
  178.     public function getId(): ?int
  179.     {
  180.         return $this->id;
  181.     }
  182.     public function getUuid(): ?string
  183.     {
  184.         return $this->uuid;
  185.     }
  186.     public function setUuid(string $uuid): self
  187.     {
  188.         $this->uuid $uuid;
  189.         return $this;
  190.     }
  191.     /**
  192.      * A visual identifier that represents this user.
  193.      *
  194.      * @see UserInterface
  195.      */
  196.     public function getUsername(): string
  197.     {
  198.         return (string) $this->email;
  199.     }
  200.     public function getRoles(): array
  201.     {
  202.         $roles $this->roles;
  203.         // guarantee every user at least has ROLE_USER
  204.         $roles[] = 'ROLE_USER';
  205.         return array_unique($roles);
  206.     }
  207.     /**
  208.      * @see UserInterface
  209.      */
  210.     public function getPassword(): string
  211.     {
  212.         return (string) $this->password;
  213.     }
  214.     public function setPassword(string $password): self
  215.     {
  216.         $this->password $password;
  217.         return $this;
  218.     }
  219.     /**
  220.      * @see UserInterface
  221.      */
  222.     public function getSalt()
  223.     {
  224.         // not needed when using the "bcrypt" algorithm in security.yaml
  225.     }
  226.     /**
  227.      * @see UserInterface
  228.      */
  229.     public function eraseCredentials()
  230.     {
  231.         // If you store any temporary, sensitive data on the user, clear it here
  232.         // $this->plainPassword = null;
  233.     }
  234.     public function getEmail(): ?string
  235.     {
  236.         return $this->email;
  237.     }
  238.     public function setEmail(string $email): self
  239.     {
  240.         $this->email $email;
  241.         return $this;
  242.     }
  243.     public function getLastName(): ?string
  244.     {
  245.         return $this->lastName;
  246.     }
  247.     public function setLastName(string $lastName): self
  248.     {
  249.         $this->lastName $lastName;
  250.         return $this;
  251.     }
  252.     public function getFirstName(): ?string
  253.     {
  254.         return $this->firstName;
  255.     }
  256.     public function setFirstName(string $firstName): self
  257.     {
  258.         $this->firstName $firstName;
  259.         return $this;
  260.     }
  261.     public function getPhone(): ?string
  262.     {
  263.         return $this->phone;
  264.     }
  265.     public function setPhone(?string $phone): self
  266.     {
  267.         $this->phone $phone;
  268.         return $this;
  269.     }
  270.     public function getLastLogin(): ?\DateTimeInterface
  271.     {
  272.         return $this->lastLogin;
  273.     }
  274.     public function setLastLogin(?\DateTimeInterface $lastLogin): self
  275.     {
  276.         $this->lastLogin $lastLogin;
  277.         return $this;
  278.     }
  279.     public function getFailedLoginAttempts(): ?int
  280.     {
  281.         return $this->failedLoginAttempts;
  282.     }
  283.     public function setFailedLoginAttempts(int $failedLoginAttempts): self
  284.     {
  285.         $this->failedLoginAttempts $failedLoginAttempts;
  286.         return $this;
  287.     }
  288.     public function getEnabled(): ?bool
  289.     {
  290.         return $this->enabled;
  291.     }
  292.     public function setEnabled(bool $enabled): self
  293.     {
  294.         $this->enabled $enabled;
  295.         return $this;
  296.     }
  297.     public function getLocked(): ?bool
  298.     {
  299.         return $this->locked;
  300.     }
  301.     public function setLocked(bool $locked): self
  302.     {
  303.         $this->locked $locked;
  304.         return $this;
  305.     }
  306.     public function setRoles(array $roles): self
  307.     {
  308.         $this->roles $roles;
  309.         return $this;
  310.     }
  311.     public function getState(): ?int
  312.     {
  313.         return $this->state;
  314.     }
  315.     public function setState(int $state): self
  316.     {
  317.         $this->state $state;
  318.         return $this;
  319.     }
  320.     public function getCreated(): ?\DateTimeInterface
  321.     {
  322.         return $this->created;
  323.     }
  324.     public function setCreated(\DateTimeInterface $created): self
  325.     {
  326.         $this->created $created;
  327.         return $this;
  328.     }
  329.     public function getUpdated(): ?\DateTimeInterface
  330.     {
  331.         return $this->updated;
  332.     }
  333.     public function setUpdated(\DateTimeInterface $updated): self
  334.     {
  335.         $this->updated $updated;
  336.         return $this;
  337.     }
  338.     public function getCreatedBy(): ?self
  339.     {
  340.         return $this->createdBy;
  341.     }
  342.     public function setCreatedBy(?self $createdBy): self
  343.     {
  344.         $this->createdBy $createdBy;
  345.         return $this;
  346.     }
  347.     public function getUpdatedBy(): ?self
  348.     {
  349.         return $this->updatedBy;
  350.     }
  351.     public function setUpdatedBy(?self $updatedBy): self
  352.     {
  353.         $this->updatedBy $updatedBy;
  354.         return $this;
  355.     }
  356.     public function getUserfunction(): ?UserFunction
  357.     {
  358.         return $this->userfunction;
  359.     }
  360.     public function setUserfunction(?UserFunction $userfunction): self
  361.     {
  362.         $this->userfunction $userfunction;
  363.         return $this;
  364.     }
  365.     public function getOrganization(): ?Organization
  366.     {
  367.         return $this->organization;
  368.     }
  369.     public function setOrganization(?Organization $organization): self
  370.     {
  371.         $this->organization $organization;
  372.         return $this;
  373.     }
  374.     public function getTimezone(): ?ListItem
  375.     {
  376.         return $this->timezone;
  377.     }
  378.     public function setTimezone(?ListItem $timezone): self
  379.     {
  380.         $this->timezone $timezone;
  381.         return $this;
  382.     }
  383.     public function getLocale(): ?ListItem
  384.     {
  385.         return $this->locale;
  386.     }
  387.     public function setLocale(?ListItem $locale): self
  388.     {
  389.         $this->locale $locale;
  390.         return $this;
  391.     }
  392.     public function getPicture(): ?KernelFile
  393.     {
  394.         return $this->picture;
  395.     }
  396.     public function setPicture(?KernelFile $picture): self
  397.     {
  398.         $this->picture $picture;
  399.         return $this;
  400.     }
  401.     public function getType(): ?int
  402.     {
  403.         return $this->type;
  404.     }
  405.     public function setType(?int $type): self
  406.     {
  407.         $this->type $type;
  408.         return $this;
  409.     }
  410.     public function getEmployee(): ?Employee
  411.     {
  412.         return $this->employee;
  413.     }
  414.     public function setEmployee(?Employee $employee): self
  415.     {
  416.         $this->employee $employee;
  417.         return $this;
  418.     }
  419.     /**
  420.      * @return Collection|Contact[]
  421.      */
  422.     public function getContacts(): Collection
  423.     {
  424.         return $this->contacts;
  425.     }
  426.     public function addContact(Contact $contact): self
  427.     {
  428.         if (!$this->contacts->contains($contact)) {
  429.             $this->contacts[] = $contact;
  430.             $contact->addUser($this);
  431.         }
  432.         return $this;
  433.     }
  434.     public function removeContact(Contact $contact): self
  435.     {
  436.         if ($this->contacts->removeElement($contact)) {
  437.             $contact->removeUser($this);
  438.         }
  439.         return $this;
  440.     }
  441.     
  442. }