src/Entity/User.php line 228

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