src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  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\Table(name="fs_user")
  11.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     public function __toString()
  17.     {
  18.         return $this->name." ".$this->surname;
  19.     }
  20.     
  21.     public function canConfigureAgency($agencyId){
  22.         foreach($this->agencies as $jt){
  23.             if($jt->getAgency()->getId() == $agencyId){
  24.                 $jtou $jt;
  25.                 break;
  26.             }
  27.         }
  28.         if($this->getRole() == "ROLE_ADMIN"){
  29.             return true;
  30.         }
  31.         elseif($jtou->getRole()->getSlug() == "responsible"){
  32.             if($this->isAdminActive && $jtou->getAgency() != null && $jtou->getAgency()->getIsActive())
  33.                 return true;
  34.         }
  35.         elseif($jtou->getRole()->getSlug() == "on_charge" || $jtou->getRole()->getSlug() == "delegate"){
  36.             if($this->isAdminActive && $jtou->getAgency() != null && $jtou->getAgency()->getIsActive() && $jtou->getAgency()->getIsConfigurationCompleted())
  37.                 return true;
  38.         }
  39.         return false;
  40.     }
  41.     public function canEditAgency($agencyId)
  42.     {
  43.         foreach($this->agencies as $jt){
  44.             if($jt->getAgency()->getId() == $agencyId){
  45.                 $jtou $jt;
  46.                 break;
  47.             }
  48.         }
  49.         
  50.         if($this->getRole() == "ROLE_ADMIN"){
  51.             return true;
  52.         }
  53.         elseif($jtou->getUser()->getRole() == "ROLE_USER"){
  54.             if($this->isAdminActive && $jtou->getAgency() != null && $jtou->getAgency()->getIsActive())
  55.                 return true;
  56.         }
  57.         return false;
  58.     }
  59.     
  60.     public function displayName()
  61.     {
  62.         return $this->name." ".$this->surname;
  63.     }
  64.     
  65.     /**
  66.      * @ORM\Column(name="id", type="bigint")
  67.      * @ORM\Id
  68.      * @ORM\GeneratedValue(strategy="AUTO")
  69.      */
  70.     protected $id;
  71.     
  72.     /**
  73.      * @ORM\Column(name="email", type="string", unique=true)
  74.      */
  75.     protected $email;
  76.     /**
  77.      * @ORM\Column(name="name", type="string")
  78.      */
  79.     protected $name;
  80.     
  81.     /**
  82.      * @ORM\Column(name="surname", type="string")
  83.      */
  84.     protected $surname;
  85.     
  86.     /**
  87.      * @ORM\Column(name="password", type="string", nullable=true)
  88.      */
  89.     protected $password;
  90.     
  91.     /**
  92.      * @ORM\Column(name="role", type="string")
  93.      */
  94.     protected $role "ROLE_USER";
  95.     
  96.     /**
  97.      * @ORM\Column(name="one_time_code", type="string", nullable=true)
  98.      */
  99.     protected $oneTimeCode;
  100.         
  101.     /**
  102.      * @ORM\Column(name="active", type="boolean")
  103.      */
  104.     protected $active true;
  105.     
  106.     /**
  107.      * @ORM\Column(name="admin_active", type="boolean")
  108.      */
  109.     protected $adminActive true;
  110.     
  111.     /**
  112.      * @ORM\Column(name="directory_path", type="string", length=191, nullable=true)
  113.      */
  114.     protected $directoryPath;
  115.     
  116.     // ONE TO ONE
  117.         /**
  118.          * @ORM\OneToOne(targetEntity="App\Entity\UserDetail", mappedBy="user")
  119.          */
  120.         private $userDetail;
  121.     //
  122.     // ONE TO MANY
  123.         /**
  124.          * @ORM\OneToMany(targetEntity="App\Entity\JoinTableAgencyUser", mappedBy="user")
  125.          */
  126.         private $agencies;
  127.         
  128.         /**
  129.          * @ORM\OneToMany(targetEntity="App\Entity\JoinTableDealerUser", mappedBy="user")
  130.          */
  131.         private $dealers;
  132.         
  133.         /**
  134.          * @ORM\OneToMany(targetEntity="App\Entity\Reservation", mappedBy="user")
  135.          */
  136.         private $reservations;
  137.     //
  138.     public function __construct()
  139.     {
  140.         $this->agencies = new ArrayCollection();
  141.         $this->reservations = new ArrayCollection();
  142.         $this->dealers = new ArrayCollection();
  143.     }
  144.     public function getUserIdentifier(): string
  145.     {
  146.         return (string) $this->email;
  147.     }
  148.     public function getRoles(): array
  149.     {
  150.         switch($this->role){
  151.             case 'ROLE_USER': return array('ROLE_USER');
  152.             case 'ROLE_ADMIN': return array('ROLE_ADMIN');
  153.         };
  154.     }
  155.     public function getPassword(): string
  156.     {
  157.         return $this->password;
  158.     }
  159.     public function setPassword(string $password): self
  160.     {
  161.         $this->password $password;
  162.         return $this;
  163.     }
  164.     public function getSalt(): ?string
  165.     {
  166.         return null;
  167.     }
  168.     public function eraseCredentials() {
  169.         return;
  170.     }
  171.     
  172.     public function getUsername(): string
  173.     {
  174.         return $this->email;
  175.     }
  176.     public function getId(): ?string
  177.     {
  178.         return $this->id;
  179.     }
  180.     public function getEmail(): ?string
  181.     {
  182.         return $this->email;
  183.     }
  184.     public function setEmail(string $email): self
  185.     {
  186.         $this->email $email;
  187.         return $this;
  188.     }
  189.     public function getName(): ?string
  190.     {
  191.         return $this->name;
  192.     }
  193.     public function setName(string $name): self
  194.     {
  195.         $this->name $name;
  196.         return $this;
  197.     }
  198.     public function getSurname(): ?string
  199.     {
  200.         return $this->surname;
  201.     }
  202.     public function setSurname(string $surname): self
  203.     {
  204.         $this->surname $surname;
  205.         return $this;
  206.     }
  207.     public function getRole(): ?string
  208.     {
  209.         return $this->role;
  210.     }
  211.     public function setRole(string $role): self
  212.     {
  213.         $this->role $role;
  214.         return $this;
  215.     }
  216.     public function getOneTimeCode(): ?string
  217.     {
  218.         return $this->oneTimeCode;
  219.     }
  220.     public function setOneTimeCode(?string $oneTimeCode): self
  221.     {
  222.         $this->oneTimeCode $oneTimeCode;
  223.         return $this;
  224.     }
  225.     public function isActive(): ?bool
  226.     {
  227.         return $this->active;
  228.     }
  229.     public function setActive(bool $active): self
  230.     {
  231.         $this->active $active;
  232.         return $this;
  233.     }
  234.     public function isAdminActive(): ?bool
  235.     {
  236.         return $this->adminActive;
  237.     }
  238.     public function setAdminActive(bool $adminActive): self
  239.     {
  240.         $this->adminActive $adminActive;
  241.         return $this;
  242.     }
  243.     public function getDirectoryPath(): ?string
  244.     {
  245.         return $this->directoryPath;
  246.     }
  247.     public function setDirectoryPath(?string $directoryPath): self
  248.     {
  249.         $this->directoryPath $directoryPath;
  250.         return $this;
  251.     }
  252.     public function getUserDetail(): ?UserDetail
  253.     {
  254.         return $this->userDetail;
  255.     }
  256.     public function setUserDetail(?UserDetail $userDetail): self
  257.     {
  258.         // unset the owning side of the relation if necessary
  259.         if ($userDetail === null && $this->userDetail !== null) {
  260.             $this->userDetail->setUser(null);
  261.         }
  262.         // set the owning side of the relation if necessary
  263.         if ($userDetail !== null && $userDetail->getUser() !== $this) {
  264.             $userDetail->setUser($this);
  265.         }
  266.         $this->userDetail $userDetail;
  267.         return $this;
  268.     }
  269.     /**
  270.      * @return Collection<int, JoinTableAgencyUser>
  271.      */
  272.     public function getAgencies(): Collection
  273.     {
  274.         return $this->agencies;
  275.     }
  276.     public function addAgency(JoinTableAgencyUser $agency): self
  277.     {
  278.         if (!$this->agencies->contains($agency)) {
  279.             $this->agencies->add($agency);
  280.             $agency->setUser($this);
  281.         }
  282.         return $this;
  283.     }
  284.     public function removeAgency(JoinTableAgencyUser $agency): self
  285.     {
  286.         if ($this->agencies->removeElement($agency)) {
  287.             // set the owning side to null (unless already changed)
  288.             if ($agency->getUser() === $this) {
  289.                 $agency->setUser(null);
  290.             }
  291.         }
  292.         return $this;
  293.     }
  294.     /**
  295.      * @return Collection<int, Reservation>
  296.      */
  297.     public function getReservations(): Collection
  298.     {
  299.         return $this->reservations;
  300.     }
  301.     public function addReservation(Reservation $reservation): self
  302.     {
  303.         if (!$this->reservations->contains($reservation)) {
  304.             $this->reservations->add($reservation);
  305.             $reservation->setUser($this);
  306.         }
  307.         return $this;
  308.     }
  309.     public function removeReservation(Reservation $reservation): self
  310.     {
  311.         if ($this->reservations->removeElement($reservation)) {
  312.             // set the owning side to null (unless already changed)
  313.             if ($reservation->getUser() === $this) {
  314.                 $reservation->setUser(null);
  315.             }
  316.         }
  317.         return $this;
  318.     }
  319.     /**
  320.      * @return Collection<int, JoinTableDealerUser>
  321.      */
  322.     public function getDealers(): Collection
  323.     {
  324.         return $this->dealers;
  325.     }
  326.     public function addDealer(JoinTableDealerUser $dealer): self
  327.     {
  328.         if (!$this->dealers->contains($dealer)) {
  329.             $this->dealers->add($dealer);
  330.             $dealer->setUser($this);
  331.         }
  332.         return $this;
  333.     }
  334.     public function removeDealer(JoinTableDealerUser $dealer): self
  335.     {
  336.         if ($this->dealers->removeElement($dealer)) {
  337.             // set the owning side to null (unless already changed)
  338.             if ($dealer->getUser() === $this) {
  339.                 $dealer->setUser(null);
  340.             }
  341.         }
  342.         return $this;
  343.     }
  344. }