src/Entity/Master/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Master;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\Master\UserRepository")
  11.  * @ORM\HasLifecycleCallbacks()
  12.  * @ORM\Table(name="eaml_m_user")
  13.  */
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     
  17.     public function __toString()
  18.        {
  19.            return $this->name." ".$this->surname;
  20.        }
  21.     
  22.     public function getCanEditOffice($officeId){
  23.         foreach($this->offices as $jt){
  24.             if($jt->getOffice()->getId() == $officeId){
  25.                 $jtou $jt;
  26.                 break;
  27.             }
  28.         }
  29.         
  30.         if($this->getRole() == "ROLE_ADMIN"){
  31.             return true;
  32.         }
  33.         elseif($jtou->getUser()->getRole() == "ROLE_USER"){
  34.             if($this->isAdminActive && $jtou->getOffice() != null && $jtou->getOffice()->getIsActive())
  35.                 return true;
  36.         }
  37.         elseif($this->getRole() == "ROLE_RESELLER"){
  38.             if($this->isAdminActive && $this->reseller != null && $this->reseller->getIsAdminActive() && $jtou->getOffice()->getIsActive() && $jtou->getOffice()->getAllowResellerAccess())
  39.                 return true;
  40.         }
  41.         return false;
  42.     }
  43.     
  44.     public function getCanConfigureOffice($officeId){
  45.         foreach($this->offices as $jt){
  46.             if($jt->getOffice()->getId() == $officeId){
  47.                 $jtou $jt;
  48.                 break;
  49.             }
  50.         }
  51.         if($this->getRole() == "ROLE_ADMIN"){
  52.             return true;
  53.         }
  54.         elseif($jtou->getRole()->getSlug() == "responsible"){
  55.             if($this->isAdminActive && $jtou->getOffice() != null && $jtou->getOffice()->getIsActive())
  56.                 return true;
  57.         }
  58.         elseif($jtou->getRole()->getSlug() == "on_charge" || $jtou->getRole()->getSlug() == "delegate"){
  59.             if($this->isAdminActive && $jtou->getOffice() != null && $jtou->getOffice()->getIsActive() && $jtou->getOffice()->getIsConfigurationCompleted())
  60.                 return true;
  61.         }
  62.         elseif($this->getRole() == "ROLE_RESELLER"){
  63.             if($this->isAdminActive && $this->reseller != null && $this->reseller->getIsAdminActive() && $jtou->getOffice() != null && $jtou->getOffice()->getIsActive() && $jtou->getOffice()->getAllowResellerAccess())
  64.                 return true;
  65.         }
  66.         return false;
  67.     }
  68.     public function getJtRole($officeId){
  69.         foreach($this->offices as $jt){
  70.             if($jt->getOffice()->getId() == $officeId){
  71.                 $jtou $jt;
  72.                 break;
  73.             }
  74.         }
  75.         return $jtou->getRole()->getValue();
  76.     }
  77.     
  78.     /**
  79.      * @ORM\Column(name="id", type="bigint")
  80.      * @ORM\Id
  81.      * @ORM\GeneratedValue(strategy="AUTO")
  82.      */
  83.     protected $id;
  84.     /**
  85.      * @ORM\Column(name="position", type="string", nullable=true)
  86.      */
  87.     protected $position;
  88.     
  89.     /**
  90.      * @ORM\Column(name="email", type="string", unique=true)
  91.      */
  92.     protected $email;
  93.     /**
  94.      * @ORM\Column(name="name", type="string")
  95.      */
  96.     protected $name;
  97.     
  98.     /**
  99.      * @ORM\Column(name="surname", type="string")
  100.      */
  101.     protected $surname;
  102.     
  103.     /**
  104.      * @ORM\Column(name="password", type="string", nullable=true)
  105.      */
  106.     protected $password;
  107.     
  108.     /**
  109.      * @ORM\Column(name="role", type="string")
  110.      */
  111.     protected $role "ROLE_USER";
  112.     
  113.     /**
  114.      * @ORM\Column(name="one_time_code", type="string", nullable=true)
  115.      */
  116.     protected $oneTimeCode;
  117.     
  118.     /**
  119.      * @ORM\Column(name="expiration_one_time_code", type="datetime", nullable=true)
  120.      */
  121.     protected $expirationOneTimeCode;
  122.     
  123.     /**
  124.      * @ORM\Column(name="is_tutorial_active", type="boolean")
  125.      */
  126.     protected $isTutorialActive true;
  127.     
  128.     /**
  129.      * @ORM\Column(name="is_admin_active", type="boolean")
  130.      */
  131.     protected $isAdminActive true;
  132.     
  133.     // ONE TO MANY
  134.         /**
  135.          * @ORM\OneToMany(targetEntity="App\Entity\Master\Notification", mappedBy="user")
  136.          */
  137.         private $notifications;
  138.         
  139.         /**
  140.          * @ORM\OneToMany(targetEntity="App\Entity\Master\JoinTableOfficeUser", mappedBy="user")
  141.          */
  142.         private $offices;
  143.     //
  144.     // MANY TO ONE        
  145.         /**
  146.          * @ORM\ManyToOne(targetEntity="App\Entity\Master\Reseller", inversedBy="users")
  147.          * @ORM\JoinColumn(name="reseller_id", referencedColumnName="id", nullable=true)
  148.          */
  149.         private $reseller;
  150.         public function __construct()
  151.         {
  152.             $this->notifications = new ArrayCollection();
  153.             $this->offices = new ArrayCollection();
  154.         }
  155.     //
  156.     
  157.     public function getUserIdentifier(): string
  158.     {
  159.         return (string) $this->email;
  160.     }
  161.     public function getRoles(): array
  162.     {
  163.         switch($this->role){
  164.             case 'ROLE_USER': return array('ROLE_USER');
  165.             case 'ROLE_RESELLER': return array('ROLE_RESELLER');
  166.             case 'ROLE_ADMIN': return array('ROLE_ADMIN');
  167.         };
  168.     }
  169.     public function getPassword(): string
  170.     {
  171.         return $this->password;
  172.     }
  173.     public function setPassword(string $password): self
  174.     {
  175.         $this->password $password;
  176.         return $this;
  177.     }
  178.     public function getSalt(): ?string
  179.     {
  180.         return null;
  181.     }
  182.     public function eraseCredentials() {
  183.         return;
  184.     }
  185.     
  186.     public function getUsername(): string
  187.     {
  188.         return $this->email;
  189.     }
  190.     public function getId(): ?string
  191.     {
  192.         return $this->id;
  193.     }
  194.     public function getPosition(): ?string
  195.     {
  196.         return $this->position;
  197.     }
  198.     public function setPosition(?string $position): self
  199.     {
  200.         $this->position $position;
  201.         return $this;
  202.     }
  203.     public function getEmail(): ?string
  204.     {
  205.         return $this->email;
  206.     }
  207.     public function setEmail(string $email): self
  208.     {
  209.         $this->email $email;
  210.         return $this;
  211.     }
  212.     public function getName(): ?string
  213.     {
  214.         return $this->name;
  215.     }
  216.     public function setName(string $name): self
  217.     {
  218.         $this->name $name;
  219.         return $this;
  220.     }
  221.     public function getSurname(): ?string
  222.     {
  223.         return $this->surname;
  224.     }
  225.     public function setSurname(string $surname): self
  226.     {
  227.         $this->surname $surname;
  228.         return $this;
  229.     }
  230.     public function getRole(): ?string
  231.     {
  232.         return $this->role;
  233.     }
  234.     public function setRole(string $role): self
  235.     {
  236.         $this->role $role;
  237.         return $this;
  238.     }
  239.     public function getOneTimeCode(): ?string
  240.     {
  241.         return $this->oneTimeCode;
  242.     }
  243.     public function setOneTimeCode(?string $oneTimeCode): self
  244.     {
  245.         $this->oneTimeCode $oneTimeCode;
  246.         return $this;
  247.     }
  248.     public function getExpirationOneTimeCode(): ?\DateTimeInterface
  249.     {
  250.         return $this->expirationOneTimeCode;
  251.     }
  252.     public function setExpirationOneTimeCode(?\DateTimeInterface $expirationOneTimeCode): self
  253.     {
  254.         $this->expirationOneTimeCode $expirationOneTimeCode;
  255.         return $this;
  256.     }
  257.     public function isIsTutorialActive(): ?bool
  258.     {
  259.         return $this->isTutorialActive;
  260.     }
  261.     public function setIsTutorialActive(bool $isTutorialActive): self
  262.     {
  263.         $this->isTutorialActive $isTutorialActive;
  264.         return $this;
  265.     }
  266.     public function isIsAdminActive(): ?bool
  267.     {
  268.         return $this->isAdminActive;
  269.     }
  270.     public function setIsAdminActive(bool $isAdminActive): self
  271.     {
  272.         $this->isAdminActive $isAdminActive;
  273.         return $this;
  274.     }
  275.     /**
  276.      * @return Collection<int, Notification>
  277.      */
  278.     public function getNotifications(): Collection
  279.     {
  280.         return $this->notifications;
  281.     }
  282.     public function addNotification(Notification $notification): self
  283.     {
  284.         if (!$this->notifications->contains($notification)) {
  285.             $this->notifications[] = $notification;
  286.             $notification->setUser($this);
  287.         }
  288.         return $this;
  289.     }
  290.     public function removeNotification(Notification $notification): self
  291.     {
  292.         if ($this->notifications->removeElement($notification)) {
  293.             // set the owning side to null (unless already changed)
  294.             if ($notification->getUser() === $this) {
  295.                 $notification->setUser(null);
  296.             }
  297.         }
  298.         return $this;
  299.     }
  300.     /**
  301.      * @return Collection<int, JoinTableOfficeUser>
  302.      */
  303.     public function getOffices(): Collection
  304.     {
  305.         return $this->offices;
  306.     }
  307.     public function addOffice(JoinTableOfficeUser $office): self
  308.     {
  309.         if (!$this->offices->contains($office)) {
  310.             $this->offices[] = $office;
  311.             $office->setUser($this);
  312.         }
  313.         return $this;
  314.     }
  315.     public function removeOffice(JoinTableOfficeUser $office): self
  316.     {
  317.         if ($this->offices->removeElement($office)) {
  318.             // set the owning side to null (unless already changed)
  319.             if ($office->getUser() === $this) {
  320.                 $office->setUser(null);
  321.             }
  322.         }
  323.         return $this;
  324.     }
  325.     public function getReseller(): ?Reseller
  326.     {
  327.         return $this->reseller;
  328.     }
  329.     public function setReseller(?Reseller $reseller): self
  330.     {
  331.         $this->reseller $reseller;
  332.         return $this;
  333.     } 
  334. }