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