3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 * Page for displaying list of financial types
22 class CRM_PCP_Page_PCP
extends CRM_Core_Page_Basic
{
25 * The action links that we need to display for the browse screen.
29 public static $_links = NULL;
37 public function getBAOName() {
38 return 'CRM_PCP_BAO_PCP';
45 * (reference) of action links
47 public function &links() {
48 if (!(self
::$_links)) {
49 // helper variable for nicer formatting
50 $deleteExtra = ts('Are you sure you want to delete this Campaign Page ?');
53 CRM_Core_Action
::UPDATE
=> [
55 'url' => 'civicrm/pcp/info',
56 'qs' => 'action=update&reset=1&id=%%id%%&context=dashboard',
57 'title' => ts('Edit Personal Campaign Page'),
59 CRM_Core_Action
::RENEW
=> [
60 'name' => ts('Approve'),
61 'url' => 'civicrm/admin/pcp',
62 'qs' => 'action=renew&id=%%id%%',
63 'title' => ts('Approve Personal Campaign Page'),
65 CRM_Core_Action
::REVERT
=> [
66 'name' => ts('Reject'),
67 'url' => 'civicrm/admin/pcp',
68 'qs' => 'action=revert&id=%%id%%',
69 'title' => ts('Reject Personal Campaign Page'),
71 CRM_Core_Action
::DELETE
=> [
72 'name' => ts('Delete'),
73 'url' => 'civicrm/admin/pcp',
74 'qs' => 'action=delete&id=%%id%%',
75 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
76 'title' => ts('Delete Personal Campaign Page'),
78 CRM_Core_Action
::ENABLE
=> [
79 'name' => ts('Enable'),
80 'url' => 'civicrm/admin/pcp',
81 'qs' => 'action=enable&id=%%id%%',
82 'title' => ts('Enable'),
84 CRM_Core_Action
::DISABLE
=> [
85 'name' => ts('Disable'),
86 'url' => 'civicrm/admin/pcp',
87 'qs' => 'action=disable&id=%%id%%',
88 'title' => ts('Disable'),
98 * This method is called after the page is created. It checks for the
99 * type of action and executes that action.
100 * Finally it calls the parent's run method.
103 * @throws \CRM_Core_Exception
105 public function run() {
106 $id = $this->getIdAndAction();
108 if ($this->_action
& CRM_Core_Action
::REVERT
) {
109 CRM_PCP_BAO_PCP
::setIsActive($id, 0);
110 $session = CRM_Core_Session
::singleton();
111 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
113 elseif ($this->_action
& CRM_Core_Action
::RENEW
) {
114 CRM_PCP_BAO_PCP
::setIsActive($id, 1);
115 $session = CRM_Core_Session
::singleton();
116 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
118 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
119 $session = CRM_Core_Session
::singleton();
120 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&action=browse'));
121 $controller = new CRM_Core_Controller_Simple('CRM_PCP_Form_PCP',
122 'Personal Campaign Page',
123 CRM_Core_Action
::DELETE
125 //$this->setContext( $id, $action );
126 $controller->set('id', $id);
127 $controller->process();
128 return $controller->run();
135 CRM_Core_Page
::run();
139 * Browse all custom data groups.
143 * @throws \CRM_Core_Exception
145 public function browse($action = NULL) {
146 CRM_Core_Resources
::singleton()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
148 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
152 if ($this->_sortByCharacter
== 1 ||
155 $this->_sortByCharacter
= '';
158 $status = CRM_PCP_BAO_PCP
::buildOptions('status_id', 'create');
160 $pcpSummary = $params = [];
163 if (!empty($_POST) ||
!empty($_GET['page_type'])) {
164 if (!empty($_POST['status_id'])) {
165 $whereClause = ' AND cp.status_id = %1';
166 $params['1'] = [$_POST['status_id'], 'Integer'];
169 if (!empty($_POST['page_type'])) {
170 $whereClause .= ' AND cp.page_type = %2';
171 $params['2'] = [$_POST['page_type'], 'String'];
173 elseif (!empty($_GET['page_type'])) {
174 $whereClause .= ' AND cp.page_type = %2';
175 $params['2'] = [$_GET['page_type'], 'String'];
178 if (!empty($_POST['page_id'])) {
179 $whereClause .= ' AND cp.page_id = %4 AND cp.page_type = "contribute"';
180 $params['4'] = [$_POST['page_id'], 'Integer'];
183 if (!empty($_POST['event_id'])) {
184 $whereClause .= ' AND cp.page_id = %5 AND cp.page_type = "event"';
185 $params['5'] = [$_POST['event_id'], 'Integer'];
189 $this->set('whereClause', $whereClause);
190 $this->set('params', $params);
193 $this->set('whereClause', NULL);
194 $this->set('params', NULL);
198 $approvedId = CRM_Core_PseudoConstant
::getKey('CRM_PCP_BAO_PCP', 'status_id', 'Approved');
200 //check for delete CRM-4418
201 $allowToDelete = CRM_Core_Permission
::check('delete in CiviContribute');
203 // get all contribution pages
204 $query = "SELECT id, title, start_date, end_date FROM civicrm_contribution_page WHERE (1)";
205 $cpages = CRM_Core_DAO
::executeQuery($query);
206 while ($cpages->fetch()) {
207 $pages['contribute'][$cpages->id
]['id'] = $cpages->id
;
208 $pages['contribute'][$cpages->id
]['title'] = $cpages->title
;
209 $pages['contribute'][$cpages->id
]['start_date'] = $cpages->start_date
;
210 $pages['contribute'][$cpages->id
]['end_date'] = $cpages->end_date
;
213 // get all event pages. pcp campaign start and end dates for event related pcp's use the online registration start and end dates,
214 // although if target is contribution page this might not be correct. fixme? dgg
215 $query = "SELECT id, title, start_date, end_date, registration_start_date, registration_end_date
217 WHERE is_template IS NULL OR is_template != 1";
218 $epages = CRM_Core_DAO
::executeQuery($query);
219 while ($epages->fetch()) {
220 $pages['event'][$epages->id
]['id'] = $epages->id
;
221 $pages['event'][$epages->id
]['title'] = $epages->title
;
222 $pages['event'][$epages->id
]['start_date'] = $epages->registration_start_date
;
223 $pages['event'][$epages->id
]['end_date'] = $epages->registration_end_date
;
226 $params = $this->get('params') ?
$this->get('params') : [];
229 if ($this->_sortByCharacter
!== NULL) {
230 $clauses[] = "cp.title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
234 SELECT cp.id, cp.contact_id , cp.status_id, cp.title, cp.is_active, cp.page_type, cp.page_id
236 WHERE $title" . $this->get('whereClause') . " ORDER BY cp.status_id";
238 $pcp = CRM_Core_DAO
::executeQuery($query, $params);
239 while ($pcp->fetch()) {
240 $action = array_sum(array_keys($this->links()));
241 $contact = CRM_Contact_BAO_Contact
::getDisplayAndImage($pcp->contact_id
);
245 if ($pcp->status_id
!= $approvedId ||
$pcp->is_active
!= 1) {
249 switch ($pcp->status_id
) {
251 $action -= CRM_Core_Action
::RENEW
;
255 $action -= CRM_Core_Action
::REVERT
;
259 switch ($pcp->is_active
) {
261 $action -= CRM_Core_Action
::ENABLE
;
265 $action -= CRM_Core_Action
::DISABLE
;
269 if (!$allowToDelete) {
270 $action -= CRM_Core_Action
::DELETE
;
273 $page_type = $pcp->page_type
;
274 $page_id = (int) $pcp->page_id
;
275 if ($pages[$page_type][$page_id]['title'] == '' ||
$pages[$page_type][$page_id]['title'] == NULL) {
276 $title = '(no title found for ' . $page_type . ' id ' . $page_id . ')';
279 $title = $pages[$page_type][$page_id]['title'];
282 if ($pcp->page_type
== 'contribute') {
283 $pageUrl = CRM_Utils_System
::url('civicrm/' . $page_type . '/transact', 'reset=1&id=' . $pcp->page_id
);
286 $pageUrl = CRM_Utils_System
::url('civicrm/' . $page_type . '/register', 'reset=1&id=' . $pcp->page_id
);
289 $pcpSummary[$pcp->id
] = [
291 'start_date' => $pages[$page_type][$page_id]['start_date'],
292 'end_date' => $pages[$page_type][$page_id]['end_date'],
293 'supporter' => $contact['0'],
294 'supporter_id' => $pcp->contact_id
,
295 'status_id' => $status[$pcp->status_id
],
296 'page_id' => $page_id,
297 'page_title' => $title,
298 'page_url' => $pageUrl,
299 'page_type' => $page_type,
300 'action' => CRM_Core_Action
::formLink(self
::links(), $action,
301 ['id' => $pcp->id
], ts('more'), FALSE, 'contributionpage.pcp.list', 'PCP', $pcp->id
303 'title' => $pcp->title
,
309 $this->pagerAToZ($this->get('whereClause'), $params);
311 $this->assign('rows', $pcpSummary);
313 // Let template know if user has run a search or not
314 if ($this->get('whereClause')) {
315 $this->assign('isSearch', 1);
318 $this->assign('isSearch', 0);
322 public function search() {
323 if ($this->_action
& CRM_Core_Action
::DELETE
) {
327 $form = new CRM_Core_Controller_Simple('CRM_PCP_Form_PCP', ts('Search Campaign Pages'), CRM_Core_Action
::ADD
);
328 $form->setEmbedded(TRUE);
329 $form->setParent($this);
335 * Get name of edit form.
338 * Classname of edit form.
340 public function editForm() {
341 return 'CRM_PCP_Form_PCP';
345 * Get edit form name.
350 public function editName() {
351 return ts('Personal Campaign Page');
362 public function userContext($mode = NULL) {
363 return 'civicrm/admin/pcp';
367 * @TODO this function changed, debug this at runtime
368 * @param $whereClause
369 * @param array $whereParams
371 public function pagerAtoZ($whereClause, $whereParams) {
374 if (strpos($whereClause, ' AND') == 0) {
375 $whereClause = substr($whereClause, 4);
377 $where = 'WHERE ' . $whereClause;
381 SELECT UPPER(LEFT(cp.title, 1)) as sort_name
384 ORDER BY LEFT(cp.title, 1);
387 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
389 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
390 $this->assign('aToZ', $aToZBar);