src/Entity/User.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Domain;
  4. use App\Entity\Course;
  5. use App\Entity\SchoolYear;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use App\Entity\Traits\TimeStampable;
  9. use App\Repository\UserRepository;
  10. use App\Entity\Traits\HasUploadableField;
  11. use App\Repository\AttributionRepository;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Symfony\Component\Security\Core\User\UserInterface;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. /**
  18.  * @ORM\Entity(repositoryClass=UserRepository::class)
  19.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  20.  * @UniqueEntity(fields={"phoneNumber"}, message="There is already an account with this phone number")
  21.  * @UniqueEntity(fields={"numCni"}, message="There is already an account with this cni number")
  22.  * @ORM\HasLifecycleCallbacks
  23.  * 
  24.  */
  25. class User implements UserInterface//, PasswordAuthenticatedUserInterface
  26. {
  27.     use TimeStampable;
  28.     use HasUploadableField;
  29.     /**
  30.      * @ORM\Id
  31.      * @ORM\GeneratedValue
  32.      * @ORM\Column(type="integer")
  33.      */
  34.     private $id;
  35.     /**
  36.      * @ORM\Column(type="string", length=180, unique=true)
  37.      * @Assert\NotBlank(message="Please enter your email address")
  38.      * @Assert\NotBlank(message="Please enter a valid  email address")
  39.      */
  40.     private $email;
  41.       /** @ORM\Column(name="github_id", type="string", length=255, nullable=true) */
  42.      private $github_id;
  43.     
  44.      /** @ORM\Column(name="github_access_token", type="string", length=255, nullable=true) */
  45.      private $github_access_token;
  46.  
  47.      /** @ORM\Column(name="facebook_id", type="string", length=255, nullable=true) */
  48.      private $facebook_id;
  49.  
  50.      /** @ORM\Column(name="facebook_access_token", type="string", length=255, nullable=true) */
  51.      private $facebook_access_token;
  52.  
  53.      /** @ORM\Column(name="google_id", type="string", length=255, nullable=true) */
  54.      private $google_id;
  55.  
  56.      /** @ORM\Column(name="google_access_token", type="string", length=255, nullable=true) */
  57.      private $google_access_token;
  58.  
  59.      /** @ORM\Column(name="linkedin_id", type="string", length=255, nullable=true) */
  60.      private $linkedin_id;
  61.  
  62.      /** @ORM\Column(name="linkedin_access_token", type="string", length=255, nullable=true) */
  63.      private $linkedin_access_token;
  64.     /** @ORM\Column(name="twitter_id", type="string", length=255, nullable=true) */
  65.     private $twitter_id;
  66.      /** @ORM\Column(name="twitter_access_token", type="string", length=255, nullable=true) */
  67.      private $twitter_access_token;
  68.      /** @ORM\Column(name="yahoo_id", type="string", length=255, nullable=true) */
  69.     private $yahoo_id;
  70.     /** @ORM\Column(name="yahoo_access_token", type="string", length=255, nullable=true) */
  71.     private $yahoo_access_token;
  72.    
  73.     private $roles = [];
  74.     /**
  75.      * @var string The hashed password
  76.      * @ORM\Column(type="string")
  77.      */
  78.     private $password;
  79.       /**
  80.      * @Assert\EqualTo( value="password",
  81.      * message = " Le mot de passe et le mot de passe de verification doivent etre les memes ")
  82.      */
  83.     public $confirm_password;
  84.     /**
  85.      * @ORM\Column(type="boolean")
  86.      */
  87.     private $isVerified false;
  88.       /**
  89.      * @ORM\OneToMany(targetEntity=Email::class, mappedBy="sender")
  90.      */
  91.     private $emails;
  92.   
  93.     
  94.    
  95.       /**
  96.      * @ORM\Column(name="avatarPath", type="string", length=255, nullable=true)
  97.      */
  98.     protected $avatarPath;
  99.    
  100.     /**
  101.      * @var string
  102.      *
  103.      * @ORM\Column(name="phoneNumber", type="string", length=255, nullable=false)
  104.      */
  105.     protected $phoneNumber;
  106.     /** @ORM\Column(name="gender", nullable=true, unique=false, length=10) 
  107.      * @Assert\Choice(
  108.      * choices = { 0, 1 },
  109.      * message = "précisez le sexe")
  110.      */
  111.     protected $gender;
  112.     /**
  113.      * @var \Date
  114.      *
  115.      * @ORM\Column(name="birthday", type="date", nullable=true)
  116.      */
  117.     protected $birthday;
  118.     /**
  119.      * @var string
  120.      *
  121.      * @ORM\Column(name="birthplace", type="string", length=255, nullable=true)
  122.      */
  123.     private $birthplace;
  124.     /**
  125.      * @var string
  126.      *
  127.      * @ORM\Column(name="nationality", type="string", length=255, nullable=true)
  128.      */
  129.     protected $nationality;
  130.     /**
  131.      * @var string
  132.      *
  133.      * @ORM\Column(name="location", type="string", length=255, nullable=true)
  134.      */
  135.     protected $location;
  136.     /** @ORM\Column(name="region", nullable=true, unique=false, length=10) 
  137.      * @Assert\Choice(
  138.      * choices = { "Adamaoua", "Centre" ,"Est", "Extrême-Nord" ,"Littoral", "Nord", "Nord-Ouest" ,"Ouest", "Sud", "Sud-Ouest"},
  139.      * message = "précisez votre region d'origine")
  140.      */
  141.     protected $region;
  142.       /**
  143.      * @var string
  144.      *
  145.      * @ORM\Column(name="department", type="string", length=255, nullable=true)
  146.      */
  147.     protected $department;
  148.     /** @ORM\Column(name="academicLevel", nullable=true, unique=false, length=10) 
  149.      * @Assert\Choice(
  150.      * choices = { "BAC", "LICENCE" ,"DIP1", "DIP2" ,"MASTER", "DOCTORAT"},
  151.      * message = "précisez le niveau académique")
  152.      */
  153.     protected $academicLevel;
  154.     /**
  155.      * @var string
  156.      *
  157.      * @ORM\Column(name="numCni", type="string", length=255, nullable=true, unique=false)
  158.      */
  159.     protected $numCni;
  160.   
  161.     /** @ORM\Column(name="status", nullable=true, unique=false, length=10) 
  162.      * @Assert\Choice(
  163.      * choices = {"ELEVE","ADMIN", "PROF", "FINANCE", "PRINCIPAL", "PREFET"},
  164.      * * message = "précisez votre statu dans ISBB")
  165.      */
  166.     protected $status;
  167.     /**
  168.      * @ORM\ManyToOne(targetEntity=Domain::class, inversedBy="teachers")
  169.      */
  170.     private $domain;
  171.     /**
  172.      * @ORM\OneToMany(targetEntity=ClassRoom::class, mappedBy="fullTeacher")
  173.      */
  174.     private $fullTeacherOf;
  175.     
  176.     /**
  177.      * @ORM\OneToMany(targetEntity=Attribution::class, mappedBy="teacher")
  178.      */
  179.     private $attributions;
  180.     /**
  181.      * @ORM\Column(type="string", length=255, nullable=true)
  182.      */
  183.     private $fullName;
  184.   
  185.    
  186.     public function getAvatar(int $size 50): ?string
  187.     {
  188.         return "https://www.gravatar.com/avatar/"md5(strtolower(trim($this->getEmail())))."/?s=".$size;
  189.     }
  190.     public function __construct()
  191.     {
  192.         
  193.         $this->emails = new ArrayCollection();
  194.         $this->fullTeacherOf = new ArrayCollection();
  195.         $this->attributions = new ArrayCollection();
  196.     }
  197.     public function getId(): ?int
  198.     {
  199.         return $this->id;
  200.     }
  201.     public function getAvatarPath(): ?string
  202.     {
  203.         return $this->avatarPath;
  204.     }
  205.     public function setAvatarPath(?string $imageName): self
  206.     {
  207.         $this->avatarPath $imageName;
  208.         return $this;
  209.     }
  210.    
  211.     public function __toString() {
  212.         $username = ( is_null($this->getFullName())) ? "" $this->getFullName();
  213.         return $username;
  214.     }
  215.     public function getEmail(): ?string
  216.     {
  217.         return $this->email;
  218.     }
  219.     public function setEmail(string $email): self
  220.     {
  221.         $this->email $email;
  222.         return $this;
  223.     }
  224.     /**
  225.      * A visual identifier that represents this user.
  226.      *
  227.      * @see UserInterface
  228.      */
  229.     public function getUsername(): string
  230.     {
  231.         return (string) $this->email;
  232.     }
  233.     /**
  234.      * @see UserInterface
  235.      */
  236.     public function getRoles(): array
  237.     {
  238.         $roles $this->roles;
  239.         // guarantee every user at least has ROLE_USER
  240.         $roles[] = 'ROLE_USER';
  241.         $roles[] = 'ROLE_ADMIN';
  242.         return array_unique($roles);
  243.     }
  244.     public function setRoles(array $roles): self
  245.     {
  246.         $this->roles $roles;
  247.         return $this;
  248.     }
  249.     /**
  250.      * @see UserInterface
  251.      */
  252.     public function getPassword(): string
  253.     {
  254.         return $this->password;
  255.     }
  256.     public function setPassword(string $password): self
  257.     {
  258.         $this->password $password;
  259.         return $this;
  260.     }
  261.     /**
  262.      * Returning a salt is only needed, if you are not using a modern
  263.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  264.      *
  265.      * @see UserInterface
  266.      */
  267.     public function getSalt(): ?string
  268.     {
  269.         return null;
  270.     }
  271.     /**
  272.      * @see UserInterface
  273.      */
  274.     public function eraseCredentials()
  275.     {
  276.         // If you store any temporary, sensitive data on the user, clear it here
  277.         // $this->plainPassword = null;
  278.     }
  279.     public function isVerified(): bool
  280.     {
  281.         return $this->isVerified;
  282.     }
  283.     public function toggleIsVerified(): self
  284.     {
  285.          $this->isVerified = !$this->isVerified;
  286.          return $this;
  287.     }
  288.     public function setIsVerified(bool $isVerified): self
  289.     {
  290.         $this->isVerified $isVerified;
  291.         return $this;
  292.     }
  293.     public function getPhoneNumber(): ?string
  294.     {
  295.         return $this->phoneNumber;
  296.     }
  297.     public function setPhoneNumber(string $phone): self
  298.     {
  299.         $this->phoneNumber $phone;
  300.         return $this;
  301.     }
  302.      /**
  303.      * Get firstName
  304.      *
  305.      * @return string
  306.      */
  307.     public function getStatus() {
  308.         return $this->status;
  309.     }
  310.     public function setStatus($email) {
  311.         if (!empty($email))
  312.             $this->status $email;
  313.         return $this;
  314.     }
  315.       /**
  316.      * Set birthplace
  317.      *
  318.      * @param string $birthplace
  319.      *
  320.      * @return User
  321.      */
  322.     public function setBirthplace($birthplace)
  323.     {
  324.         $this->birthplace $birthplace;
  325.         return $this;
  326.     }
  327.     /**
  328.      * Get birthplace
  329.      *
  330.      * @return string
  331.      */
  332.     public function getBirthplace()
  333.     {
  334.         return $this->birthplace;
  335.     }
  336.      /**
  337.      * Set birthday
  338.      *
  339.      * @param \DateTime $birthday
  340.      *
  341.      * @return User
  342.      */
  343.     public function setBirthday($birthday)
  344.     {
  345.         $this->birthday $birthday;
  346.         return $this;
  347.     }
  348.     /**
  349.      * Get birthday
  350.      *
  351.      * @return \DateTime
  352.      */
  353.     public function getBirthday()
  354.     {
  355.         return $this->birthday;
  356.     }
  357.      /**
  358.      * Set gender
  359.      *
  360.      * @param string $gender
  361.      *
  362.      * @return User
  363.      */
  364.     public function setGender($gender) {
  365.         $this->gender $gender;
  366.         return $this;
  367.     }
  368.     /**
  369.      * Get gender
  370.      *
  371.      * @return string
  372.      */
  373.     public function getGender() {
  374.         return $this->gender;
  375.     }
  376.      /**
  377.      * Set nationality
  378.      *
  379.      * @param string $nationality
  380.      *
  381.      * @return User
  382.      */
  383.     public function setNationality($nationality) {
  384.         $this->nationality $nationality;
  385.         return $this;
  386.     }
  387.     /**
  388.      * Get nationality
  389.      *
  390.      * @return string
  391.      */
  392.     public function getNationality() {
  393.         return $this->nationality;
  394.     }
  395.     /**
  396.      * Set location
  397.      *
  398.      * @param string $location
  399.      *
  400.      * @return User
  401.      */
  402.     public function setLocation($location) {
  403.         $this->location $location;
  404.         return $this;
  405.     }
  406.     /**
  407.      * Get location
  408.      *
  409.      * @return string
  410.      */
  411.     public function getLocation() {
  412.         return $this->location;
  413.     }
  414.     /**
  415.      * Set academicLevel
  416.      *
  417.      * @param string $academicLevel
  418.      *
  419.      * @return User
  420.      */
  421.     public function setAcademicLevel($academicLevel) {
  422.         $this->academicLevel $academicLevel;
  423.         return $this;
  424.     }
  425.     /**
  426.      * Get academicLevel
  427.      *
  428.      * @return string
  429.      */
  430.     public function getAcademicLevel() {
  431.         return $this->academicLevel;
  432.     }
  433.     /**
  434.      * Set numCni
  435.      *
  436.      * @param string $numCni
  437.      *
  438.      * @return User
  439.      */
  440.     public function setNumCni($numCni) {
  441.         $this->numCni $numCni;
  442.         return $this;
  443.     }
  444.     /**
  445.      * Get numCni
  446.      *
  447.      * @return string
  448.      */
  449.     public function getNumCni() {
  450.         return $this->numCni;
  451.     }
  452.      /**
  453.      * Set domain
  454.      *
  455.      * @param \App\Entity\Domain $domain
  456.      *
  457.      * @return User
  458.      */
  459.     public function setDomain(Domain $domain null) {
  460.         $this->domain $domain;
  461.         return $this;
  462.     }
  463.     /**
  464.      * Get domain
  465.      *
  466.      * @return \App\Entity\Domain
  467.      */
  468.     public function getDomain() {
  469.         return $this->domain;
  470.     }
  471.     /**
  472.      * @return Collection|ClassRoom[]
  473.      */
  474.     public function getFullTeacherOf(): Collection
  475.     {
  476.         return $this->fullTeacherOf;
  477.     }
  478.     public function addFullTeacherOf(ClassRoom $fullTeacherOf): self
  479.     {
  480.         if (!$this->fullTeacherOf->contains($fullTeacherOf)) {
  481.             $this->fullTeacherOf[] = $fullTeacherOf;
  482.             $fullTeacherOf->setFullTeacher($this);
  483.         }
  484.         return $this;
  485.     }
  486.     public function removeFullTeacherOf(ClassRoom $fullTeacherOf): self
  487.     {
  488.         if ($this->fullTeacherOf->removeElement($fullTeacherOf)) {
  489.             // set the owning side to null (unless already changed)
  490.             if ($fullTeacherOf->getFullTeacher() === $this) {
  491.                 $fullTeacherOf->setFullTeacher(null);
  492.             }
  493.         }
  494.         return $this;
  495.     }
  496.     public function getUsernameCanonical(): ?string
  497.     {
  498.         return $this->username_canonical;
  499.     }
  500.     public function setUsernameCanonical(string $username_canonical): self
  501.     {
  502.         $this->username_canonical $username_canonical;
  503.         return $this;
  504.     }
  505.     public function getEmailCanonical(): ?string
  506.     {
  507.         return $this->email_canonical;
  508.     }
  509.     public function setEmailCanonical(string $email_canonical): self
  510.     {
  511.         $this->email_canonical $email_canonical;
  512.         return $this;
  513.     }
  514.     public function getEnabled(): ?bool
  515.     {
  516.         return $this->enabled;
  517.     }
  518.     public function setEnabled(bool $enabled): self
  519.     {
  520.         $this->enabled $enabled;
  521.         return $this;
  522.     }
  523.     public function setSalt(?string $salt): self
  524.     {
  525.         $this->salt $salt;
  526.         return $this;
  527.     }
  528.     public function getLastLogin(): ?\DateTimeInterface
  529.     {
  530.         return $this->last_login;
  531.     }
  532.     public function setLastLogin(?\DateTimeInterface $last_login): self
  533.     {
  534.         $this->last_login $last_login;
  535.         return $this;
  536.     }
  537.     public function getConfirmationToken(): ?string
  538.     {
  539.         return $this->confirmation_token;
  540.     }
  541.     public function setConfirmationToken(?string $confirmation_token): self
  542.     {
  543.         $this->confirmation_token $confirmation_token;
  544.         return $this;
  545.     }
  546.     public function getPasswordRequestedAt(): ?\DateTimeImmutable
  547.     {
  548.         return $this->password_requested_at;
  549.     }
  550.     public function setPasswordRequestedAt(?\DateTimeImmutable $password_requested_at): self
  551.     {
  552.         $this->password_requested_at $password_requested_at;
  553.         return $this;
  554.     }
  555.     public function getFullName(): ?string
  556.     {
  557.         return $this->fullName;
  558.     }
  559.     public function setFullName(?string $fullName): self
  560.     {
  561.         $this->fullName $fullName;
  562.         return $this;
  563.     }
  564.     public function getGithubId(): ?string
  565.     {
  566.         return $this->github_id;
  567.     }
  568.     public function setGithubId(?string $github_id): self
  569.     {
  570.         $this->github_id $github_id;
  571.         return $this;
  572.     }
  573.     public function getGithubAccessToken(): ?string
  574.     {
  575.         return $this->github_access_token;
  576.     }
  577.     public function setGithubAccessToken(?string $github_access_token): self
  578.     {
  579.         $this->github_access_token $github_access_token;
  580.         return $this;
  581.     }
  582.     public function getFacebookId(): ?string
  583.     {
  584.         return $this->facebook_id;
  585.     }
  586.     public function setFacebookId(?string $facebook_id): self
  587.     {
  588.         $this->facebook_id $facebook_id;
  589.         return $this;
  590.     }
  591.     public function getFacebookAccessToken(): ?string
  592.     {
  593.         return $this->facebook_access_token;
  594.     }
  595.     public function setFacebookAccessToken(?string $facebook_access_token): self
  596.     {
  597.         $this->facebook_access_token $facebook_access_token;
  598.         return $this;
  599.     }
  600.     public function getGoogleId(): ?string
  601.     {
  602.         return $this->google_id;
  603.     }
  604.     public function setGoogleId(?string $google_id): self
  605.     {
  606.         $this->google_id $google_id;
  607.         return $this;
  608.     }
  609.     public function getGoogleAccessToken(): ?string
  610.     {
  611.         return $this->google_access_token;
  612.     }
  613.     public function setGoogleAccessToken(?string $google_access_token): self
  614.     {
  615.         $this->google_access_token $google_access_token;
  616.         return $this;
  617.     }
  618.     public function getLinkedinId(): ?string
  619.     {
  620.         return $this->linkedin_id;
  621.     }
  622.     public function setLinkedinId(?string $linkedin_id): self
  623.     {
  624.         $this->linkedin_id $linkedin_id;
  625.         return $this;
  626.     }
  627.     public function getLinkedinAccessToken(): ?string
  628.     {
  629.         return $this->linkedin_access_token;
  630.     }
  631.     public function setLinkedinAccessToken(?string $linkedin_access_token): self
  632.     {
  633.         $this->linkedin_access_token $linkedin_access_token;
  634.         return $this;
  635.     }
  636.     public function getTwitterId(): ?string
  637.     {
  638.         return $this->twitter_id;
  639.     }
  640.     public function setTwitterId(?string $twitter_id): self
  641.     {
  642.         $this->twitter_id $twitter_id;
  643.         return $this;
  644.     }
  645.     public function getTwitterAccessToken(): ?string
  646.     {
  647.         return $this->twitter_access_token;
  648.     }
  649.     public function setTwitterAccessToken(?string $twitter_access_token): self
  650.     {
  651.         $this->twitter_access_token $twitter_access_token;
  652.         return $this;
  653.     }
  654.     public function getYahooId(): ?string
  655.     {
  656.         return $this->yahoo_id;
  657.     }
  658.     public function setYahooId(?string $yahoo_id): self
  659.     {
  660.         $this->yahoo_id $yahoo_id;
  661.         return $this;
  662.     }
  663.     public function getYahooAccessToken(): ?string
  664.     {
  665.         return $this->yahoo_access_token;
  666.     }
  667.     public function setYahooAccessToken(?string $yahoo_access_token): self
  668.     {
  669.         $this->yahoo_access_token $yahoo_access_token;
  670.         return $this;
  671.     }
  672.     public function getIsVerified(): ?bool
  673.     {
  674.         return $this->isVerified;
  675.     }
  676.     /**
  677.      * @return Collection|Email[]
  678.      */
  679.     public function getEmails(): Collection
  680.     {
  681.         return $this->emails;
  682.     }
  683.     public function addEmail(Email $email): self
  684.     {
  685.         if (!$this->emails->contains($email)) {
  686.             $this->emails[] = $email;
  687.             $email->setSender($this);
  688.         }
  689.         return $this;
  690.     }
  691.     public function removeEmail(Email $email): self
  692.     {
  693.         if ($this->emails->removeElement($email)) {
  694.             // set the owning side to null (unless already changed)
  695.             if ($email->getSender() === $this) {
  696.                 $email->setSender(null);
  697.             }
  698.         }
  699.         return $this;
  700.     }
  701.     /**
  702.      * @return Collection|Attribution[]
  703.      */
  704.     public function getAttributions(): Collection
  705.     {
  706.         return $this->attributions;
  707.     }
  708.     /**
  709.      * list of courses assigned to a teacher during a given year
  710.      */
  711.     public function getCourses(SchoolYear $year)
  712.     {
  713.         $courses = [];
  714.         foreach($this->attributions as $attribution){
  715.             if($attribution->getSchoolYear()==$year){
  716.                 $courses[] = $attribution->getCourse();
  717.             }
  718.         }
  719.         return $courses;
  720.     }
  721.     public function addAttribution(Attribution $attribution): self
  722.     {
  723.         if (!$this->attributions->contains($attribution)) {
  724.             $this->attributions[] = $attribution;
  725.             $attribution->setTeacher($this);
  726.         }
  727.         return $this;
  728.     }
  729.     public function removeAttribution(Attribution $attribution): self
  730.     {
  731.         if ($this->attributions->removeElement($attribution)) {
  732.             // set the owning side to null (unless already changed)
  733.             if ($attribution->getTeacher() === $this) {
  734.                  
  735.             }
  736.         }
  737.         return $this;
  738.     }
  739.     public function getUserIdentifier() {
  740.       return $this->getEmail();
  741.     }
  742.     public function isIsVerified(): ?bool
  743.     {
  744.         return $this->isVerified;
  745.     }
  746.  
  747.     public function getDepartment(): ?string
  748.     {
  749.         return $this->department;
  750.     }
  751.     public function setDepartment(?string $department): static
  752.     {
  753.         $this->department $department;
  754.         return $this;
  755.     }
  756.     public function getRegion(): ?string
  757.     {
  758.         return $this->region;
  759.     }
  760.     public function setRegion(?string $region): static
  761.     {
  762.         $this->region $region;
  763.         return $this;
  764.     }
  765.   
  766. }