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