diff --git a/src/plugin/cursus/Controller/EventPresenceController.php b/src/plugin/cursus/Controller/EventPresenceController.php index be9408172bd..c4028593333 100644 --- a/src/plugin/cursus/Controller/EventPresenceController.php +++ b/src/plugin/cursus/Controller/EventPresenceController.php @@ -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(); diff --git a/src/plugin/cursus/Manager/EventPresenceManager.php b/src/plugin/cursus/Manager/EventPresenceManager.php index 5727a810e42..cec148e0e58 100644 --- a/src/plugin/cursus/Manager/EventPresenceManager.php +++ b/src/plugin/cursus/Manager/EventPresenceManager.php @@ -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); diff --git a/src/plugin/cursus/Resources/modules/actions/presence/confirm-presence.js b/src/plugin/cursus/Resources/modules/actions/presence/confirm-presence.js deleted file mode 100644 index 9375029e76e..00000000000 --- a/src/plugin/cursus/Resources/modules/actions/presence/confirm-presence.js +++ /dev/null @@ -1,25 +0,0 @@ -import {ASYNC_BUTTON} from '#/main/app/buttons' -import {trans} from '#/main/app/intl' -import {hasPermission} from '#/main/app/security' - -export default (presences, refresher) => { - const processable = presences.filter(presence => hasPermission('administrate', presence)) - - return { - name: 'confirm-presence', - type: ASYNC_BUTTON, - icon: 'fa fa-fw fa-clipboard-check', - label: trans('presence_validation', {}, 'presence'), - request: { - url: ['apiv2_cursus_event_presence_confirm'], - request: { - method: 'PUT', - body: JSON.stringify(processable.map(presence => presence.id)) - }, - success: refresher.update - }, - displayed: 0 !== processable.length, - group: trans('validation', {}, 'presence'), - scope: ['collection', 'object'] - } -} diff --git a/src/plugin/cursus/Resources/modules/event/components/list.jsx b/src/plugin/cursus/Resources/modules/event/components/list.jsx index 1317a120df9..f387722ae0c 100644 --- a/src/plugin/cursus/Resources/modules/event/components/list.jsx +++ b/src/plugin/cursus/Resources/modules/event/components/list.jsx @@ -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={{ diff --git a/src/plugin/cursus/Resources/modules/event/components/page.jsx b/src/plugin/cursus/Resources/modules/event/components/page.jsx index c5905174013..33f28a07eaa 100644 --- a/src/plugin/cursus/Resources/modules/event/components/page.jsx +++ b/src/plugin/cursus/Resources/modules/event/components/page.jsx @@ -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' @@ -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' + } + } } ]} diff --git a/src/plugin/cursus/Resources/modules/plugin.js b/src/plugin/cursus/Resources/modules/plugin.js index 48b74fe4c98..a8012452ea1 100644 --- a/src/plugin/cursus/Resources/modules/plugin.js +++ b/src/plugin/cursus/Resources/modules/plugin.js @@ -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') } } }, diff --git a/src/plugin/cursus/Resources/translations/presence.en.json b/src/plugin/cursus/Resources/translations/presence.en.json index a5a65b4fd00..7bea7bec420 100644 --- a/src/plugin/cursus/Resources/translations/presence.en.json +++ b/src/plugin/cursus/Resources/translations/presence.en.json @@ -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" diff --git a/src/plugin/cursus/Resources/translations/presence.fr.json b/src/plugin/cursus/Resources/translations/presence.fr.json index c9589c0afd3..f0bc1b163e7 100644 --- a/src/plugin/cursus/Resources/translations/presence.fr.json +++ b/src/plugin/cursus/Resources/translations/presence.fr.json @@ -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"