Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
SpecialCancelEventRegistration | |
0.00% |
0 / 29 |
|
0.00% |
0 / 8 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
checkRegistrationPrecondition | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
getFormFields | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
alterForm | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
onSubmit | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
onSuccess | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
requiresUnblock | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkEventIsValid | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare( strict_types=1 ); |
4 | |
5 | namespace MediaWiki\Extension\CampaignEvents\Special; |
6 | |
7 | use MediaWiki\Extension\CampaignEvents\Event\Store\IEventLookup; |
8 | use MediaWiki\Extension\CampaignEvents\MWEntity\CampaignsCentralUserLookup; |
9 | use MediaWiki\Extension\CampaignEvents\MWEntity\MWAuthorityProxy; |
10 | use MediaWiki\Extension\CampaignEvents\MWEntity\UserNotGlobalException; |
11 | use MediaWiki\Extension\CampaignEvents\Participants\ParticipantsStore; |
12 | use MediaWiki\Extension\CampaignEvents\Participants\UnregisterParticipantCommand; |
13 | use MediaWiki\Html\Html; |
14 | use MediaWiki\HTMLForm\HTMLForm; |
15 | use Status; |
16 | use StatusValue; |
17 | |
18 | class SpecialCancelEventRegistration extends ChangeRegistrationSpecialPageBase { |
19 | public const PAGE_NAME = 'CancelEventRegistration'; |
20 | |
21 | private UnregisterParticipantCommand $unregisterParticipantCommand; |
22 | private ParticipantsStore $participantsStore; |
23 | |
24 | /** |
25 | * @param IEventLookup $eventLookup |
26 | * @param CampaignsCentralUserLookup $centralUserLookup |
27 | * @param UnregisterParticipantCommand $unregisterParticipantCommand |
28 | * @param ParticipantsStore $participantsStore |
29 | */ |
30 | public function __construct( |
31 | IEventLookup $eventLookup, |
32 | CampaignsCentralUserLookup $centralUserLookup, |
33 | UnregisterParticipantCommand $unregisterParticipantCommand, |
34 | ParticipantsStore $participantsStore |
35 | ) { |
36 | parent::__construct( self::PAGE_NAME, $eventLookup, $centralUserLookup ); |
37 | $this->unregisterParticipantCommand = $unregisterParticipantCommand; |
38 | $this->participantsStore = $participantsStore; |
39 | } |
40 | |
41 | /** |
42 | * @inheritDoc |
43 | */ |
44 | protected function checkRegistrationPrecondition() { |
45 | try { |
46 | $centralUser = $this->centralUserLookup->newFromAuthority( new MWAuthorityProxy( $this->getAuthority() ) ); |
47 | $isParticipating = $this->participantsStore->userParticipatesInEvent( |
48 | $this->event->getID(), |
49 | $centralUser, |
50 | true |
51 | ); |
52 | } catch ( UserNotGlobalException $_ ) { |
53 | $isParticipating = false; |
54 | } |
55 | |
56 | return $isParticipating ? true : 'campaignevents-unregister-not-participant'; |
57 | } |
58 | |
59 | /** |
60 | * @inheritDoc |
61 | */ |
62 | protected function getFormFields(): array { |
63 | return [ |
64 | 'Info' => [ |
65 | 'type' => 'info', |
66 | 'default' => $this->msg( 'campaignevents-unregister-confirmation-text' )->text(), |
67 | ], |
68 | ]; |
69 | } |
70 | |
71 | /** |
72 | * @inheritDoc |
73 | */ |
74 | protected function alterForm( HTMLForm $form ): void { |
75 | $form->setWrapperLegendMsg( 'campaignevents-unregister-confirmation-top' ); |
76 | $form->setSubmitTextMsg( 'campaignevents-unregister-confirmation-btn' ); |
77 | } |
78 | |
79 | /** |
80 | * @inheritDoc |
81 | */ |
82 | public function onSubmit( array $data ) { |
83 | return Status::wrap( $this->unregisterParticipantCommand->unregisterIfAllowed( |
84 | $this->event, |
85 | new MWAuthorityProxy( $this->getAuthority() ) |
86 | ) ); |
87 | } |
88 | |
89 | /** |
90 | * @inheritDoc |
91 | */ |
92 | public function onSuccess(): void { |
93 | $this->getOutput()->addHTML( Html::successBox( |
94 | $this->msg( 'campaignevents-unregister-success' )->escaped() |
95 | ) ); |
96 | } |
97 | |
98 | /** |
99 | * @inheritDoc |
100 | */ |
101 | public function requiresUnblock(): bool { |
102 | return false; |
103 | } |
104 | |
105 | /** |
106 | * @inheritDoc |
107 | */ |
108 | public function checkEventIsValid(): StatusValue { |
109 | return UnregisterParticipantCommand::checkIsUnregistrationAllowed( $this->event ); |
110 | } |
111 | } |