Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 96 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
CentralNoticePager | |
0.00% |
0 / 96 |
|
0.00% |
0 / 6 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 45 |
|
0.00% |
0 / 1 |
20 | |||
formatRow | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
6 | |||
getStartBody | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
6 | |||
getEndBody | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
bucketDropdown | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | use MediaWiki\Html\Html; |
4 | |
5 | class CentralNoticePager extends TemplatePager { |
6 | |
7 | public function __construct( $special, $filter = '' ) { |
8 | parent::__construct( $special, $filter ); |
9 | } |
10 | |
11 | /** |
12 | * Pull banners from the database |
13 | * @return array[] |
14 | */ |
15 | public function getQueryInfo() { |
16 | $dbr = CNDatabase::getDb(); |
17 | |
18 | // First we must construct the filter before we pull banners |
19 | // When the filter comes in it is space delimited, so break that... |
20 | $likeArray = preg_split( '/\s/', $this->filter ); |
21 | |
22 | // ...and then insert all the wildcards between search terms |
23 | if ( !$likeArray ) { |
24 | $likeArray = $dbr->anyString(); |
25 | } else { |
26 | $anyStringToken = $dbr->anyString(); |
27 | $tempArray = [ $anyStringToken ]; |
28 | foreach ( $likeArray as $likePart ) { |
29 | $tempArray[] = $likePart; |
30 | $tempArray[] = $anyStringToken; |
31 | } |
32 | $likeArray = $tempArray; |
33 | } |
34 | |
35 | // Get the current campaign and filter on that as well if required |
36 | $notice = $this->mRequest->getVal( 'notice' ); |
37 | $noticeId = Campaign::getNoticeId( $notice ); |
38 | |
39 | if ( $noticeId ) { |
40 | // Return all the banners not already assigned to the current campaign |
41 | return [ |
42 | 'tables' => [ |
43 | 'assignments' => 'cn_assignments', |
44 | 'templates' => 'cn_templates', |
45 | ], |
46 | |
47 | 'fields' => [ |
48 | 'templates.tmp_name', |
49 | 'templates.tmp_id', |
50 | ], |
51 | |
52 | 'conds' => [ |
53 | 'assignments.tmp_id IS NULL', |
54 | 'tmp_name' . $dbr->buildLike( $likeArray ), |
55 | 'templates.tmp_is_template = 0' |
56 | ], |
57 | |
58 | 'join_conds' => [ |
59 | 'assignments' => [ |
60 | 'LEFT JOIN', |
61 | [ |
62 | "assignments.tmp_id = templates.tmp_id ", |
63 | "assignments.not_id" => $noticeId |
64 | ] |
65 | ] |
66 | ] |
67 | ]; |
68 | } else { |
69 | // Return all the banners in the database |
70 | return [ |
71 | 'tables' => [ 'templates' => 'cn_templates' ], |
72 | 'fields' => [ 'templates.tmp_name', 'templates.tmp_id' ], |
73 | 'conds' => [ |
74 | 'templates.tmp_name' . $dbr->buildLike( $likeArray ), |
75 | 'templates.tmp_is_template = 0' |
76 | ], |
77 | ]; |
78 | } |
79 | } |
80 | |
81 | /** |
82 | * Generate the content of each table row (1 row = 1 banner) |
83 | * @param stdClass $row |
84 | * @return string HTML |
85 | */ |
86 | public function formatRow( $row ) { |
87 | // Begin banner row |
88 | $htmlOut = Html::openElement( 'tr' ); |
89 | |
90 | if ( $this->editable ) { |
91 | // Add box |
92 | $htmlOut .= Html::rawElement( 'td', [ 'valign' => 'top' ], |
93 | Xml::check( 'addTemplates[]', false, [ 'value' => $row->tmp_name ] ) |
94 | ); |
95 | |
96 | // Bucket |
97 | $htmlOut .= Html::rawElement( 'td', [ 'valign' => 'top' ], |
98 | $this->bucketDropdown( $row->tmp_name ) |
99 | ); |
100 | |
101 | // Weight select |
102 | $htmlOut .= Html::rawElement( 'td', [ 'valign' => 'top', 'class' => 'cn-weight' ], |
103 | Xml::listDropdown( "weight[$row->tmp_id]", |
104 | CentralNotice::dropdownList( |
105 | $this->msg( 'centralnotice-weight' )->text(), range( 0, 100, 5 ) |
106 | ), |
107 | '', |
108 | '25' |
109 | ) |
110 | ); |
111 | } |
112 | |
113 | // Render banner row. |
114 | $htmlOut .= Html::rawElement( 'td', [ 'valign' => 'top' ], |
115 | BannerRenderer::linkToBanner( $row->tmp_name ) |
116 | ); |
117 | |
118 | // End banner row |
119 | $htmlOut .= Html::closeElement( 'tr' ); |
120 | |
121 | return $htmlOut; |
122 | } |
123 | |
124 | /** |
125 | * Specify table headers |
126 | * |
127 | * @return string |
128 | */ |
129 | public function getStartBody() { |
130 | $htmlOut = ''; |
131 | $htmlOut .= Html::openElement( 'table', [ 'cellpadding' => 9 ] ); |
132 | $htmlOut .= Html::openElement( 'tr' ); |
133 | if ( $this->editable ) { |
134 | $htmlOut .= Xml::element( 'th', [ 'align' => 'left', 'width' => '5%' ], |
135 | $this->msg( "centralnotice-add" )->text() |
136 | ); |
137 | $htmlOut .= Xml::element( 'th', [ 'align' => 'left', 'width' => '5%' ], |
138 | $this->msg( 'centralnotice-bucket' )->text() |
139 | ); |
140 | $htmlOut .= Xml::element( 'th', |
141 | [ 'align' => 'left', 'width' => '5%', 'class' => 'cn-weight' ], |
142 | $this->msg( 'centralnotice-weight' )->text() |
143 | ); |
144 | } |
145 | $htmlOut .= Xml::element( 'th', [ 'align' => 'left' ], |
146 | $this->msg( 'centralnotice-templates' )->text() |
147 | ); |
148 | $htmlOut .= Html::closeElement( 'tr' ); |
149 | return $htmlOut; |
150 | } |
151 | |
152 | /** |
153 | * Close table |
154 | * |
155 | * @return string |
156 | */ |
157 | public function getEndBody() { |
158 | return Html::closeElement( 'table' ); |
159 | } |
160 | |
161 | private function bucketDropdown( $bannerName ) { |
162 | global $wgNoticeNumberOfBuckets; |
163 | |
164 | $html = ''; |
165 | foreach ( range( 0, $wgNoticeNumberOfBuckets - 1 ) as $value ) { |
166 | $html .= Xml::option( chr( $value + ord( 'A' ) ), $value, false, [] ); |
167 | } |
168 | |
169 | return Html::rawElement( 'select', [ |
170 | 'name' => "bucket-{$bannerName}", |
171 | // class should coordinate with CentralNotice::bucketDropdown() |
172 | 'class' => 'bucketSelector', |
173 | ], $html ); |
174 | } |
175 | } |