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