Skip to content

Commit

Permalink
presence management
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Oct 14, 2024
1 parent 62ee780 commit db9e92d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 42 deletions.
23 changes: 13 additions & 10 deletions src/plugin/cursus/Controller/EventPresenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,27 @@ public function signStatusAction(Request $request): JsonResponse
}

/**
* Confirm the status of a EventPresence for current user.
* Confirm the status of a EventPresence for current event.
*
* @Route("/confirm", name="apiv2_cursus_event_presence_confirm", methods={"PUT"})
* @Route("/confirm/{id}", name="apiv2_cursus_event_presence_confirm", methods={"PUT"})
*
* @EXT\ParamConverter("event", class="Claroline\CursusBundle\Entity\Event", options={"mapping": {"id": "uuid"}})
*/
public function confirmStatusAction(Request $request): JsonResponse
public function confirmStatusAction(Event $event): JsonResponse
{
$data = $this->decodeRequest($request);
if (empty($data)) {
throw new InvalidDataException('Invalid data');
}
$this->checkPermission('ADMINISTRATE', $event, [], true);

$presences = $this->om->getRepository(EventPresence::class)->findBy(['event' => $event]);
$presencesToValidate = array_filter($presences, function (EventPresence $presence) {
return EventPresence::UNKNOWN !== $presence->getStatus();
});

$presences = $this->om->getRepository(EventPresence::class)->findBy(['uuid' => $data]);
$this->om->startFlushSuite();
foreach ($presences as $presence) {
$this->checkPermission('ADMINISTRATE', $presence, [], true);

foreach ($presencesToValidate as $presence) {
$this->manager->setValidationDate([$presence], new \DateTime());
}

$this->om->endFlushSuite();

return new JsonResponse();
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/cursus/Manager/EventPresenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function setStatus(array $presences, string $status): array
return $presences;
}

public function setValidationDate(array $presences, \DateTimeInterface $date): array
public function setValidationDate(array $presences, ?\DateTimeInterface $date): array
{
foreach ($presences as $presence) {
$presence->setValidationDate($date);
Expand Down

This file was deleted.

13 changes: 13 additions & 0 deletions src/plugin/cursus/Resources/modules/event/components/list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ const Events = (props) =>
displayed: hasPermission('edit', rows[0]),
group: trans('presences', {}, 'cursus'),
target: ['apiv2_cursus_event_presence_download', {id: rows[0].id, filled: 1}]
}, {
name: 'confirm-status',
type: ASYNC_BUTTON,
icon: 'fa fa-fw fa-clipboard-check',
label: trans('presence_validation', {}, 'presence'),
displayed: hasPermission('edit', rows[0]),
group: trans('validation', {}, 'presence'),
request: {
url: ['apiv2_cursus_event_presence_confirm', {id: rows[0].id}],
request: {
method: 'PUT'
}
}
}
].concat(props.customActions(rows))}
delete={{
Expand Down
15 changes: 14 additions & 1 deletion src/plugin/cursus/Resources/modules/event/components/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import isEmpty from 'lodash/isEmpty'

import {trans} from '#/main/app/intl/translation'
import {hasPermission} from '#/main/app/security'
import {MODAL_BUTTON, URL_BUTTON} from '#/main/app/buttons'
import {MODAL_BUTTON, URL_BUTTON, ASYNC_BUTTON} from '#/main/app/buttons'
import {ContentLoader} from '#/main/app/content/components/loader'
import {ToolPage} from '#/main/core/tool'

Expand Down Expand Up @@ -82,6 +82,19 @@ const EventPage = (props) => {
displayed: hasPermission('edit', props.event),
group: trans('presences', {}, 'cursus'),
target: ['apiv2_cursus_event_presence_download', {id: props.event.id, filled: 1}]
}, {
name: 'confirm-status',
type: ASYNC_BUTTON,
icon: 'fa fa-fw fa-clipboard-check',
label: trans('presence_validation', {}, 'presence'),
displayed: hasPermission('edit', props.event),
group: trans('validation', {}, 'presence'),
request: {
url: ['apiv2_cursus_event_presence_confirm', {id: props.event.id}],
request: {
method: 'PUT'
}
}
}
]}

Expand Down
1 change: 0 additions & 1 deletion src/plugin/cursus/Resources/modules/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ registry.add('ClarolineCursusBundle', {
'mark-absent-unjustified': () => { return import(/* webpackChunkName: "training-action-presence-absent-unjustified" */ '#/plugin/cursus/actions/presence/mark-absent-unjustified') },
'mark-absent-present' : () => { return import(/* webpackChunkName: "training-action-presence-present" */ '#/plugin/cursus/actions/presence/mark-present') },
'mark-unknown' : () => { return import(/* webpackChunkName: "training-action-presence-unknown" */ '#/plugin/cursus/actions/presence/mark-unknown') },
'confirm-presence' : () => { return import(/* webpackChunkName: "training-action-presence-confirm" */ '#/plugin/cursus/actions/presence/confirm-presence') },
'add-evidence' : () => { return import(/* webpackChunkName: "training-action-presence-add-evidence" */ '#/plugin/cursus/actions/presence/add-evidence') }
}
},
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 @@ -16,10 +16,10 @@
"presence_confirm_title": "Presence confirmation",
"presence_confirm_desc": "Your %event_title% event signature has been successfully recorded.",
"presence_confirm_other": "Confirm another presence",
"presence_confirmation_date": "Confirmation date",
"presence_confirmation_date": "Validation date",
"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 presence",
"presence_validation": "Validate status",

"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 @@ -16,10 +16,10 @@
"presence_confirm_title": "Confirmation de présence",
"presence_confirm_desc": "Votre présence à la séance %event_title% a bien été enregistrée.",
"presence_confirm_other": "Confirmer une autre présence",
"presence_confirmation_date": "Date de confirmation",
"presence_confirmation_date": "Date de validation",
"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": "Confirmer la présence",
"presence_validation": "Valider les statuts",

"validate": "Valider",
"validation": "Validation"
Expand Down

0 comments on commit db9e92d

Please sign in to comment.