src/Entity/User.php line 232

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