Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Oct 25, 2024
1 parent 6f88726 commit 64c1c68
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 75 deletions.
24 changes: 12 additions & 12 deletions src/plugin/cursus/Controller/EventPresenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(),
Expand All @@ -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());

Expand All @@ -301,15 +301,15 @@ 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"}})
*/
public function deleteEvidenceAction(EventPresence $eventPresence): JsonResponse
{
$this->checkPermission('EDIT', $eventPresence, [], true);

$eventPresence->setEvidences(null);
$eventPresence->setEvidence(null);

$this->om->persist($eventPresence);
$this->om->flush();
Expand All @@ -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"}})
*/
Expand Down
41 changes: 13 additions & 28 deletions src/plugin/cursus/Entity/EventPresence.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,6 +17,7 @@ class EventPresence
{
use Id;
use Uuid;
use UpdatedAt;

public const UNKNOWN = 'unknown';
public const PRESENT = 'present';
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ 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)'
");
}

public function down(Schema $schema): void
{
$this->addSql('
ALTER TABLE claro_cursusbundle_presence_status
DROP evidences
DROP evidence
');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
');
}

Expand All @@ -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
');
}
}
20 changes: 8 additions & 12 deletions src/plugin/cursus/Resources/modules/presence/components/list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/cursus/Resources/translations/presence.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/cursus/Resources/translations/presence.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 15 additions & 11 deletions src/plugin/cursus/Serializer/EventPresenceSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
];
Expand Down Expand Up @@ -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'])) {
Expand Down

0 comments on commit 64c1c68

Please sign in to comment.