diff --git a/src/plugin/cursus/Controller/EventPresenceController.php b/src/plugin/cursus/Controller/EventPresenceController.php index db1cf74d84..c4ef612bae 100644 --- a/src/plugin/cursus/Controller/EventPresenceController.php +++ b/src/plugin/cursus/Controller/EventPresenceController.php @@ -93,8 +93,8 @@ public function signStatusAction(Request $request): JsonResponse $presence->setStatus(EventPresence::PRESENT); $presence->setSignature($signature); - $presence->setPresenceUpdatedBy($this->tokenStorage->getToken()->getUser()); - $presence->setPresenceUpdatedAt(new \DateTime()); + $presence->setUpdatedBy($this->tokenStorage->getToken()->getUser()); + $presence->setUpdatedAt(new \DateTime()); $this->om->persist($presence); $this->om->flush(); @@ -217,8 +217,8 @@ public function updateStatusAction(string $status, Request $request): JsonRespon $this->manager->setStatus([$presence], $status); - $presence->setPresenceUpdatedBy($this->tokenStorage->getToken()->getUser()); - $presence->setPresenceUpdatedAt(new \DateTime()); + $presence->setUpdatedBy($this->tokenStorage->getToken()->getUser()); + $presence->setUpdatedAt(new \DateTime()); } $this->om->endFlushSuite(); @@ -267,20 +267,20 @@ public function downloadUserPdfAction(EventPresence $eventPresence, Request $req } /** - * @Route("/{id}/evidences", name="apiv2_cursus_presence_evidence_upload", methods={"POST"}) + * @Route("/{id}/evidence", name="apiv2_cursus_presence_evidence_upload", methods={"POST"}) * * @EXT\ParamConverter("eventPresence", class="Claroline\CursusBundle\Entity\EventPresence", options={"mapping": {"id": "uuid"}}) */ - public function uploadEvidences(EventPresence $eventPresence, Request $request): JsonResponse + public function uploadEvidence(EventPresence $eventPresence, Request $request): JsonResponse { $this->checkPermission('EDIT', $eventPresence, [], true); $files = $request->files->all(); - $evidences = []; + $evidence = []; foreach ($files as $index => $file) { $evidenceFile = $this->manager->uploadEvidence($file, $eventPresence); - $evidences[] = [ + $evidence[] = [ 'type' => $evidenceFile->getMimeType(), 'mimeType' => $evidenceFile->getMimeType(), 'name' => $evidenceFile->getFilename(), @@ -290,7 +290,7 @@ public function uploadEvidences(EventPresence $eventPresence, Request $request): ]; } - $eventPresence->setEvidences($evidences); + $eventPresence->setEvidence($evidence); $eventPresence->setEvidenceAddedBy($this->tokenStorage->getToken()->getUser()); $eventPresence->setEvidenceAddedAt(new \DateTime()); @@ -301,7 +301,7 @@ public function uploadEvidences(EventPresence $eventPresence, Request $request): } /** - * @Route("/{id}/evidences", name="apiv2_cursus_presence_evidence_delete", methods={"DELETE"}) + * @Route("/{id}/evidence", name="apiv2_cursus_presence_evidence_delete", methods={"DELETE"}) * * @EXT\ParamConverter("eventPresence", class="Claroline\CursusBundle\Entity\EventPresence", options={"mapping": {"id": "uuid"}}) */ @@ -309,7 +309,7 @@ public function deleteEvidenceAction(EventPresence $eventPresence): JsonResponse { $this->checkPermission('EDIT', $eventPresence, [], true); - $eventPresence->setEvidences(null); + $eventPresence->setEvidence(null); $this->om->persist($eventPresence); $this->om->flush(); @@ -318,7 +318,7 @@ public function deleteEvidenceAction(EventPresence $eventPresence): JsonResponse } /** - * @Route("/{id}/evidences", name="apiv2_cursus_presence_evidence_download", methods={"GET"}) + * @Route("/{id}/evidence", name="apiv2_cursus_presence_evidence_download", methods={"GET"}) * * @EXT\ParamConverter("eventPresence", class="Claroline\CursusBundle\Entity\EventPresence", options={"mapping": {"id": "uuid"}}) */ diff --git a/src/plugin/cursus/Entity/EventPresence.php b/src/plugin/cursus/Entity/EventPresence.php index b86eb0b879..9f4b9a07bb 100644 --- a/src/plugin/cursus/Entity/EventPresence.php +++ b/src/plugin/cursus/Entity/EventPresence.php @@ -4,6 +4,7 @@ use Claroline\AppBundle\Entity\Identifier\Id; use Claroline\AppBundle\Entity\Identifier\Uuid; +use Claroline\AppBundle\Entity\Meta\UpdatedAt; use Claroline\CoreBundle\Entity\User; use Doctrine\ORM\Mapping as ORM; @@ -16,6 +17,7 @@ class EventPresence { use Id; use Uuid; + use UpdatedAt; public const UNKNOWN = 'unknown'; public const PRESENT = 'present'; @@ -60,19 +62,14 @@ class EventPresence /** * @ORM\Column(type="json", nullable=true) */ - private ?array $evidences = null; + private ?array $evidence = null; /** * @ORM\ManyToOne(targetEntity="Claroline\CoreBundle\Entity\User") * - * @ORM\JoinColumn(name="presence_updated_by", referencedColumnName="id", nullable=true) + * @ORM\JoinColumn(name="updatedBy", referencedColumnName="id", nullable=true) */ - private ?User $presenceUpdatedBy = null; - - /** - * @ORM\Column(name="presence_updated_at", type="datetime", nullable=true) - */ - private ?\DateTimeInterface $presenceUpdatedAt = null; + private ?User $updatedBy = null; /** * @ORM\ManyToOne(targetEntity="Claroline\CoreBundle\Entity\User") @@ -141,36 +138,24 @@ public function setValidationDate(?\DateTimeInterface $validationDate): void $this->validationDate = $validationDate; } - public function getEvidences(): ?array - { - return $this->evidences; - } - - public function setEvidences(?array $evidences): void + public function getEvidence(): ?array { - $this->evidences = $evidences; + return $this->evidence; } - public function getPresenceUpdatedBy(): ?User + public function setEvidence(?array $evidence): void { - return $this->presenceUpdatedBy; - } - - public function setPresenceUpdatedBy(?User $user): self - { - $this->presenceUpdatedBy = $user; - - return $this; + $this->evidence = $evidence; } - public function getPresenceUpdatedAt(): ?\DateTimeInterface + public function getUpdatedBy(): ?User { - return $this->presenceUpdatedAt; + return $this->updatedBy; } - public function setPresenceUpdatedAt(?\DateTimeInterface $date): self + public function setUpdatedBy(?User $user): self { - $this->presenceUpdatedAt = $date; + $this->updatedBy = $user; return $this; } diff --git a/src/plugin/cursus/Installation/Migrations/Version20240408151719.php b/src/plugin/cursus/Installation/Migrations/Version20240408151719.php index adaef5af07..4a0c3ec1af 100644 --- a/src/plugin/cursus/Installation/Migrations/Version20240408151719.php +++ b/src/plugin/cursus/Installation/Migrations/Version20240408151719.php @@ -16,7 +16,7 @@ public function up(Schema $schema): void { $this->addSql(" ALTER TABLE claro_cursusbundle_presence_status - ADD evidences LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)' + ADD evidence LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)' "); } @@ -24,7 +24,7 @@ public function down(Schema $schema): void { $this->addSql(' ALTER TABLE claro_cursusbundle_presence_status - DROP evidences + DROP evidence '); } } diff --git a/src/plugin/cursus/Installation/Migrations/Version20241014084016.php b/src/plugin/cursus/Installation/Migrations/Version20241014084016.php index 0a33576739..8b94edb607 100644 --- a/src/plugin/cursus/Installation/Migrations/Version20241014084016.php +++ b/src/plugin/cursus/Installation/Migrations/Version20241014084016.php @@ -16,16 +16,16 @@ public function up(Schema $schema): void { $this->addSql(' ALTER TABLE claro_cursusbundle_presence_status - ADD presence_updated_by INT DEFAULT NULL, - ADD presence_updated_at DATETIME DEFAULT NULL + ADD updatedBy INT DEFAULT NULL, + ADD updatedAt DATETIME DEFAULT NULL '); $this->addSql(' ALTER TABLE claro_cursusbundle_presence_status - ADD CONSTRAINT FK_DFE5E1FE349A94C7 FOREIGN KEY (presence_updated_by) + ADD CONSTRAINT FK_DFE5E1FE349A94C7 FOREIGN KEY (updatedBy) REFERENCES claro_user (id) '); $this->addSql(' - CREATE INDEX IDX_DFE5E1FE349A94C7 ON claro_cursusbundle_presence_status (presence_updated_by) + CREATE INDEX IDX_DFE5E1FE349A94C7 ON claro_cursusbundle_presence_status (updatedBy) '); } @@ -40,8 +40,8 @@ public function down(Schema $schema): void '); $this->addSql(' ALTER TABLE claro_cursusbundle_presence_status - DROP presence_updated_by, - DROP presence_updated_at + DROP updatedBy, + DROP updatedAt '); } } diff --git a/src/plugin/cursus/Resources/modules/presence/components/list.jsx b/src/plugin/cursus/Resources/modules/presence/components/list.jsx index a21393ac48..6c14eb4edd 100644 --- a/src/plugin/cursus/Resources/modules/presence/components/list.jsx +++ b/src/plugin/cursus/Resources/modules/presence/components/list.jsx @@ -46,26 +46,22 @@ const Presences = props => { ), displayed: true }, { - name: 'presence_updated_by', + name: 'meta.updatedBy', type: 'user', - label: trans('presence_updated_by', {}, 'presence'), - displayed: true + label: trans('updated_by', {}, 'presence'), + displayed: false }, { - name: 'presence_updated_at', + name: 'meta.updatedAt', type: 'date', - label: trans('presence_updated_at', {}, 'presence'), - displayed: true, - options: { - time: true - } + label: trans('updated_at', {}, 'presence'), + displayed: false, + options: {time: true} },{ name: 'validation_date', type: 'date', label: trans('presence_confirmation_date', {}, 'presence'), displayed: true, - options: { - time: true - } + options: {time: true} }, { name: 'evidences', type: 'number', diff --git a/src/plugin/cursus/Resources/translations/presence.en.json b/src/plugin/cursus/Resources/translations/presence.en.json index 0a808a9756..37da68c1c6 100644 --- a/src/plugin/cursus/Resources/translations/presence.en.json +++ b/src/plugin/cursus/Resources/translations/presence.en.json @@ -30,8 +30,8 @@ "presence_validation_date": "Validation date by tutor", "presence_info": "Me, %user%, was present at the event %event_title% from %event_date_start% to %event_date_end%.", "presence_validation": "Validate status", - "presence_updated_by": "Status updated by", - "presence_updated_at": "Update date", + "updated_by": "Status updated by", + "updated_at": "Update date", "validate": "Validate", "validation": "Validation" diff --git a/src/plugin/cursus/Resources/translations/presence.fr.json b/src/plugin/cursus/Resources/translations/presence.fr.json index 9e1eb25688..7e22f15f18 100644 --- a/src/plugin/cursus/Resources/translations/presence.fr.json +++ b/src/plugin/cursus/Resources/translations/presence.fr.json @@ -30,8 +30,8 @@ "presence_validation_date": "Date de validation par le formateur", "presence_info": "Moi, %user%, étais présent à la séance %event_title% du %event_datetime_start% au %event_datetime_end%.", "presence_validation": "Valider les statuts", - "presence_updated_by": "Statut mis à jour par", - "presence_updated_at": "Date de mise à jour", + "updated_by": "Statut mis à jour par", + "updated_at": "Date de mise à jour", "validate": "Valider", "validation": "Validation" diff --git a/src/plugin/cursus/Serializer/EventPresenceSerializer.php b/src/plugin/cursus/Serializer/EventPresenceSerializer.php index 0d840ce4ae..c829c38655 100644 --- a/src/plugin/cursus/Serializer/EventPresenceSerializer.php +++ b/src/plugin/cursus/Serializer/EventPresenceSerializer.php @@ -53,9 +53,11 @@ public function serialize(EventPresence $eventPresence, array $options = []): ar 'status' => $eventPresence->getStatus(), 'signature' => $eventPresence->getSignature(), 'validation_date' => DateNormalizer::normalize($eventPresence->getValidationDate()), - 'evidences' => $eventPresence->getEvidences(), - 'presence_updated_by' => $eventPresence->getPresenceUpdatedBy() ? $this->userSerializer->serialize($eventPresence->getPresenceUpdatedBy(), [SerializerInterface::SERIALIZE_MINIMAL]) : null, - 'presence_updated_at' => DateNormalizer::normalize($eventPresence->getPresenceUpdatedAt()), + 'evidence' => $eventPresence->getEvidence(), + 'meta' => [ + 'updatedBy' => $eventPresence->getUpdatedBy() ? $this->userSerializer->serialize($eventPresence->getUpdatedBy(), [SerializerInterface::SERIALIZE_MINIMAL]) : null, + 'updatedAt' => DateNormalizer::normalize($eventPresence->getUpdatedAt()), + ], 'evidence_added_by' => $eventPresence->getEvidenceAddedBy() ? $this->userSerializer->serialize($eventPresence->getEvidenceAddedBy(), [SerializerInterface::SERIALIZE_MINIMAL]) : null, 'evidence_added_at' => DateNormalizer::normalize($eventPresence->getEvidenceAddedAt()), ]; @@ -88,17 +90,19 @@ public function deserialize(array $data, EventPresence $eventPresence): EventPre $eventPresence->setUser($user); } - if (array_key_exists('evidences', $data)) { - $eventPresence->setEvidences($data['evidences'] ?? null); + if (array_key_exists('evidence', $data)) { + $eventPresence->setEvidence($data['evidence'] ?? null); } - if (isset($data['presence_updated_by'])) { - $updatedBy = $this->om->getRepository(User::class)->findOneBy(['uuid' => $data['presence_updated_by']['id']]); - $eventPresence->setPresenceUpdatedBy($updatedBy); - } + if (isset($data['meta'])) { + if (isset($data['meta']['updatedBy'])) { + $updatedBy = $this->om->getRepository(User::class)->findOneBy(['uuid' => $data['updatedBy']['id']]); + $eventPresence->setUpdatedBy($updatedBy); + } - if (isset($data['presence_updated_at'])) { - $eventPresence->setPresenceUpdatedAt(DateNormalizer::denormalize($data['presence_updated_at'])); + if (isset($data['meta']['updatedAt'])) { + $eventPresence->setUpdatedAt(DateNormalizer::denormalize($data['meta']['updatedAt'])); + } } if (isset($data['evidence_added_by'])) {