Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit Subscriptions #1802

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions module/Activity/src/Controller/ActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Activity\Controller;

use Activity\Form\Signup as SignupForm;
use Activity\Mapper\Signup as SignupMapper;
use Activity\Model\Activity as ActivityModel;
use Activity\Model\SignupList as SignupListModel;
use Activity\Service\AclService;
Expand Down Expand Up @@ -36,6 +37,7 @@
public function __construct(
private readonly AclService $aclService,
private readonly Translator $translator,
private readonly SignupMapper $signupMapper,
private readonly ActivityQueryService $activityQueryService,
private readonly SignupService $signupService,
private readonly SignupListQueryService $signupListQueryService,
Expand Down Expand Up @@ -81,7 +83,7 @@
return $this->forward()->dispatch(
self::class,
[
'action' => 'viewSignupList',

Check failure on line 86 in module/Activity/src/Controller/ActivityController.php

View workflow job for this annotation

GitHub Actions / Psalm

PossiblyFalseReference

module/Activity/src/Controller/ActivityController.php:86:75: PossiblyFalseReference: Cannot call method getId on possibly false value (see https://psalm.dev/105)
'id' => $activityId,
'signupList' => $activity->getSignupLists()->first()->getId(),
],
Expand Down Expand Up @@ -127,6 +129,11 @@
$identity = $this->aclService->getUserIdentityOrThrowException();
$isSignedUp = $isAllowedToSubscribe
&& $this->signupService->isSignedUp($signupList, $identity);
if ($isSignedUp) {
if (null !== ($signup = $this->signupMapper->getSignUp($signupList, $identity))) {
$form->setData($signup->toFormArray());
}
}
}

$subscriptionOpenDatePassed = $signupList->getOpenDate() < new DateTime();
Expand Down Expand Up @@ -254,16 +261,15 @@

$identity = $this->aclService->getUserIdentityOrThrowException();

// Check if the user is not already subscribed
if ($this->signupService->isSignedUp($signupList, $identity)) {
$error = $this->translator->translate('You have already been subscribed for this activity');

return $this->redirectActivityRequest($activityId, $signupListId, false, $error);
// Let user edit subscription details
if (null !== ($signup = $this->signupMapper->getSignUp($signupList, $identity))) {
$this->signupService->editSignUp($signup, $form->getData(FormInterface::VALUES_AS_ARRAY));
$message = $this->translator->translate('Successfully updated subscription');
} else {
$this->signupService->signUp($signupList, $form->getData(FormInterface::VALUES_AS_ARRAY));
$message = $this->translator->translate('Successfully subscribed');
}

$this->signupService->signUp($signupList, $form->getData(FormInterface::VALUES_AS_ARRAY));
$message = $this->translator->translate('Successfully subscribed');

return $this->redirectActivityRequest($activityId, $signupListId, true, $message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __invoke(
return new ActivityController(
$container->get('activity_service_acl'),
$container->get(MvcTranslator::class),
$container->get('activity_mapper_signup'),
$container->get('activity_service_activityQuery'),
$container->get('activity_service_signup'),
$container->get('activity_service_signupListQuery'),
Expand Down
21 changes: 21 additions & 0 deletions module/Activity/src/Model/Signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,25 @@ public function toGdprArray(): array
'fieldValues' => $fieldValues,
];
}

/**
* @return array<array-key, int|string|null>
*/
public function toFormArray(): array
{
$fieldValues = [];
foreach ($this->getFieldValues() as $fieldValue) {
$value = null;

if (3 === $fieldValue->getField()->getType()) {
$value = $fieldValue->getOption()?->getId();
} elseif (1 === $fieldValue->getField()->getType()) {
$value = 'Yes' === $fieldValue->getValue() ? '1' : '0';
}

$fieldValues[$fieldValue->getField()->getId()] = $value ?? $fieldValue->getValue();
}

return $fieldValues;
}
}
32 changes: 30 additions & 2 deletions module/Activity/src/Service/Signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ protected function createSignup(
array $fieldResults,
): ExternalSignupModel|UserSignupModel {
$signup->setSignupList($signupList);
$optionMapper = $this->signupOptionMapper;
$em = $this->entityManager;

foreach ($signupList->getFields() as $field) {
Expand All @@ -194,7 +193,7 @@ protected function createSignup(
$fieldValue->setValue($value ? 'Yes' : 'No');
break;
case 3://'Choice'
$fieldValue->setOption($optionMapper->find((int) $value));
$fieldValue->setOption($this->signupOptionMapper->find((int) $value));
break;
}

Expand All @@ -208,6 +207,35 @@ protected function createSignup(
return $signup;
}

/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification
*/
public function editSignUp(
UserSignupModel $signup,
array $fieldResults,
): void {
foreach ($signup->getFieldValues() as $fieldValue) {
$value = $fieldResults[$fieldValue->getField()->getId()];

//Change the value into the actual format
switch ($fieldValue->getField()->getType()) {
case 0://'Text'
case 2://'Number'
$fieldValue->setValue($value);
break;
case 1://'Yes/No'
$fieldValue->setValue($value ? 'Yes' : 'No');
break;
case 3://'Choice'
$fieldValue->setOption($this->signupOptionMapper->find((int) $value));
break;
}
}

$this->signupMapper->persist($signup);
$this->signupMapper->flush();
}

/**
* Sign an external user up for an activity, which the current user may admin.
*
Expand Down
22 changes: 18 additions & 4 deletions module/Activity/view/activity/activity/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,17 @@ $this->headTitle($this->translate('Activities'));
<span class="fas fa-user-check"></span> <?= $this->translate('Unsubscription period closed') ?>
</button>
<?php else: ?>
<button class="btn btn-default btn-lg" type="button" data-toggle="modal"
data-target="#signoffModal" aria-hidden="true" aria-controls="signoffModal">
<span class="fas fa-user-minus"></span> <?= $this->translate('Unsubscribe') ?>
</button>
<div class="col">
<button class="btn btn-default btn-lg" type="button" data-toggle="modal"
data-target="#signoffModal" aria-hidden="true" aria-controls="signoffModal">
<span class="fas fa-user-minus"></span> <?= $this->translate('Unsubscribe') ?>
</button>
<button class="btn btn-primary btn-lg" type="button" data-toggle="modal"
data-target="#signupModal" aria-hidden="true" aria-controls="signupModal">
<span class="fas fa-user-pen"></span> <?= $this->translate('Update subscription') ?>
</button>
</div>
<!-- modal to sign out -->
<div class="modal fade" id="signoffModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
Expand Down Expand Up @@ -239,6 +246,13 @@ $this->headTitle($this->translate('Activities'));
</div>
</div>
</div>
<!-- modal to edit subscription details -->
<?= $this->partial('partial/signupForm', [
'form' => $form,
'signupList' => $signupList,
'update' => true,
])
?>
<?php endif; ?>
<?php elseif (!$signupOpen): ?>
<button class="btn btn-default btn-lg" type="button" disabled="disabled">
Expand Down
33 changes: 29 additions & 4 deletions module/Activity/view/partial/signupForm.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use Laminas\View\Renderer\PhpRenderer;
* @var PhpRenderer|HelperTrait $this
* @var SignupForm $form
* @var SignupListModel $signupList
* @var ?bool $update
*/

$showCaptcha = false;
Expand All @@ -20,21 +21,45 @@ switch ($form->getType()) {
case SignupForm::USER:
$agreementText = $this->translate('By subscribing to this activity, you agree to the terms outlined in the');
$sensitiveStartText = $this->translate('Your sign-up will be visible to other members and graduates.');
$submitUrl = $this->url('activity/signup', ['id' => $signupList->getActivity()->getId(), 'signupList' => $signupList->getId()]);
$submitText = $this->translate('Confirm subscription');
$submitUrl = $this->url(
'activity/signup',
[
'id' => $signupList->getActivity()->getId(),
'signupList' => $signupList->getId(),
],
);

if (isset($update)) {
$submitText = $this->translate('Update subscription');
} else {
$submitText = $this->translate('Confirm subscription');
}

break;
case SignupForm::EXTERNAL_USER:
$agreementText = $this->translate('By subscribing to this activity, you agree to the terms outlined in the');
$sensitiveStartText = $this->translate('Your sign-up will be visible to all visitors of the website.');
$submitUrl = $this->url('activity/externalSignup', ['id' => $signupList->getActivity()->getId(), 'signupList' => $signupList->getId()]);
$submitUrl = $this->url(
'activity/externalSignup',
[
'id' => $signupList->getActivity()->getId(),
'signupList' => $signupList->getId(),
],
);
$submitText = $this->translate('Subscribe as external participant');
$showCaptcha = true;
$showName = true;
break;
case SignupForm::EXTERNAL_ADMIN:
$agreementText = $this->translate('By subscribing an external participant to this activity, they must agree to the terms outlined in the');
$sensitiveStartText = $this->translate('The sign-up of this external participant will be visible to all visitors of the website.');
$submitUrl = $this->url('activity_admin/adminSignup', ['id' => $signupList->getActivity()->getId(), 'signupList' => $signupList->getId()]);
$submitUrl = $this->url(
'activity_admin/adminSignup',
[
'id' => $signupList->getActivity()->getId(),
'signupList' => $signupList->getId(),
],
);
$submitText = $this->translate('Subscribe an external participant');
$showName = true;
break;
Expand Down
18 changes: 11 additions & 7 deletions module/Application/language/en.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions module/Application/language/gewisweb.pot

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading