|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Application\Api\Field\Mutation; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Api\Exception; |
|
8
|
|
|
use Application\Api\Field\FieldInterface; |
|
9
|
|
|
use Application\Api\Helper; |
|
10
|
|
|
use Application\DBAL\Types\BookingStatusType; |
|
11
|
|
|
use Application\DBAL\Types\BookingTypeType; |
|
12
|
|
|
use Application\Model\Bookable; |
|
13
|
|
|
use Application\Model\Booking; |
|
14
|
|
|
use Application\Model\User; |
|
15
|
|
|
use Application\Repository\UserRepository; |
|
16
|
|
|
use Cake\Chronos\Chronos; |
|
17
|
|
|
use GraphQL\Type\Definition\Type; |
|
18
|
|
|
use Zend\Expressive\Session\SessionInterface; |
|
19
|
|
|
|
|
20
|
|
|
abstract class ConfirmRegistration implements FieldInterface |
|
21
|
|
|
{ |
|
22
|
2 |
|
public static function build(): array |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
1 |
|
'name' => 'confirmRegistration', |
|
26
|
1 |
|
'type' => Type::nonNull(Type::boolean()), |
|
27
|
1 |
|
'description' => 'First step to register as a new user.', |
|
28
|
|
|
'args' => [ |
|
29
|
1 |
|
'token' => Type::nonNull(_types()->get('Token')), |
|
|
|
|
|
|
30
|
1 |
|
'input' => Type::nonNull(_types()->get('ConfirmRegistrationInput')), |
|
31
|
|
|
], |
|
32
|
|
|
'resolve' => function ($root, array $args, SessionInterface $session): bool { |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** @var UserRepository $repository */ |
|
35
|
2 |
|
$repository = _em()->getRepository(User::class); |
|
36
|
|
|
|
|
37
|
|
|
/** @var User $user */ |
|
38
|
2 |
|
$repository->getAclFilter()->setEnabled(false); |
|
39
|
2 |
|
$user = $repository->findOneByToken($args['token']); |
|
|
|
|
|
|
40
|
2 |
|
$repository->getAclFilter()->setEnabled(true); |
|
41
|
|
|
|
|
42
|
2 |
|
if (!$user || !$user->isTokenValid()) { |
|
43
|
1 |
|
throw new Exception('Cannot confirm registration with an invalid token'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// Do it |
|
47
|
1 |
|
$input = $args['input']; |
|
48
|
1 |
|
Helper::hydrate($user, $input); |
|
49
|
|
|
|
|
50
|
|
|
// Active the member |
|
51
|
1 |
|
$user->initialize(); |
|
52
|
|
|
|
|
53
|
|
|
// Create mandatory booking for him |
|
54
|
1 |
|
User::setCurrent($user); |
|
55
|
|
|
|
|
56
|
1 |
|
$mandatoryBookables = _em()->getRepository(Bookable::class)->findByBookingType(BookingTypeType::MANDATORY); |
|
|
|
|
|
|
57
|
1 |
|
foreach ($mandatoryBookables as $bookable) { |
|
58
|
1 |
|
$booking = new Booking(); |
|
59
|
1 |
|
_em()->persist($booking); |
|
60
|
|
|
|
|
61
|
1 |
|
$booking->setOwner($user); |
|
62
|
1 |
|
$booking->setStatus(BookingStatusType::BOOKED); |
|
63
|
1 |
|
$booking->setStartDate(new Chronos()); |
|
64
|
1 |
|
$booking->setBookable($bookable); |
|
65
|
|
|
|
|
66
|
|
|
// Non-periodic bookable must be terminated immediately |
|
67
|
1 |
|
if (bccomp($bookable->getPeriodicPrice(), '0.00') === 0) { |
|
68
|
1 |
|
$booking->terminate('Terminé automatiquement parce que paiement ponctuel uniquement'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
1 |
|
_em()->flush(); |
|
73
|
|
|
|
|
74
|
1 |
|
return true; |
|
75
|
1 |
|
}, |
|
76
|
|
|
]; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|