src/Entity/Personne.php line 90

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use ApiPlatform\Metadata\Post;
  7. use ApiPlatform\OpenApi\Model\Operation;
  8. use ApiPlatform\OpenApi\Model\RequestBody;
  9. use App\Controller\Api\Controller\User\ChangeAvatarController;
  10. use App\Controller\Api\Controller\User\NetworkController;
  11. use App\Repository\PersonneRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\DBAL\Types\Types;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Serializer\Annotation\Ignore;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. #[ORM\Entity(repositoryClassPersonneRepository::class)]
  20. #[ApiResource(
  21.     types: ['https://schema.org/MediaObject'],
  22.     operations: [
  23.         new Post(
  24.             uriTemplate'/post/{id}/avatar',
  25.             controllerChangeAvatarController::class,
  26.             openapiContext: [
  27.                 'security' => [['bearerAuth' => []]],
  28.                 'responses' => [
  29.                     '200' => [
  30.                         'description' => 'Avatar updated successfully',
  31.                         'content' => [
  32.                             'application/json' => [
  33.                                 'schema' => [
  34.                                     'type' => 'object',
  35.                                     'properties' => [
  36.                                         'success' => ['type' => 'boolean'],
  37.                                         'data' => [
  38.                                             'type' => 'object',
  39.                                             'properties' => [
  40.                                                 'id' => ['type' => 'integer'],
  41.                                                 'avatar' => ['type' => 'string'],
  42.                                                 'avatarUrl' => ['type' => 'string'],
  43.                                                 'message' => ['type' => 'string']
  44.                                             ]
  45.                                         ]
  46.                                     ]
  47.                                 ]
  48.                             ]
  49.                         ]
  50.                     ]
  51.                 ]
  52.             ],
  53.             openapi: new Operation(
  54.                 requestBody: new RequestBody(
  55.                     content: new \ArrayObject([
  56.                         'multipart/form-data' => [
  57.                             'schema' => [
  58.                                 'type' => 'object',
  59.                                 'properties' => [
  60.                                     'file' => [
  61.                                         'type' => 'string',
  62.                                         'format' => 'binary'
  63.                                     ]
  64.                                 ]
  65.                             ]
  66.                         ]
  67.                     ])
  68.                 )
  69.             ),
  70.             deserializefalse,
  71.             validatefalse,
  72.             writefalse
  73.         ),
  74.         new GetCollection(
  75.             uriTemplate'/personne/{id}/network',
  76.             controllerNetworkController::class,
  77.             openapiContext: [
  78.                 'security' => [['bearerAuth' => []]]
  79.             ],
  80.             readfalse,
  81.         ),
  82.     ],
  83.     normalizationContext: [
  84.         'groups' => ['read:personne:item']
  85.     ],
  86. )]
  87. class Personne
  88. {
  89.     #[ORM\Id]
  90.     #[ORM\GeneratedValue]
  91.     #[ORM\Column]
  92.     #[Groups(['read:course:collection''read:forum:item''read:forum:messsage:collection''read:sujet:item''read:sujet:collection''read:review:collection''read:exam:collection''read:payment:collection','read:personne:item''read:quizresult:collection'])]
  93.     private ?int $id null;
  94.     #[ORM\Column(length255)]
  95.     #[Assert\NotBlank(message"Ne peut Ãªtre vide !")]
  96.     #[Assert\NotNull(message"Ne peut Ãªtre nul !")]
  97.     #[Assert\Length(min2minMessage"Le nom doit faire au moins 2 caractères !")]
  98.     #[Groups(['read:course:collection''read:forum:item''read:forum:messsage:collection''read:sujet:item''read:sujet:collection''read:review:collection''read:exam:collection''post:user:item','read:payment:collection','read:personne:item''read:quizresult:collection'])]
  99.     private ?string $lastName null;
  100.     #[ORM\Column(length255nullabletrue)]
  101.     #[Groups(['read:course:collection''read:forum:item''read:forum:messsage:collection''read:sujet:item''read:sujet:collection''read:review:collection','read:exam:collection''post:user:item','read:payment:collection','read:personne:item''read:quizresult:collection'])]
  102.     private ?string $firstName null;
  103.     #[ORM\Column(length255)]
  104.     #[Assert\NotBlank(message"Ne peut Ãªtre vide !")]
  105.     #[Assert\NotNull(message"Ne peut Ãªtre nul !")]
  106.     #[Assert\Length(min5max8minMessage"Il faut 5 caractères minimum !"maxMessage"Il faut 8 caractères maximun")]
  107.     #[Groups(['read:course:collection''read:forum:messsage:collection''read:sujet:item''read:sujet:collection''read:review:collection','read:exam:collection','post:user:item''read:personne:item'])]
  108.     private ?string $pseudo null;
  109.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  110.     #[Groups(['post:user:item''read:personne:item'])]
  111.     private ?\DateTimeInterface $bornAt null;
  112.     #[ORM\Column(length255nullabletrue)]
  113.     #[Groups(['post:user:item''read:personne:item'])]
  114.     private ?string $lieuNaissance null;
  115.     #[ORM\Column(length100nullabletrue)]
  116.     #[Groups(['read:course:item''read:forum:messsage:collection''read:sujet:item''read:sujet:collection''read:review:collection''read:exam:collection','post:user:item''read:personne:item'])]
  117.     private ?string $sexe null;
  118.     #[ORM\Column(length255nullabletrue)]
  119.     #[Groups(['read:course:collection''read:forum:item''read:forum:messsage:collection''read:sujet:item''read:sujet:collection''read:review:collection''read:exam:collection''read:payment:collection''read:personne:item'])]
  120.     private ?string $avatar null;
  121.     #[ORM\Column(length255nullabletrue)]
  122.     #[Groups(['post:user:item''read:personne:item'])]
  123.     private ?string $adresse null;
  124.     #[ORM\Column(length255nullabletrue)]
  125.     #[Groups(['read:course:collection''read:forum:item''read:forum:messsage:collection''read:sujet:item''read:sujet:collection''read:review:collection''read:exam:collection''post:user:item''read:payment:collection''read:personne:item'])]
  126.     private ?string $telephone null;
  127.     #[ORM\OneToOne(mappedBy"personne"cascade: ['persist''remove'])]
  128.     #[ORM\JoinColumn(nullablefalse)]
  129.     private ?User $utilisateur null;
  130.     #[ORM\Column(length255uniquetrue)]
  131.     #[Groups(['read:personne:item'])]
  132.     private ?string $invitationCode null;
  133.     #[ORM\Column(typeTypes::TEXT)]
  134.     #[Groups(['read:personne:item'])]
  135.     private ?string $invitationLink null;
  136.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'invites')]
  137.     private ?self $parent null;
  138.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  139.     private Collection $invites;
  140.     #[ORM\ManyToOne(inversedBy'personnes')]
  141.     #[Groups(['read:course:item''post:user:item'])]
  142.     private ?Pays $pays null;
  143.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  144.     #[Groups(['read:course:item''read:course:collection''read:review:collection''read:personne:item'])]
  145.     private ?string $contentUrl null;
  146.     #[ORM\Column(nullabletrue)]
  147.     private ?\DateTimeImmutable $joinAt null;
  148.     #[ORM\Column(nullabletrue)]
  149.     private ?\DateTimeImmutable $updateAt null;
  150.     public function __construct()
  151.     {
  152.         $this->invites = new ArrayCollection();
  153.         $this->joinAt = new \DateTimeImmutable();
  154.     }
  155.     public function getId(): ?int
  156.     {
  157.         return $this->id;
  158.     }
  159.     public function getLastName(): ?string
  160.     {
  161.         return $this->lastName;
  162.     }
  163.     public function setLastName(?string $lastName): self
  164.     {
  165.         $this->lastName $lastName;
  166.         return $this;
  167.     }
  168.     public function getFirstName(): ?string
  169.     {
  170.         return $this->firstName;
  171.     }
  172.     public function setFirstName(?string $firstName): self
  173.     {
  174.         $this->firstName $firstName;
  175.         return $this;
  176.     }
  177.     public function getPseudo(): ?string
  178.     {
  179.         return $this->pseudo;
  180.     }
  181.     public function setPseudo(string $pseudo): self
  182.     {
  183.         $this->pseudo $pseudo;
  184.         return $this;
  185.     }
  186.     public function getBornAt(): ?\DateTimeInterface
  187.     {
  188.         return $this->bornAt;
  189.     }
  190.     public function setBornAt(?\DateTimeInterface $bornAt): self
  191.     {
  192.         $this->bornAt $bornAt;
  193.         return $this;
  194.     }
  195.     public function getLieuNaissance(): ?string
  196.     {
  197.         return $this->lieuNaissance;
  198.     }
  199.     public function setLieuNaissance(?string $lieuNaissance): self
  200.     {
  201.         $this->lieuNaissance $lieuNaissance;
  202.         return $this;
  203.     }
  204.     public function getSexe(): ?string
  205.     {
  206.         return $this->sexe;
  207.     }
  208.     public function setSexe(?string $sexe): self
  209.     {
  210.         $this->sexe $sexe;
  211.         return $this;
  212.     }
  213.     public function getAvatar(): ?string
  214.     {
  215.         return $this->avatar;
  216.     }
  217.     public function setAvatar(?string $avatar): self
  218.     {
  219.         $this->avatar $avatar;
  220.         return $this;
  221.     }
  222.     public function getAdresse(): ?string
  223.     {
  224.         return $this->adresse;
  225.     }
  226.     public function setAdresse(?string $adresse): self
  227.     {
  228.         $this->adresse $adresse;
  229.         return $this;
  230.     }
  231.     public function getTelephone(): ?string
  232.     {
  233.         return $this->telephone;
  234.     }
  235.     public function setTelephone(?string $telephone): self
  236.     {
  237.         $this->telephone $telephone;
  238.         return $this;
  239.     }
  240.     public function getUtilisateur(): ?User
  241.     {
  242.         return $this->utilisateur;
  243.     }
  244.     public function setUtilisateur(User $utilisateur): self
  245.     {
  246.         $this->utilisateur $utilisateur;
  247.         return $this;
  248.     }
  249.     public function getInvitationCode(): ?string
  250.     {
  251.         return $this->invitationCode;
  252.     }
  253.     public function setInvitationCode(string $invitationCode): self
  254.     {
  255.         $this->invitationCode $invitationCode;
  256.         return $this;
  257.     }
  258.     public function getInvitationLink()
  259.     {
  260.         return json_decode($this->invitationLink);
  261.     }
  262.     public function setInvitationLink(string $invitationLink): self
  263.     {
  264.         $this->invitationLink $invitationLink;
  265.         return $this;
  266.     }
  267.     public function getParent(): ?self
  268.     {
  269.         return $this->parent;
  270.     }
  271.     public function setParent(?self $parent): self
  272.     {
  273.         $this->parent $parent;
  274.         return $this;
  275.     }
  276.     /**
  277.      * @return Collection<int, self>
  278.      */
  279.     public function getInvites(): Collection
  280.     {
  281.         return $this->invites;
  282.     }
  283.     public function addInvite(self $invite): self
  284.     {
  285.         if (!$this->invites->contains($invite)) {
  286.             $this->invites->add($invite);
  287.             $invite->setParent($this);
  288.         }
  289.         return $this;
  290.     }
  291.     public function removeInvite(self $invite): self
  292.     {
  293.         if ($this->invites->removeElement($invite)) {
  294.             // set the owning side to null (unless already changed)
  295.             if ($invite->getParent() === $this) {
  296.                 $invite->setParent(null);
  297.             }
  298.         }
  299.         return $this;
  300.     }
  301.     public function getPays(): ?Pays
  302.     {
  303.         return $this->pays;
  304.     }
  305.     public function setPays(?Pays $pays): self
  306.     {
  307.         $this->pays $pays;
  308.         return $this;
  309.     }
  310.     public function getName(): ?string
  311.     {
  312.         return $this->firstName ' ' $this->lastName;
  313.     }
  314.     public function getNomComplet(): ? string
  315.     {
  316.         if ($this->getLastName() === null) {
  317.             return $this->getFirstName();
  318.         }
  319.         return $this->getFirstName() .' '$this->getLastName();
  320.     }
  321.     public function getAvatarPath(): string
  322.     {
  323.         if (!$this->getUtilisateur()) {
  324.             return "assets/images/avatar/avatar.png";
  325.         }
  326.         $avatarPath 'uploads/images/admin/' $this->getAvatar();
  327.         if ($this->getUtilisateur()->getEleve() !== null) {
  328.             $avatarPath 'uploads/images/eleves/' $this->getAvatar();
  329.         } elseif ($this->getUtilisateur()->getEnseignant() !== null) {
  330.             $avatarPath 'uploads/images/enseignants/kyc/' $this->getAvatar();
  331.         }
  332.         if (!$this->getAvatar()) {
  333.             $avatarPath "assets/images/avatar/avatar.png";
  334.         }
  335.         return $avatarPath;
  336.     }
  337.     public function getJoinAt(): ?\DateTimeImmutable
  338.     {
  339.         return $this->joinAt;
  340.     }
  341.     public function setJoinAt(?\DateTimeImmutable $joinAt): self
  342.     {
  343.         $this->joinAt $joinAt;
  344.         return $this;
  345.     }
  346.     public function getUpdateAt(): ?\DateTimeImmutable
  347.     {
  348.         return $this->updateAt;
  349.     }
  350.     public function setUpdateAt(?\DateTimeImmutable $updateAt): self
  351.     {
  352.         $this->updateAt $updateAt;
  353.         return $this;
  354.     }
  355.     public function setContentUrl(?string $contentUrl): self
  356.     {
  357.         $this->contentUrl $contentUrl;
  358.         return $this;
  359.     }
  360.     public function getContentUrl(): ?string
  361.     {
  362.         return $this->contentUrl;
  363.     }
  364. }