src/Entity/User.php line 21

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Mapped\Entity;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\EquatableInterface;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * @ORM\Entity()
  14.  * @ORM\Table(name="user")
  15.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  16.  * @UniqueEntity(fields="email", message="registracija.emailVecPostoji", groups={"registration"})
  17.  */
  18. class User extends Entity implements EquatableInterface,UserInterface,PasswordAuthenticatedUserInterface
  19. {
  20.     /**
  21.      * @ORM\Column(type="string", length=180, name="first_name", nullable=true)
  22.      * @Assert\NotBlank(groups={"registration", "update"})
  23.      * @Assert\Length(max="100", groups={"registration", "update"})
  24.      */
  25.     private $firstName;
  26.     /**
  27.      * @ORM\Column(type="string", length=180, name="last_name", nullable=true)
  28.      * @Assert\NotBlank(groups={"registration", "update"})
  29.      * @Assert\Length(max="100", groups={"registration", "update"})
  30.      */
  31.     private $lastName;
  32.     /**
  33.      * @ORM\Column(type="simple_array")
  34.      */
  35.     private $roles = [];
  36.     /**
  37.      * @var string The hashed password
  38.      * @ORM\Column(type="string" , nullable=false, name="password")
  39.      */
  40.     private $password;
  41.     /**
  42.      * @Assert\Length(max="4096", groups={"registration", "password-reset", "update"})
  43.      * @Assert\NotBlank(groups={"registration", "password-reset"})
  44.      */
  45.     private $plainPassword;
  46.     /**
  47.      * @ORM\Column(type="string", length=100, unique=true)
  48.      * @Assert\Email(groups={"registration"}, message = "registracija.neispravanEmail")
  49.      * @Assert\NotBlank(groups={"registration"})
  50.      * @Assert\Length(max="100", groups={"registration"})
  51.      */
  52.     private $email;
  53.     /**
  54.      * @Gedmo\Slug(fields={"email"})
  55.      * @ORM\Column(name="slug", length=128)
  56.      */
  57.     private $slug;
  58.     /**
  59.      * @var $token
  60.      * @ORM\Column(name="token", type="string", length=191, nullable=true)
  61.      */
  62.     private $token null;
  63.     /**
  64.      * @var $registrationToken
  65.      * @ORM\Column(name="registration_token", type="string", length=191, nullable=true)
  66.      */
  67.     private $registrationToken null;
  68.     /**
  69.      * @ORM\Column(name="menu_visibility", type="boolean")
  70.      */
  71.     private $menuVisibility false;
  72.     /**
  73.      * @ORM\ManyToOne(targetEntity="App\Entity\City")
  74.      * @ORM\JoinColumn(name="city")
  75.      */
  76.     private $city;
  77.     /**
  78.      * @ORM\OneToMany(
  79.      *     targetEntity="App\Entity\NotificationSystem",
  80.      *     mappedBy="recipient",
  81.      *     fetch="EXTRA_LAZY",
  82.      *     orphanRemoval=true,
  83.      *     cascade={"persist"}
  84.      * )
  85.      */
  86.     private $notification;
  87.     /**
  88.      * @ORM\OneToMany(
  89.      *     targetEntity="App\Entity\TenderUser",
  90.      *     mappedBy="user",
  91.      *     fetch="EXTRA_LAZY",
  92.      *     orphanRemoval=true,
  93.      *     cascade={"persist"}
  94.      * )
  95.      */
  96.     private $tenderUser;
  97.     public function __construct()
  98.     {
  99.         $this->tenderUser = new ArrayCollection();
  100.     }
  101.     /**
  102.      * @return mixed
  103.      */
  104.     public function getFirstName()
  105.     {
  106.         return $this->firstName;
  107.     }
  108.     /**
  109.      * @param mixed $firstName
  110.      * @return User
  111.      */
  112.     public function setFirstName($firstName): self
  113.     {
  114.         $this->firstName $firstName;
  115.         return $this;
  116.     }
  117.     /**
  118.      * @return mixed
  119.      */
  120.     public function getLastName()
  121.     {
  122.         return $this->lastName;
  123.     }
  124.     /**
  125.      * @param mixed $lastName
  126.      * @return User
  127.      */
  128.     public function setLastName($lastName): self
  129.     {
  130.         $this->lastName $lastName;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return mixed
  135.      */
  136.     public function getSlug()
  137.     {
  138.         return $this->slug;
  139.     }
  140.     /**
  141.      * @param mixed $slug
  142.      * @return User
  143.      */
  144.     public function setSlug($slug): self
  145.     {
  146.         $this->slug $slug;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return mixed
  151.      */
  152.     public function getPlainPassword()
  153.     {
  154.         return $this->plainPassword;
  155.     }
  156.     /**
  157.      * @param mixed $plainPassword
  158.      * @return User
  159.      */
  160.     public function setPlainPassword($plainPassword): self
  161.     {
  162.         $this->plainPassword $plainPassword;
  163.         $this->password null;
  164.         return $this;
  165.     }
  166.     public function getPassword(): ?string
  167.     {
  168.         return $this->password;
  169.     }
  170.     /**
  171.      * @param string $password
  172.      * @return User
  173.      */
  174.     public function setPassword(string $password): self
  175.     {
  176.         $this->password $password;
  177.         return $this;
  178.     }
  179.     /**
  180.      * @return mixed
  181.      */
  182.     public function getEmail()
  183.     {
  184.         return $this->email;
  185.     }
  186.     /**
  187.      * @param mixed $email
  188.      * @return User
  189.      */
  190.     public function setEmail($email): self
  191.     {
  192.         $this->email $email;
  193.         return $this;
  194.     }
  195.     public function getUsername()
  196.     {
  197.         return $this->email;
  198.     }
  199.     public function getRoles() :array
  200.     {
  201.         $roles $this->roles;
  202.         // guarantee every user at least has ROLE_USER
  203.         $roles[] = 'ROLE_USER';
  204.         return array_unique($roles);
  205.     }
  206.     /**
  207.      * @param array $roles
  208.      * @return $this
  209.      */
  210.     public function setRoles(array $roles): self
  211.     {
  212.         $this->roles $roles;
  213.         return $this;
  214.     }
  215.     /**
  216.      * @return mixed
  217.      */
  218.     public function getToken()
  219.     {
  220.         return $this->token;
  221.     }
  222.     /**
  223.      * @param mixed $token
  224.      * @return User
  225.      */
  226.     public function setToken($token): self
  227.     {
  228.         $this->token $token;
  229.         return $this;
  230.     }
  231.     /**
  232.      * @return mixed
  233.      */
  234.     public function getRegistrationToken()
  235.     {
  236.         return $this->registrationToken;
  237.     }
  238.     /**
  239.      * @param mixed $registrationToken
  240.      * @return User
  241.      */
  242.     public function setRegistrationToken($registrationToken): self
  243.     {
  244.         $this->registrationToken $registrationToken;
  245.         return $this;
  246.     }
  247.     /**
  248.      * @return string
  249.      */
  250.     public function getFullName(): string
  251.     {
  252.         return $this->getFirstName() . ' ' $this->getLastName();
  253.     }
  254.     /**
  255.      * @return bool
  256.      */
  257.     public function isMenuVisibility(): bool
  258.     {
  259.         return $this->menuVisibility;
  260.     }
  261.     /**
  262.      * @param bool $menuVisibility
  263.      */
  264.     public function setMenuVisibility(bool $menuVisibility): void
  265.     {
  266.         $this->menuVisibility $menuVisibility;
  267.     }
  268.     /**
  269.      * @return mixed
  270.      */
  271.     public function getNotification()
  272.     {
  273.         return $this->notification;
  274.     }
  275.     /**
  276.      * @param mixed $notification
  277.      */
  278.     public function setNotification($notification): void
  279.     {
  280.         $this->notification $notification;
  281.     }
  282.     /**
  283.      * @return ArrayCollection
  284.      */
  285.     public function getTenderUser(): ArrayCollection
  286.     {
  287.         return $this->tenderUser;
  288.     }
  289.     /**
  290.      * @return mixed
  291.      */
  292.     public function getCity()
  293.     {
  294.         return $this->city;
  295.     }
  296.     /**
  297.      * @param mixed $city
  298.      */
  299.     public function setCity($city): void
  300.     {
  301.         $this->city $city;
  302.     }
  303.     /**
  304.      * @return int
  305.      */
  306.     public function isNotificationsUnread()
  307.     {
  308.         /** @var NotificationSystem $n */
  309.         foreach ($this->getNotification() as $n) {
  310.             if (null === $n->getReadDate()) {
  311.                 return true;
  312.             }
  313.         }
  314.         return false;
  315.     }
  316.     /**
  317.      * @return bool|int
  318.      */
  319.     public function getReference()
  320.     {
  321.     }
  322.     public function getSalt(){}
  323.     public function eraseCredentials(){}
  324.     /**
  325.      * The equality comparison should neither be done by referential equality
  326.      * nor by comparing identities (i.e. getId() === getId()).
  327.      *
  328.      * However, you do not need to compare every attribute, but only those that
  329.      * are relevant for assessing whether re-authentication is required.
  330.      *
  331.      * Also implementation should consider that $user instance may implement
  332.      * the extended user interface `AdvancedUserInterface`.
  333.      *
  334.      * @param UserInterface $user
  335.      *
  336.      * @return bool
  337.      */
  338.     public function isEqualTo(UserInterface $user): bool
  339.     {
  340.         return $user->getPassword() === $this->getPassword();
  341.     }
  342.     /**
  343.      * @return string
  344.      */
  345.     public function getUserIdentifier():string
  346.     {
  347.         return $this->getUsername();
  348.     }
  349. }