Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 83 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
InvitationsListPager | |
0.00% |
0 / 83 |
|
0.00% |
0 / 7 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
formatRow | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
2 | |||
getIndexField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEmptyBody | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
getStartBody | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
getInfoChip | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | declare( strict_types=1 ); |
3 | |
4 | namespace MediaWiki\Extension\CampaignEvents\Pager; |
5 | |
6 | use MediaWiki\Context\IContextSource; |
7 | use MediaWiki\Extension\CampaignEvents\Database\CampaignsDatabaseHelper; |
8 | use MediaWiki\Extension\CampaignEvents\Invitation\InvitationList; |
9 | use MediaWiki\Extension\CampaignEvents\MWEntity\CentralUser; |
10 | use MediaWiki\Extension\CampaignEvents\Special\SpecialGenerateInvitationList; |
11 | use MediaWiki\Extension\CampaignEvents\Special\SpecialInvitationList; |
12 | use MediaWiki\Html\TemplateParser; |
13 | use MediaWiki\Linker\LinkRenderer; |
14 | use MediaWiki\Pager\ReverseChronologicalPager; |
15 | use MediaWiki\SpecialPage\SpecialPage; |
16 | use MediaWiki\WikiMap\WikiMap; |
17 | use OOUI\ButtonWidget; |
18 | use OOUI\HtmlSnippet; |
19 | use OOUI\Tag; |
20 | use stdClass; |
21 | |
22 | class InvitationsListPager extends ReverseChronologicalPager { |
23 | private CentralUser $centralUser; |
24 | private TemplateParser $templateParser; |
25 | |
26 | public function __construct( |
27 | CentralUser $user, |
28 | CampaignsDatabaseHelper $databaseHelper, |
29 | IContextSource $context, |
30 | LinkRenderer $linkRenderer |
31 | ) { |
32 | $this->centralUser = $user; |
33 | $this->templateParser = new TemplateParser( __DIR__ . '/../../templates' ); |
34 | $this->mDb = $databaseHelper->getDBConnection( DB_REPLICA ); |
35 | parent::__construct( $context, $linkRenderer ); |
36 | } |
37 | |
38 | /** |
39 | * @inheritDoc |
40 | */ |
41 | public function formatRow( $row ) { |
42 | $container = ( new Tag() )->addClasses( [ 'ext-campaignevents-invitations-pager-row' ] ); |
43 | $linkWrapper = ( new Tag() )->appendContent( |
44 | new HtmlSnippet( |
45 | $this->getLinkRenderer()->makeKnownLink( |
46 | SpecialPage::getTitleFor( SpecialInvitationList::PAGE_NAME, (string)$row->ceil_id ), |
47 | $row->ceil_name |
48 | ) ) |
49 | )->addClasses( [ 'ext-campaignevents-invitations-pager-link' ] ); |
50 | $chip = new HtmlSnippet( $this->getInfoChip( $row ) ); |
51 | return $container->appendContent( [ $linkWrapper, $chip ] ); |
52 | } |
53 | |
54 | /** |
55 | * @inheritDoc |
56 | */ |
57 | public function getQueryInfo() { |
58 | return [ |
59 | 'tables' => [ 'ce_invitation_lists', 'ce_invitation_list_users' ], |
60 | 'fields' => [ |
61 | 'ceil_id', |
62 | 'ceil_name', |
63 | 'ceil_status', |
64 | 'ceil_created_at', |
65 | 'ceil_user_id', |
66 | 'ceil_editor_count' => 'COUNT(ceilu_id)' |
67 | ], |
68 | 'conds' => [ |
69 | 'ceil_wiki' => WikiMap::getCurrentWikiId(), |
70 | 'ceil_user_id' => $this->centralUser->getCentralID() |
71 | ], |
72 | 'options' => [ 'GROUP BY' => [ |
73 | 'ceil_id' |
74 | ] ], |
75 | 'join_conds' => [ |
76 | 'ce_invitation_list_users' => [ |
77 | 'LEFT JOIN', [ |
78 | 'ceil_id=ceilu_ceil_id', |
79 | $this->mDb->expr( |
80 | 'ceilu_score', |
81 | '>=', |
82 | SpecialInvitationList::RECOMMENDED_MIN_SCORE |
83 | ) |
84 | ] |
85 | ] |
86 | ] |
87 | ]; |
88 | } |
89 | |
90 | /** |
91 | * @inheritDoc |
92 | */ |
93 | public function getIndexField() { |
94 | // This index is not optimized |
95 | return [ [ 'ceil_created_at', 'ceil_id' ] ]; |
96 | } |
97 | |
98 | /** |
99 | * @inheritDoc |
100 | */ |
101 | public function getEmptyBody() { |
102 | $container = ( new Tag() ); |
103 | $text = new Tag( 'p' ); |
104 | $text->appendContent( |
105 | $this->msg( |
106 | 'campaignevents-myinvitationslist-empty-text' |
107 | )->text() |
108 | ); |
109 | $button = new ButtonWidget( |
110 | [ |
111 | 'href' => SpecialPage::getTitleFor( SpecialGenerateInvitationList::PAGE_NAME )->getLocalURL(), |
112 | 'label' => $this->msg( 'campaignevents-myinvitationslist-generate-button' )->text(), |
113 | 'flags' => [ 'primary', 'progressive' ] |
114 | ] |
115 | ); |
116 | $textContainer = ( new Tag() )->appendContent( [ $text, $button ] ); |
117 | return $container->appendContent( [ $textContainer ] ); |
118 | } |
119 | |
120 | /** |
121 | * @inheritDoc |
122 | */ |
123 | public function getStartBody(): string { |
124 | if ( $this->getNumRows() ) { |
125 | return ( new ButtonWidget( |
126 | [ |
127 | 'href' => SpecialPage::getTitleFor( SpecialGenerateInvitationList::PAGE_NAME )->getLocalURL(), |
128 | 'label' => $this->msg( 'campaignevents-myinvitationslist-new-button' )->text(), |
129 | 'icon' => 'add', |
130 | ] |
131 | ) ) . parent::getStartBody(); |
132 | } |
133 | return parent::getStartBody(); |
134 | } |
135 | |
136 | /** |
137 | * @param stdClass $row |
138 | * @return string |
139 | */ |
140 | private function getInfoChip( stdClass $row ): string { |
141 | if ( (int)$row->ceil_status === InvitationList::STATUS_PENDING ) { |
142 | $data = [ |
143 | 'status' => 'notice', |
144 | 'message' => $this->msg( 'campaignevents-invitations-pager-status-processing' )->text() |
145 | ]; |
146 | } else { |
147 | $editorCount = (int)$row->ceil_editor_count; |
148 | $data = [ |
149 | 'status' => $editorCount > 0 ? 'success' : 'warning', |
150 | 'message' => $this->msg( 'campaignevents-invitations-pager-status-editors' ) |
151 | ->numParams( $editorCount ) |
152 | ->text() |
153 | ]; |
154 | } |
155 | |
156 | return $this->templateParser->processTemplate( 'InfoChip', $data ); |
157 | } |
158 | } |