src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  14.  */
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     const INSTRUCTOR 'instructor';
  18.     const CUSTOMER 'customer';
  19.     const ROLE_INSTRUCTOR 'ROLE_INSTRUCTOR';
  20.     const ROLE_CUSTOMER 'ROLE_CUSTOMER';
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @ORM\Column(type="string", length=180, unique=true)
  29.      */
  30.     private $email;
  31.     /**
  32.      * @ORM\Column(type="json")
  33.      */
  34.     private $roles = [];
  35.     /**
  36.      * @var string The hashed password
  37.      * @ORM\Column(type="string")
  38.      */
  39.     private $password;
  40.     /**
  41.      * @ORM\Column(type="string", length=255)
  42.      */
  43.     private $firstName;
  44.     /**
  45.      * @ORM\Column(type="string", length=255)
  46.      */
  47.     private $lastName;
  48.     /**
  49.      * @ORM\Column(type="datetime", nullable=true)
  50.      */
  51.     private $subscriptionDuedate;
  52.     /**
  53.      * @ORM\Column(type="datetime_immutable")
  54.      */
  55.     private $createdAt;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity=Cours::class, mappedBy="author")
  58.      */
  59.     private $cours;
  60.     /**
  61.      * @ORM\Column(type="array", nullable=true)
  62.      * [
  63.      *  0 => read later []
  64.      *  1 => last view []
  65.      * ]
  66.      */
  67.     private $story = [];
  68.     /**
  69.      * @ORM\Column(type="boolean")
  70.      */
  71.     private $paswwordChanged;
  72.     /**
  73.      * @ORM\OneToMany(targetEntity=ResetPassword::class, mappedBy="user")
  74.      */
  75.     private $resetPasswords;
  76.     /**
  77.      * @ORM\Column(type="string", length=255, nullable=true)
  78.      */
  79.     private $adminEmailRecovery;
  80.     /**
  81.      * @ORM\Column(type="array", nullable=true)
  82.      */
  83.     private $readLater = [];
  84.     public function __construct()
  85.     {
  86.         $this->createdAt = new \DateTimeImmutable();
  87.         $this->subscriptionDuedate = new \DateTime();
  88.         $this->cours = new ArrayCollection();
  89.         $this->paswwordChanged false;
  90.         $this->resetPasswords = new ArrayCollection();
  91.     }
  92.     public function getId(): ?int
  93.     {
  94.         return $this->id;
  95.     }
  96.     public function getEmail(): ?string
  97.     {
  98.         return $this->email;
  99.     }
  100.     public function setEmail(string $email): self
  101.     {
  102.         $this->email $email;
  103.         return $this;
  104.     }
  105.     /**
  106.      * A visual identifier that represents this user.
  107.      *
  108.      * @see UserInterface
  109.      */
  110.     public function getUserIdentifier(): string
  111.     {
  112.         return (string) $this->email;
  113.     }
  114.     /**
  115.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  116.      */
  117.     public function getUsername(): string
  118.     {
  119.         return (string) $this->email;
  120.     }
  121.     /**
  122.      * @see UserInterface
  123.      */
  124.     public function getRoles(): array
  125.     {
  126.         $roles $this->roles;
  127.         // guarantee every user at least has ROLE_USER
  128.         $roles[] = 'ROLE_USER';
  129.         return array_unique($roles);
  130.     }
  131.     public function setRoles(array $roles): self
  132.     {
  133.         $this->roles $roles;
  134.         return $this;
  135.     }
  136.     /**
  137.      * @see PasswordAuthenticatedUserInterface
  138.      */
  139.     public function getPassword(): string
  140.     {
  141.         return $this->password;
  142.     }
  143.     public function setPassword(string $password): self
  144.     {
  145.         $this->password $password;
  146.         return $this;
  147.     }
  148.     /**
  149.      * Returning a salt is only needed, if you are not using a modern
  150.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  151.      *
  152.      * @see UserInterface
  153.      */
  154.     public function getSalt(): ?string
  155.     {
  156.         return null;
  157.     }
  158.     /**
  159.      * @see UserInterface
  160.      */
  161.     public function eraseCredentials()
  162.     {
  163.         // If you store any temporary, sensitive data on the user, clear it here
  164.         // $this->plainPassword = null;
  165.     }
  166.     public function getFirstName(): ?string
  167.     {
  168.         return $this->firstName;
  169.     }
  170.     public function setFirstName(string $firstName): self
  171.     {
  172.         $this->firstName $firstName;
  173.         return $this;
  174.     }
  175.     public function getLastName(): ?string
  176.     {
  177.         return $this->lastName;
  178.     }
  179.     public function setLastName(string $lastName): self
  180.     {
  181.         $this->lastName $lastName;
  182.         return $this;
  183.     }
  184.     public function getSubscriptionDuedate(): ?\DateTime
  185.     {
  186.         return $this->subscriptionDuedate;
  187.     }
  188.     public function setSubscriptionDuedate(?\DateTime $subscriptionDuedate): self
  189.     {
  190.         $this->subscriptionDuedate $subscriptionDuedate;
  191.         return $this;
  192.     }
  193.     public function getCreatedAt(): ?\DateTimeImmutable
  194.     {
  195.         return $this->createdAt;
  196.     }
  197.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  198.     {
  199.         $this->createdAt $createdAt;
  200.         return $this;
  201.     }
  202.     public function getFullName(): string
  203.     {
  204.         return $this->firstName ' ' $this->lastName;
  205.     }
  206.     public function __toString()
  207.     {
  208.         return $this->getFullName();
  209.     }
  210.     public function getSubscriptionActive(): bool
  211.     {
  212.         $now = new \DateTime();
  213.         return $this->subscriptionDuedate $now;
  214.     }
  215.     public function extendsMembershipsFromNow(int $days): self
  216.     {
  217.         $this->subscriptionDuedate->modify("+" $days " days");
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return Collection<int, Cours>
  222.      */
  223.     public function getCours(): Collection
  224.     {
  225.         return $this->cours;
  226.     }
  227.     public function addCour(Cours $cour): self
  228.     {
  229.         if (!$this->cours->contains($cour)) {
  230.             $this->cours[] = $cour;
  231.             $cour->setAuthor($this);
  232.         }
  233.         return $this;
  234.     }
  235.     public function removeCour(Cours $cour): self
  236.     {
  237.         if ($this->cours->removeElement($cour)) {
  238.             // set the owning side to null (unless already changed)
  239.             if ($cour->getAuthor() === $this) {
  240.                 $cour->setAuthor(null);
  241.             }
  242.         }
  243.         return $this;
  244.     }
  245.     public function getStory(): ?array
  246.     {
  247.         return $this->story;
  248.     }
  249.     public function setStory(?array $story): self
  250.     {
  251.         $this->story $story;
  252.         return $this;
  253.     }
  254.     public function getLastViews(): array
  255.     {
  256.         if($this->story == null){
  257.             return [];
  258.         }
  259.        return array_slice($this->story01);
  260.     }
  261.     public function getReadlerList(): array
  262.     {
  263.         if($this->readLater == null){
  264.             return [];
  265.         }
  266.         return array_slice($this->readLater06);
  267.     }
  268.     public function addToReadLater(int $id): self
  269.     {
  270.         if($this->readLater == null){
  271.             $this->readLater = [];
  272.         }
  273.         if(in_array($id$this->readLater)){
  274.             return $this;
  275.         }
  276.         array_unshift($this->readLater$id);
  277.         return $this;
  278.     }
  279.     public function isViewlater(int $id): bool
  280.     {
  281.         return in_array($id$this->readLater);
  282.     }
  283.     public function removeReadLater(int $id): void
  284.     {
  285.         if($this->readLater == null){
  286.             $this->readLater = [];
  287.         }
  288.         $this->readLater array_filter($this->readLater, function($item) use($id){
  289.            if($item != $id){
  290.             return $item;
  291.            } 
  292.         });
  293.     }
  294.     public function removeHistory(int $id): void
  295.     {
  296.         if($this->story == null){
  297.             $this->story = [];
  298.         }
  299.         $this->story array_filter($this->story, function($item) use($id){
  300.            if($item != $id){
  301.             return $item;
  302.            } 
  303.         });
  304.     }
  305.     public function addToLastView(int $id): self
  306.     {
  307.         if($this->story == null){
  308.             $this->story = [];
  309.         }
  310.         array_unshift($this->story$id);
  311.         return $this;
  312.     }
  313.     public function isPaswwordChanged(): ?bool
  314.     {
  315.         return $this->paswwordChanged;
  316.     }
  317.     public function setPaswwordChanged(bool $paswwordChanged): self
  318.     {
  319.         $this->paswwordChanged $paswwordChanged;
  320.         return $this;
  321.     }
  322.     /**
  323.      * @return Collection<int, ResetPassword>
  324.      */
  325.     public function getResetPasswords(): Collection
  326.     {
  327.         return $this->resetPasswords;
  328.     }
  329.     public function addResetPassword(ResetPassword $resetPassword): self
  330.     {
  331.         if (!$this->resetPasswords->contains($resetPassword)) {
  332.             $this->resetPasswords[] = $resetPassword;
  333.             $resetPassword->setUser($this);
  334.         }
  335.         return $this;
  336.     }
  337.     public function removeResetPassword(ResetPassword $resetPassword): self
  338.     {
  339.         if ($this->resetPasswords->removeElement($resetPassword)) {
  340.             // set the owning side to null (unless already changed)
  341.             if ($resetPassword->getUser() === $this) {
  342.                 $resetPassword->setUser(null);
  343.             }
  344.         }
  345.         return $this;
  346.     }
  347.     public function getAdminEmailRecovery(): ?string
  348.     {
  349.         return $this->adminEmailRecovery;
  350.     }
  351.     public function setAdminEmailRecovery(?string $adminEmailRecovery): self
  352.     {
  353.         $this->adminEmailRecovery $adminEmailRecovery;
  354.         return $this;
  355.     }
  356.     public function getReadLater(): ?array
  357.     {
  358.         return $this->readLater;
  359.     }
  360.     public function setReadLater(?array $readLater): self
  361.     {
  362.         $this->readLater $readLater;
  363.         return $this;
  364.     }
  365. }