-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdPager.php
145 lines (128 loc) · 3.61 KB
/
AdPager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* Provides pagination functionality for viewing ad lists in the Promoter admin interface.
*
* @deprecated 2.3 -- We're moving to an HTML form model and this is no longer used directly.
* We still need to move the Campaign manager to HTMLForm though and so this still exists for
* that part of CN.
*/
class AdPager extends ReverseChronologicalPager {
protected $onRemoveChange, $viewPage, $special;
protected $editable;
protected $filter;
function __construct( $special, $filter = '' ) {
$this->special = $special;
$this->editable = $special->editable;
$this->filter = $filter;
parent::__construct();
// Override paging defaults
list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset( 20, '' );
$this->mLimitsShown = [ 20, 50, 100 ];
$msg = Xml::encodeJsVar( $this->msg( 'promoter-confirm-delete' )->text() );
$this->onRemoveChange = "if( this.checked ) { this.checked = confirm( $msg ) }";
$this->viewPage = SpecialPage::getTitleFor( 'CampaignAd', 'view' );
}
/**
* Set the database query to retrieve all the ads in the database
*
* @return array of query settings
*/
function getQueryInfo() {
$dbr = PRDatabase::getDb();
// When the filter comes in it is space delimited, so break that...
$likeArray = preg_split( '/\s/', $this->filter );
// ...and then insert all the wildcards betwean search terms
if ( empty( $likeArray ) ) {
$likeArray = $dbr->anyString();
} else {
$anyStringToken = $dbr->anyString();
$tempArray = [ $anyStringToken ];
foreach ( $likeArray as $likePart ) {
$tempArray[ ] = $likePart;
$tempArray[ ] = $anyStringToken;
}
$likeArray = $tempArray;
}
return [
'tables' => [ 'ads' => 'pr_ads' ],
'fields' => [ 'ads.ad_name', 'ads.ad_id' ],
'conds' => [ 'ads.ad_name' . $dbr->buildLike( $likeArray ) ],
];
}
/**
* Sort the ad list by ad_id (generally equals reverse chronological)
*
* @return string
*/
function getIndexField() {
return 'ads.ad_id';
}
/**
* Generate the content of each table row (1 row = 1 ad)
*
* @param $row object: database row
*
* @return string HTML
* @throws AdDataException
*/
function formatRow( $row ) {
// Begin ad row
$htmlOut = Xml::openElement( 'tr' );
if ( $this->editable ) {
// Remove box
$htmlOut .= Xml::tags( 'td', [ 'valign' => 'top' ],
Xml::check( 'removeAds[]', false,
[
'value' => $row->ad_name,
'onchange' => $this->onRemoveChange
]
)
);
}
// Preview
$ad = Ad::fromName( $row->ad_name );
$htmlOut .= Xml::tags( 'td', [ 'valign' => 'top' ],
$ad->linkToPreview()
);
// End ad row
$htmlOut .= Xml::closeElement( 'tr' );
return $htmlOut;
}
/**
* Specify table headers
*
* @return string HTML
*/
function getStartBody() {
$htmlOut = '';
$htmlOut .= Xml::openElement( 'table', [ 'cellpadding' => 9 ] );
$htmlOut .= Xml::openElement( 'tr' );
if ( $this->editable ) {
$htmlOut .= Xml::element( 'th', [ 'align' => 'left', 'width' => '5%' ],
$this->msg( 'promoter-remove' )->text()
);
}
$htmlOut .= Xml::element( 'th', [ 'align' => 'left' ],
$this->msg( 'promoter-ads' )->text()
);
$htmlOut .= Xml::closeElement( 'tr' );
return $htmlOut;
}
/**
* Close table and add Submit button
*
* @return string HTML
*/
function getEndBody() {
$htmlOut = '';
$htmlOut .= Xml::closeElement( 'table' );
if ( $this->editable ) {
$htmlOut .= Html::hidden( 'authtoken', $this->getUser()->getEditToken() );
$htmlOut .= Xml::tags( 'div',
[ 'class' => 'pr-buttons' ],
Xml::submitButton( $this->msg( 'promoter-modify' )->text() )
);
}
return $htmlOut;
}
}