Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * Create a page for displaying Contribute Pages | |
20 | * Contribute Pages are pages that are used to display | |
21 | * contributions of different types. Pages consist | |
22 | * of many customizable sections which can be | |
23 | * accessed. | |
24 | * | |
25 | * This page provides a top level browse view | |
26 | * of all the contribution pages in the system. | |
27 | * | |
28 | */ | |
29 | class CRM_Contribute_Page_ContributionPage extends CRM_Core_Page { | |
30 | ||
31 | /** | |
fe482240 | 32 | * The action links that we need to display for the browse screen. |
6a488035 TO |
33 | * |
34 | * @var array | |
35 | */ | |
36 | private static $_actionLinks; | |
37 | private static $_contributionLinks; | |
38 | private static $_configureActionLinks; | |
39 | private static $_onlineContributionLinks; | |
40 | ||
4bf0b605 AH |
41 | /** |
42 | * @var CRM_Utils_Pager | |
43 | */ | |
6a488035 TO |
44 | protected $_pager = NULL; |
45 | ||
4bf0b605 AH |
46 | /** |
47 | * @var string | |
48 | */ | |
6a488035 TO |
49 | protected $_sortByCharacter; |
50 | ||
51 | /** | |
52 | * Get the action links for this page. | |
53 | * | |
a3379cc1 AH |
54 | * @return array |
55 | */ | |
d1424f8f | 56 | public static function &actionLinks() { |
6a488035 TO |
57 | // check if variable _actionsLinks is populated |
58 | if (!isset(self::$_actionLinks)) { | |
59 | // helper variable for nicer formatting | |
60 | $deleteExtra = ts('Are you sure you want to delete this Contribution page?'); | |
61 | $copyExtra = ts('Are you sure you want to make a copy of this Contribution page?'); | |
62 | ||
63 | self::$_actionLinks = array( | |
64 | CRM_Core_Action::COPY => array( | |
65 | 'name' => ts('Make a Copy'), | |
66 | 'url' => CRM_Utils_System::currentPath(), | |
67 | 'qs' => 'action=copy&gid=%%id%%', | |
68 | 'title' => ts('Make a Copy of CiviCRM Contribution Page'), | |
69 | 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"', | |
70 | ), | |
71 | CRM_Core_Action::DISABLE => array( | |
72 | 'name' => ts('Disable'), | |
73 | 'title' => ts('Disable'), | |
4d17a233 | 74 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
75 | ), |
76 | CRM_Core_Action::ENABLE => array( | |
77 | 'name' => ts('Enable'), | |
4d17a233 | 78 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
79 | 'title' => ts('Enable'), |
80 | ), | |
81 | CRM_Core_Action::DELETE => array( | |
82 | 'name' => ts('Delete'), | |
83 | 'url' => CRM_Utils_System::currentPath(), | |
84 | 'qs' => 'action=delete&reset=1&id=%%id%%', | |
85 | 'title' => ts('Delete Custom Field'), | |
86 | 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"', | |
87 | ), | |
88 | ); | |
89 | } | |
90 | return self::$_actionLinks; | |
91 | } | |
92 | ||
93 | /** | |
94 | * Get the configure action links for this page. | |
95 | * | |
a3379cc1 | 96 | * @return array |
6a488035 | 97 | */ |
00be9182 | 98 | public function &configureActionLinks() { |
6a488035 TO |
99 | // check if variable _actionsLinks is populated |
100 | if (!isset(self::$_configureActionLinks)) { | |
101 | $urlString = 'civicrm/admin/contribute/'; | |
102 | $urlParams = 'reset=1&action=update&id=%%id%%'; | |
103 | ||
104 | self::$_configureActionLinks = array( | |
105 | CRM_Core_Action::ADD => array( | |
106 | 'name' => ts('Title and Settings'), | |
107 | 'title' => ts('Title and Settings'), | |
108 | 'url' => $urlString . 'settings', | |
109 | 'qs' => $urlParams, | |
110 | 'uniqueName' => 'settings', | |
111 | ), | |
112 | CRM_Core_Action::UPDATE => array( | |
113 | 'name' => ts('Contribution Amounts'), | |
114 | 'title' => ts('Contribution Amounts'), | |
115 | 'url' => $urlString . 'amount', | |
116 | 'qs' => $urlParams, | |
117 | 'uniqueName' => 'amount', | |
118 | ), | |
119 | CRM_Core_Action::VIEW => array( | |
120 | 'name' => ts('Membership Settings'), | |
121 | 'title' => ts('Membership Settings'), | |
122 | 'url' => $urlString . 'membership', | |
123 | 'qs' => $urlParams, | |
124 | 'uniqueName' => 'membership', | |
125 | ), | |
126 | CRM_Core_Action::EXPORT => array( | |
127 | 'name' => ts('Thank-you and Receipting'), | |
128 | 'title' => ts('Thank-you and Receipting'), | |
129 | 'url' => $urlString . 'thankyou', | |
130 | 'qs' => $urlParams, | |
131 | 'uniqueName' => 'thankyou', | |
132 | ), | |
133 | CRM_Core_Action::BASIC => array( | |
134 | 'name' => ts('Tell a Friend'), | |
135 | 'title' => ts('Tell a Friend'), | |
136 | 'url' => $urlString . 'friend', | |
137 | 'qs' => $urlParams, | |
138 | 'uniqueName' => 'friend', | |
139 | ), | |
140 | CRM_Core_Action::PROFILE => array( | |
141 | 'name' => ts('Include Profiles'), | |
142 | 'title' => ts('Include Profiles'), | |
143 | 'url' => $urlString . 'custom', | |
144 | 'qs' => $urlParams, | |
145 | 'uniqueName' => 'custom', | |
146 | ), | |
147 | CRM_Core_Action::MAP => array( | |
148 | 'name' => ts('Contribution Widget'), | |
149 | 'title' => ts('Contribution Widget'), | |
150 | 'url' => $urlString . 'widget', | |
151 | 'qs' => $urlParams, | |
152 | 'uniqueName' => 'widget', | |
153 | ), | |
154 | CRM_Core_Action::FOLLOWUP => array( | |
155 | 'name' => ts('Premiums'), | |
156 | 'title' => ts('Premiums'), | |
157 | 'url' => $urlString . 'premium', | |
158 | 'qs' => $urlParams, | |
159 | 'uniqueName' => 'premium', | |
160 | ), | |
161 | CRM_Core_Action::ADVANCED => array( | |
162 | 'name' => ts('Personal Campaign Pages'), | |
163 | 'title' => ts('Personal Campaign Pages'), | |
164 | 'url' => $urlString . 'pcp', | |
165 | 'qs' => $urlParams, | |
166 | 'uniqueName' => 'pcp', | |
167 | ), | |
168 | ); | |
48fe48a6 | 169 | $context = array( |
170 | 'urlString' => $urlString, | |
f413512f | 171 | 'urlParams' => $urlParams, |
48fe48a6 | 172 | ); |
173 | CRM_Utils_Hook::tabset('civicrm/admin/contribute', self::$_configureActionLinks, $context); | |
6a488035 TO |
174 | } |
175 | ||
176 | return self::$_configureActionLinks; | |
177 | } | |
178 | ||
179 | /** | |
180 | * Get the online contribution links. | |
181 | * | |
a3379cc1 | 182 | * @return array |
6a488035 | 183 | */ |
00be9182 | 184 | public function &onlineContributionLinks() { |
6a488035 TO |
185 | if (!isset(self::$_onlineContributionLinks)) { |
186 | $urlString = 'civicrm/contribute/transact'; | |
187 | $urlParams = 'reset=1&id=%%id%%'; | |
188 | self::$_onlineContributionLinks = array( | |
189 | CRM_Core_Action::RENEW => array( | |
190 | 'name' => ts('Live Page'), | |
191 | 'title' => ts('Live Page'), | |
192 | 'url' => $urlString, | |
193 | 'qs' => $urlParams, | |
194 | 'fe' => TRUE, | |
195 | 'uniqueName' => 'live_page', | |
196 | ), | |
197 | CRM_Core_Action::PREVIEW => array( | |
198 | 'name' => ts('Test-drive'), | |
199 | 'title' => ts('Test-drive'), | |
200 | 'url' => $urlString, | |
201 | 'qs' => $urlParams . '&action=preview', | |
1330f57a SL |
202 | // Addresses https://lab.civicrm.org/dev/core/issues/658 |
203 | 'fe' => TRUE, | |
6a488035 TO |
204 | 'uniqueName' => 'test_drive', |
205 | ), | |
206 | ); | |
207 | } | |
208 | ||
209 | return self::$_onlineContributionLinks; | |
210 | } | |
211 | ||
212 | /** | |
213 | * Get the contributions links. | |
214 | * | |
a3379cc1 | 215 | * @return array |
6a488035 | 216 | */ |
00be9182 | 217 | public function &contributionLinks() { |
6a488035 TO |
218 | if (!isset(self::$_contributionLinks)) { |
219 | //get contribution dates. | |
220 | $dates = CRM_Contribute_BAO_Contribution::getContributionDates(); | |
35959bc5 AH |
221 | $now = $dates['now']; |
222 | $yearDate = $dates['yearDate']; | |
223 | $monthDate = $dates['monthDate']; | |
6a488035 TO |
224 | $yearNow = $yearDate + 10000; |
225 | ||
226 | $urlString = 'civicrm/contribute/search'; | |
cd8ae813 | 227 | $urlParams = 'reset=1&contribution_page_id=%%id%%&force=1&test=0'; |
6a488035 TO |
228 | |
229 | self::$_contributionLinks = array( | |
230 | CRM_Core_Action::DETACH => array( | |
231 | 'name' => ts('Current Month-To-Date'), | |
232 | 'title' => ts('Current Month-To-Date'), | |
233 | 'url' => $urlString, | |
103c6822 | 234 | 'qs' => "{$urlParams}&receive_date_low={$monthDate}&receive_date_high={$now}", |
6a488035 TO |
235 | 'uniqueName' => 'current_month_to_date', |
236 | ), | |
237 | CRM_Core_Action::REVERT => array( | |
238 | 'name' => ts('Fiscal Year-To-Date'), | |
239 | 'title' => ts('Fiscal Year-To-Date'), | |
240 | 'url' => $urlString, | |
103c6822 | 241 | 'qs' => "{$urlParams}&receive_date_low={$yearDate}&receive_date_high={$yearNow}", |
6a488035 TO |
242 | 'uniqueName' => 'fiscal_year_to_date', |
243 | ), | |
244 | CRM_Core_Action::BROWSE => array( | |
245 | 'name' => ts('Cumulative'), | |
246 | 'title' => ts('Cumulative'), | |
247 | 'url' => $urlString, | |
4679010f | 248 | 'qs' => "{$urlParams}", |
6a488035 TO |
249 | 'uniqueName' => 'cumulative', |
250 | ), | |
251 | ); | |
252 | } | |
253 | ||
254 | return self::$_contributionLinks; | |
255 | } | |
256 | ||
257 | /** | |
258 | * Run the page. | |
259 | * | |
260 | * This method is called after the page is created. It checks for the | |
261 | * type of action and executes that action. | |
262 | * Finally it calls the parent's run method. | |
263 | * | |
4bf0b605 | 264 | * @return mixed |
6a488035 | 265 | */ |
00be9182 | 266 | public function run() { |
6a488035 TO |
267 | // get the requested action |
268 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
269 | // default to 'browse' | |
270 | $this, FALSE, 'browse' | |
271 | ); | |
272 | ||
273 | // assign vars to templates | |
274 | $this->assign('action', $action); | |
275 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
276 | $this, FALSE, 0 | |
277 | ); | |
278 | ||
279 | // set breadcrumb to append to 2nd layer pages | |
353ffa53 TO |
280 | $breadCrumb = array( |
281 | array( | |
282 | 'title' => ts('Manage Contribution Pages'), | |
6a488035 TO |
283 | 'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(), |
284 | 'reset=1' | |
285 | ), | |
a130e045 | 286 | ), |
353ffa53 | 287 | ); |
6a488035 TO |
288 | |
289 | // what action to take ? | |
290 | if ($action & CRM_Core_Action::ADD) { | |
291 | $session = CRM_Core_Session::singleton(); | |
292 | $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), | |
353ffa53 TO |
293 | 'action=browse&reset=1' |
294 | )); | |
6a488035 TO |
295 | |
296 | $controller = new CRM_Contribute_Controller_ContributionPage(NULL, $action); | |
297 | CRM_Utils_System::setTitle(ts('Manage Contribution Page')); | |
298 | CRM_Utils_System::appendBreadCrumb($breadCrumb); | |
299 | return $controller->run(); | |
300 | } | |
301 | elseif ($action & CRM_Core_Action::UPDATE) { | |
6a488035 TO |
302 | // assign vars to templates |
303 | $this->assign('id', $id); | |
304 | $this->assign('title', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'title')); | |
305 | $this->assign('is_active', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active')); | |
e46f73c7 | 306 | $this->assign('CiviMember', CRM_Core_Component::isEnabled('CiviMember')); |
6a488035 TO |
307 | } |
308 | elseif ($action & CRM_Core_Action::COPY) { | |
d121646d | 309 | // @todo Unused local variable can be safely removed. |
aa344a47 AH |
310 | // But are there any side effects of CRM_Core_Session::singleton() that we |
311 | // need to preserve? | |
6a488035 TO |
312 | $session = CRM_Core_Session::singleton(); |
313 | CRM_Core_Session::setStatus(ts('A copy of the contribution page has been created'), ts('Successfully Copied'), 'success'); | |
314 | $this->copy(); | |
315 | } | |
316 | elseif ($action & CRM_Core_Action::DELETE) { | |
317 | CRM_Utils_System::appendBreadCrumb($breadCrumb); | |
318 | ||
319 | $session = CRM_Core_Session::singleton(); | |
320 | $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), | |
353ffa53 TO |
321 | 'reset=1&action=browse' |
322 | )); | |
6a488035 TO |
323 | |
324 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
325 | $this, FALSE, 0 | |
326 | ); | |
327 | $query = " | |
328 | SELECT ccp.title | |
665e5ec7 | 329 | FROM civicrm_contribution_page ccp |
6a488035 TO |
330 | JOIN civicrm_pcp cp ON ccp.id = cp.page_id |
331 | WHERE cp.page_id = {$id} | |
332 | AND cp.page_type = 'contribute' | |
333 | "; | |
334 | ||
335 | if ($pageTitle = CRM_Core_DAO::singleValueQuery($query)) { | |
336 | CRM_Core_Session::setStatus(ts('The \'%1\' cannot be deleted! You must Delete all Personal Campaign Page(s) related with this contribution page prior to deleting the page.', array(1 => $pageTitle)), ts('Deletion Error'), 'error'); | |
337 | ||
338 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/contribute', 'reset=1')); | |
339 | } | |
340 | ||
341 | $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionPage_Delete', | |
342 | 'Delete Contribution Page', | |
343 | CRM_Core_Action::DELETE | |
344 | ); | |
345 | $controller->set('id', $id); | |
346 | $controller->process(); | |
347 | return $controller->run(); | |
348 | } | |
349 | else { | |
350 | // finally browse the contribution pages | |
351 | $this->browse(); | |
352 | ||
353 | CRM_Utils_System::setTitle(ts('Manage Contribution Pages')); | |
354 | } | |
355 | ||
356 | return parent::run(); | |
357 | } | |
358 | ||
359 | /** | |
347e061b | 360 | * Make a copy of a contribution page, including all the fields in the page. |
6a488035 | 361 | */ |
00be9182 | 362 | public function copy() { |
6a488035 TO |
363 | $gid = CRM_Utils_Request::retrieve('gid', 'Positive', |
364 | $this, TRUE, 0, 'GET' | |
365 | ); | |
366 | ||
697cb7c0 | 367 | $copy = CRM_Contribute_BAO_ContributionPage::copy($gid); |
6a488035 | 368 | |
697cb7c0 J |
369 | $urlString = CRM_Utils_System::currentPath(); |
370 | $urlParams = 'reset=1'; | |
371 | ||
372 | // Redirect to copied contribution page | |
373 | if ($copy->id) { | |
374 | $urlString = 'civicrm/admin/contribute/settings'; | |
375 | $urlParams .= '&action=update&id=' . $copy->id; | |
376 | } | |
377 | ||
378 | CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams)); | |
6a488035 TO |
379 | } |
380 | ||
381 | /** | |
fe482240 | 382 | * Browse all contribution pages. |
6a488035 | 383 | * |
4bf0b605 AH |
384 | * @param mixed $action |
385 | * Unused parameter. | |
6a488035 | 386 | */ |
00be9182 | 387 | public function browse($action = NULL) { |
734b09fb CW |
388 | Civi::resources()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header'); |
389 | ||
6a488035 TO |
390 | $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', |
391 | 'String', | |
392 | $this | |
393 | ); | |
d121646d | 394 | // @todo Unused local variable can be safely removed. |
aa344a47 AH |
395 | // But are there any side effects of CRM_Utils_Request::retrieve() that we |
396 | // need to preserve? | |
6a488035 TO |
397 | $createdId = CRM_Utils_Request::retrieve('cid', 'Positive', |
398 | $this, FALSE, 0 | |
399 | ); | |
400 | ||
2a81202b | 401 | if ($this->_sortByCharacter == 'all' || |
6a488035 TO |
402 | !empty($_POST) |
403 | ) { | |
404 | $this->_sortByCharacter = ''; | |
405 | $this->set('sortByCharacter', ''); | |
406 | } | |
407 | ||
408 | $this->search(); | |
409 | ||
affcc9d2 | 410 | $params = []; |
6a488035 TO |
411 | |
412 | $whereClause = $this->whereClause($params, FALSE); | |
1bb74559 | 413 | $config = CRM_Core_Config::singleton(); |
414 | if ($config->includeAlphabeticalPager) { | |
415 | $this->pagerAToZ($whereClause, $params); | |
416 | } | |
affcc9d2 | 417 | $params = []; |
6a488035 TO |
418 | $whereClause = $this->whereClause($params, TRUE); |
419 | $this->pager($whereClause, $params); | |
420 | ||
421 | list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount(); | |
422 | ||
423 | //check for delete CRM-4418 | |
424 | $allowToDelete = CRM_Core_Permission::check('delete in CiviContribute'); | |
425 | ||
426 | $query = " | |
427 | SELECT id | |
428 | FROM civicrm_contribution_page | |
429 | WHERE $whereClause | |
2a81202b | 430 | ORDER BY is_active desc, title asc |
6a488035 TO |
431 | LIMIT $offset, $rowCount"; |
432 | $contribPage = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage'); | |
affcc9d2 | 433 | $contribPageIds = []; |
6a488035 TO |
434 | while ($contribPage->fetch()) { |
435 | $contribPageIds[$contribPage->id] = $contribPage->id; | |
436 | } | |
437 | //get all section info. | |
438 | $contriPageSectionInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo($contribPageIds); | |
439 | ||
440 | $query = " | |
441 | SELECT * | |
442 | FROM civicrm_contribution_page | |
443 | WHERE $whereClause | |
2a81202b | 444 | ORDER BY is_active desc, title asc |
6a488035 TO |
445 | LIMIT $offset, $rowCount"; |
446 | ||
447 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage'); | |
448 | ||
449 | //get all campaigns. | |
450 | $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); | |
451 | ||
452 | //get configure actions links. | |
453 | $configureActionLinks = self::configureActionLinks(); | |
454 | ||
5c0de104 | 455 | $contributions = []; |
6a488035 | 456 | while ($dao->fetch()) { |
5c0de104 BT |
457 | $contributions[$dao->id] = []; |
458 | CRM_Core_DAO::storeValues($dao, $contributions[$dao->id]); | |
6a488035 TO |
459 | |
460 | // form all action links | |
d1424f8f | 461 | $action = array_sum(array_keys(self::actionLinks())); |
6a488035 TO |
462 | |
463 | //add configure actions links. | |
464 | $action += array_sum(array_keys($configureActionLinks)); | |
465 | ||
466 | //add online contribution links. | |
467 | $action += array_sum(array_keys(self::onlineContributionLinks())); | |
468 | ||
469 | //add contribution search links. | |
470 | $action += array_sum(array_keys(self::contributionLinks())); | |
471 | ||
472 | if ($dao->is_active) { | |
874c9be7 | 473 | $action -= (int) CRM_Core_Action::ENABLE; |
6a488035 TO |
474 | } |
475 | else { | |
874c9be7 | 476 | $action -= (int) CRM_Core_Action::DISABLE; |
6a488035 TO |
477 | } |
478 | ||
479 | //CRM-4418 | |
480 | if (!$allowToDelete) { | |
874c9be7 | 481 | $action -= (int) CRM_Core_Action::DELETE; |
6a488035 TO |
482 | } |
483 | ||
484 | //build the configure links. | |
affcc9d2 | 485 | $sectionsInfo = CRM_Utils_Array::value($dao->id, $contriPageSectionInfo, []); |
5c0de104 | 486 | $contributions[$dao->id]['configureActionLinks'] = CRM_Core_Action::formLink(self::formatConfigureLinks($sectionsInfo), |
6a488035 TO |
487 | $action, |
488 | array('id' => $dao->id), | |
489 | ts('Configure'), | |
87dab4a4 AH |
490 | TRUE, |
491 | 'contributionpage.configure.actions', | |
492 | 'ContributionPage', | |
493 | $dao->id | |
6a488035 TO |
494 | ); |
495 | ||
496 | //build the contributions links. | |
5c0de104 | 497 | $contributions[$dao->id]['contributionLinks'] = CRM_Core_Action::formLink(self::contributionLinks(), |
6a488035 TO |
498 | $action, |
499 | array('id' => $dao->id), | |
500 | ts('Contributions'), | |
87dab4a4 AH |
501 | TRUE, |
502 | 'contributionpage.contributions.search', | |
503 | 'ContributionPage', | |
504 | $dao->id | |
6a488035 TO |
505 | ); |
506 | ||
507 | //build the online contribution links. | |
5c0de104 | 508 | $contributions[$dao->id]['onlineContributionLinks'] = CRM_Core_Action::formLink(self::onlineContributionLinks(), |
6a488035 TO |
509 | $action, |
510 | array('id' => $dao->id), | |
511 | ts('Links'), | |
87dab4a4 AH |
512 | TRUE, |
513 | 'contributionpage.online.links', | |
514 | 'ContributionPage', | |
515 | $dao->id | |
6a488035 TO |
516 | ); |
517 | ||
518 | //build the normal action links. | |
5c0de104 | 519 | $contributions[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), |
6a488035 TO |
520 | $action, |
521 | array('id' => $dao->id), | |
522 | ts('more'), | |
87dab4a4 AH |
523 | TRUE, |
524 | 'contributionpage.action.links', | |
525 | 'ContributionPage', | |
526 | $dao->id | |
6a488035 TO |
527 | ); |
528 | ||
529 | //show campaigns on selector. | |
5c0de104 | 530 | $contributions[$dao->id]['campaign'] = $allCampaigns[$dao->campaign_id] ?? NULL; |
6a488035 TO |
531 | } |
532 | ||
5c0de104 | 533 | $this->assign('rows', $contributions); |
6a488035 TO |
534 | } |
535 | ||
00be9182 | 536 | public function search() { |
874c9be7 | 537 | if (isset($this->_action) & (CRM_Core_Action::ADD | |
6a488035 TO |
538 | CRM_Core_Action::UPDATE | |
539 | CRM_Core_Action::DELETE | |
540 | ) | |
541 | ) { | |
542 | return; | |
543 | } | |
544 | ||
545 | $form = new CRM_Core_Controller_Simple('CRM_Contribute_Form_SearchContribution', | |
546 | ts('Search Contribution'), | |
547 | CRM_Core_Action::ADD | |
548 | ); | |
549 | $form->setEmbedded(TRUE); | |
550 | $form->setParent($this); | |
551 | $form->process(); | |
552 | $form->run(); | |
553 | } | |
554 | ||
186c9c17 | 555 | /** |
c490a46a | 556 | * @param array $params |
186c9c17 EM |
557 | * @param bool $sortBy |
558 | * | |
559 | * @return int|string | |
560 | */ | |
00be9182 | 561 | public function whereClause(&$params, $sortBy = TRUE) { |
d121646d | 562 | // @todo Unused local variable can be safely removed. |
affcc9d2 | 563 | $values = $clauses = []; |
353ffa53 | 564 | $title = $this->get('title'); |
6a488035 TO |
565 | $createdId = $this->get('cid'); |
566 | ||
567 | if ($createdId) { | |
568 | $clauses[] = "(created_id = {$createdId})"; | |
569 | } | |
570 | ||
571 | if ($title) { | |
572 | $clauses[] = "title LIKE %1"; | |
573 | if (strpos($title, '%') !== FALSE) { | |
574 | $params[1] = array(trim($title), 'String', FALSE); | |
575 | } | |
576 | else { | |
577 | $params[1] = array(trim($title), 'String', TRUE); | |
578 | } | |
579 | } | |
580 | ||
481a74f4 | 581 | $value = $this->get('financial_type_id'); |
affcc9d2 | 582 | $val = []; |
6a488035 TO |
583 | if ($value) { |
584 | if (is_array($value)) { | |
585 | foreach ($value as $k => $v) { | |
586 | if ($v) { | |
587 | $val[$k] = $k; | |
588 | } | |
589 | } | |
590 | $type = implode(',', $val); | |
591 | } | |
d121646d | 592 | // @todo Variable 'type' might not have been defined. |
8b647c3a | 593 | $clauses[] = "financial_type_id IN ({$type})"; |
6a488035 TO |
594 | } |
595 | ||
8b647c3a | 596 | if ($sortBy && $this->_sortByCharacter !== NULL) { |
6a488035 TO |
597 | $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO::escapeWildCardString($this->_sortByCharacter)) . "%'"; |
598 | } | |
599 | ||
a64ad157 | 600 | $campaignIds = $this->getCampaignIds(); |
42f91903 | 601 | if (count($campaignIds) >= 1) { |
a64ad157 AH |
602 | $clauses[] = '( campaign_id IN ( ' . implode(' , ', $campaignIds) . ' ) )'; |
603 | } | |
6a488035 TO |
604 | |
605 | if (empty($clauses)) { | |
606 | // Let template know if user has run a search or not | |
607 | $this->assign('isSearch', 0); | |
608 | return 1; | |
609 | } | |
610 | else { | |
611 | $this->assign('isSearch', 1); | |
612 | } | |
613 | ||
614 | return implode(' AND ', $clauses); | |
615 | } | |
616 | ||
a64ad157 AH |
617 | /** |
618 | * Gets the campaign ids from the session. | |
619 | * | |
620 | * @return int[] | |
621 | */ | |
13efab9d | 622 | public function getCampaignIds() { |
a64ad157 AH |
623 | // The unfiltered value from the session cannot be trusted, it needs to be |
624 | // processed to get a clean array of positive integers. | |
affcc9d2 | 625 | $ids = []; |
874c9be7 TO |
626 | foreach ((array) $this->get('campaign_id') as $id) { |
627 | if ((string) (int) $id === (string) $id && $id > 0) { | |
a64ad157 AH |
628 | $ids[] = $id; |
629 | } | |
630 | } | |
631 | return $ids; | |
632 | } | |
633 | ||
186c9c17 EM |
634 | /** |
635 | * @param $whereClause | |
100fef9d | 636 | * @param array $whereParams |
186c9c17 | 637 | */ |
a130e045 | 638 | public function pager($whereClause, $whereParams) { |
6a488035 TO |
639 | |
640 | $params['status'] = ts('Contribution %%StatusMessage%%'); | |
641 | $params['csvString'] = NULL; | |
642 | $params['buttonTop'] = 'PagerTopButton'; | |
643 | $params['buttonBottom'] = 'PagerBottomButton'; | |
644 | $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT); | |
645 | if (!$params['rowCount']) { | |
7fa7c084 | 646 | $params['rowCount'] = Civi::settings()->get('default_pager_size'); |
6a488035 TO |
647 | } |
648 | ||
649 | $query = " | |
650 | SELECT count(id) | |
8b647c3a AH |
651 | FROM civicrm_contribution_page |
652 | WHERE $whereClause"; | |
6a488035 TO |
653 | |
654 | $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams); | |
655 | ||
656 | $this->_pager = new CRM_Utils_Pager($params); | |
657 | $this->assign_by_ref('pager', $this->_pager); | |
658 | } | |
659 | ||
186c9c17 EM |
660 | /** |
661 | * @param $whereClause | |
100fef9d | 662 | * @param array $whereParams |
186c9c17 | 663 | */ |
00be9182 | 664 | public function pagerAtoZ($whereClause, $whereParams) { |
6a488035 TO |
665 | |
666 | $query = " | |
8b647c3a AH |
667 | SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name |
668 | FROM civicrm_contribution_page | |
669 | WHERE $whereClause | |
bad98dd5 | 670 | ORDER BY UPPER(LEFT(title, 1)) |
6a488035 TO |
671 | "; |
672 | $dao = CRM_Core_DAO::executeQuery($query, $whereParams); | |
673 | ||
674 | $aToZBar = CRM_Utils_PagerAToZ::getAToZBar($dao, $this->_sortByCharacter, TRUE); | |
675 | $this->assign('aToZ', $aToZBar); | |
676 | } | |
677 | ||
186c9c17 | 678 | /** |
8b647c3a | 679 | * @param array $sectionsInfo |
186c9c17 EM |
680 | * |
681 | * @return array | |
682 | */ | |
00be9182 | 683 | public function formatConfigureLinks($sectionsInfo) { |
8b647c3a | 684 | // build the formatted configure links. |
6a488035 TO |
685 | $formattedConfLinks = self::configureActionLinks(); |
686 | foreach ($formattedConfLinks as $act => & $link) { | |
9c1bc317 | 687 | $sectionName = $link['uniqueName'] ?? NULL; |
6a488035 TO |
688 | if (!$sectionName) { |
689 | continue; | |
690 | } | |
691 | ||
a7488080 | 692 | if (empty($sectionsInfo[$sectionName])) { |
affcc9d2 | 693 | $classes = []; |
6a488035 TO |
694 | if (isset($link['class'])) { |
695 | $classes = $link['class']; | |
696 | } | |
697 | $link['class'] = array_merge($classes, array('disabled')); | |
698 | } | |
699 | } | |
700 | ||
701 | return $formattedConfLinks; | |
702 | } | |
96025800 | 703 | |
6a488035 | 704 | } |