src/Entity/QuizResult.php line 87

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use ApiPlatform\Metadata\ApiProperty;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Get;
  9. use ApiPlatform\Metadata\Post;
  10. use ApiPlatform\Metadata\Put;
  11. use App\Controller\Api\Controller\Course\Quiz\PostController;
  12. use App\Repository\QuizResultRepository;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use ApiPlatform\OpenApi\Model\Operation;
  17. use ApiPlatform\OpenApi\Model\RequestBody;
  18. use App\Controller\Api\Controller\Course\Chapter\ShowQuizzesResultList;
  19. #[ORM\Entity(repositoryClassQuizResultRepository::class)]
  20. #[UniqueEntity(fields: ['quiz''eleve'], message'This item exist')]
  21. #[ApiResource(
  22.     normalizationContext: ['groups' => ['read:quizresult:collection']],
  23.     denormalizationContext: ['groups' => ['post:quizresult:item']],
  24.     paginationClientItemsPerPagetrue,
  25.     paginationItemsPerPage20,
  26.     paginationMaximumItemsPerPage20,
  27.     operations: [
  28.         new GetCollection(),
  29.         new GetCollection(
  30.             controllerShowQuizzesResultList::class,
  31.             uriTemplate'/chapitre/{id}/results',
  32.             openapiContext: [
  33.                 'security' => [['bearerAuth' => []]]
  34.             ],
  35.         ),
  36.         new Get(),
  37.         new Post(
  38.             normalizationContext: ['groups' => ['post:item']],
  39.             controllerPostController::class,
  40.             uriTemplate'/chapitre/{id}/submit/quizzes-form',
  41.             openapiContext: [
  42.                 'security' => [['bearerAuth' => []]]
  43.             ],
  44.             openapi: new Operation(
  45.                 requestBody: new RequestBody(
  46.                     content: new \ArrayObject([
  47.                         'application/json' => [
  48.                             'schema' => [
  49.                                 'type' => 'object',
  50.                                 'properties' => [
  51.                                     'quizzes' => [
  52.                                         'type' => [],
  53.                                     ],
  54.                                     'submit' => [
  55.                                         'type' => 'string',
  56.                                     ],
  57.                                     'cours_id' => [
  58.                                         'type' => 'integer',
  59.                                     ],
  60.                                     'chapitre_slug' => [
  61.                                         'type' => 'string',
  62.                                     ],
  63.                                 ]
  64.                             ]
  65.                         ]
  66.                     ])
  67.                 )
  68.             ),
  69.             deserializefalse
  70.         ),
  71.         new Put(
  72.             denormalizationContext: ['groups' => ['put:quizresult:item']],
  73.             openapiContext: [
  74.                 'security' => [['bearerAuth' => []]]
  75.             ]
  76.         )
  77.     ]
  78. )]
  79. #[ApiFilter(SearchFilter::class, properties: [
  80.     'eleve' => 'exact',
  81.     'quiz.cours' => 'exact',
  82.     'quiz.chapitre' => 'exact',
  83. ])]
  84. class QuizResult
  85. {
  86.     #[ORM\Id]
  87.     #[ORM\GeneratedValue]
  88.     #[ORM\Column]
  89.     #[Groups(['read:quizresult:collection''post:item'])]
  90.     #[ApiProperty(iris"https://schema.org/identifier"identifiertrue)]
  91.     private ?int $id null;
  92.     #[ORM\ManyToOne(inversedBy'quizResults')]
  93.     #[ORM\JoinColumn(nullablefalse)]
  94.     #[Groups(['read:quizresult:collection''post:quizresult:item'])]
  95.     private ?Quiz $quiz null;
  96.     #[ORM\ManyToOne(inversedBy'quizResults')]
  97.     #[ORM\JoinColumn(nullablefalse)]
  98.     #[Groups(['read:quizresult:collection'])]
  99.     private ?Eleve $eleve null;
  100.     #[ORM\Column(nullabletrue)]
  101.     #[Groups(['read:quizresult:collection''post:quizresult:item''put:quizresult:item'])]
  102.     private array $result = [];
  103.     #[ORM\Column]
  104.     #[Groups(['read:quizresult:collection'])]
  105.     private ?\DateTimeImmutable $createdAt null;
  106.     #[ORM\Column]
  107.     #[Groups(['read:quizresult:collection''post:quizresult:item'])]
  108.     private ?bool $isCorrect null;
  109.     #[ORM\Column]
  110.     #[Groups(['read:quizresult:collection''post:quizresult:item''put:quizresult:item'])]
  111.     private ?float $note null;
  112.     #[ORM\Column]
  113.     #[Groups(['read:quizresult:collection''put:quizresult:item'])]
  114.     private ?\DateTimeImmutable $updatedAt null;
  115.     public function __construct()
  116.     {
  117.         $this->createdAt = new \DateTimeImmutable();
  118.         $this->updatedAt = new \DateTimeImmutable();
  119.     }
  120.     public function getId(): ?int
  121.     {
  122.         return $this->id;
  123.     }
  124.     public function getQuiz(): ?Quiz
  125.     {
  126.         return $this->quiz;
  127.     }
  128.     public function setQuiz(?Quiz $quiz): self
  129.     {
  130.         $this->quiz $quiz;
  131.         return $this;
  132.     }
  133.     public function getEleve(): ?Eleve
  134.     {
  135.         return $this->eleve;
  136.     }
  137.     public function setEleve(?Eleve $eleve): self
  138.     {
  139.         $this->eleve $eleve;
  140.         return $this;
  141.     }
  142.     public function getResult(): array
  143.     {
  144.         return $this->result;
  145.     }
  146.     public function setResult(?array $result): self
  147.     {
  148.         $this->result $result;
  149.         return $this;
  150.     }
  151.     public function getCreatedAt(): ?\DateTimeImmutable
  152.     {
  153.         return $this->createdAt;
  154.     }
  155.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  156.     {
  157.         $this->createdAt $createdAt;
  158.         return $this;
  159.     }
  160.     public function isIsCorrect(): ?bool
  161.     {
  162.         return $this->isCorrect;
  163.     }
  164.     public function setIsCorrect(bool $isCorrect): self
  165.     {
  166.         $this->isCorrect $isCorrect;
  167.         return $this;
  168.     }
  169.     public function getNote(): ?float
  170.     {
  171.         return $this->note;
  172.     }
  173.     public function setNote(float $note): self
  174.     {
  175.         $this->note $note;
  176.         return $this;
  177.     }
  178.     public function getUpdatedAt(): ?\DateTimeImmutable
  179.     {
  180.         return $this->updatedAt;
  181.     }
  182.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  183.     {
  184.         $this->updatedAt $updatedAt;
  185.         return $this;
  186.     }
  187. }