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
19 * Page for displaying list of financial types
21 class CRM_PCP_Page_PCP
extends CRM_Core_Page_Basic
{
24 * The action links that we need to display for the browse screen.
28 public static $_links = NULL;
36 public function getBAOName() {
37 return 'CRM_PCP_BAO_PCP';
44 * (reference) of action links
46 public function &links() {
47 if (!(self
::$_links)) {
48 // helper variable for nicer formatting
49 $deleteExtra = ts('Are you sure you want to delete this Campaign Page ?');
52 CRM_Core_Action
::UPDATE
=> [
54 'url' => 'civicrm/pcp/info',
55 'qs' => 'action=update&reset=1&id=%%id%%&context=dashboard',
56 'title' => ts('Edit Personal Campaign Page'),
58 CRM_Core_Action
::RENEW
=> [
59 'name' => ts('Approve'),
60 'url' => 'civicrm/admin/pcp',
61 'qs' => 'action=renew&id=%%id%%',
62 'title' => ts('Approve Personal Campaign Page'),
64 CRM_Core_Action
::REVERT
=> [
65 'name' => ts('Reject'),
66 'url' => 'civicrm/admin/pcp',
67 'qs' => 'action=revert&id=%%id%%',
68 'title' => ts('Reject Personal Campaign Page'),
70 CRM_Core_Action
::DELETE
=> [
71 'name' => ts('Delete'),
72 'url' => 'civicrm/admin/pcp',
73 'qs' => 'action=delete&id=%%id%%',
74 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
75 'title' => ts('Delete Personal Campaign Page'),
77 CRM_Core_Action
::ENABLE
=> [
78 'name' => ts('Enable'),
79 'url' => 'civicrm/admin/pcp',
80 'qs' => 'action=enable&id=%%id%%',
81 'title' => ts('Enable'),
83 CRM_Core_Action
::DISABLE
=> [
84 'name' => ts('Disable'),
85 'url' => 'civicrm/admin/pcp',
86 'qs' => 'action=disable&id=%%id%%',
87 'title' => ts('Disable'),
97 * This method is called after the page is created. It checks for the
98 * type of action and executes that action.
99 * Finally it calls the parent's run method.
102 * @throws \CRM_Core_Exception
104 public function run() {
105 $id = $this->getIdAndAction();
107 if ($this->_action
& CRM_Core_Action
::REVERT
) {
108 CRM_PCP_BAO_PCP
::setIsActive($id, 0);
109 $session = CRM_Core_Session
::singleton();
110 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
112 elseif ($this->_action
& CRM_Core_Action
::RENEW
) {
113 CRM_PCP_BAO_PCP
::setIsActive($id, 1);
114 $session = CRM_Core_Session
::singleton();
115 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
117 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
118 $session = CRM_Core_Session
::singleton();
119 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&action=browse'));
120 $controller = new CRM_Core_Controller_Simple('CRM_PCP_Form_PCP',
121 'Personal Campaign Page',
122 CRM_Core_Action
::DELETE
124 //$this->setContext( $id, $action );
125 $controller->set('id', $id);
126 $controller->process();
127 return $controller->run();
134 CRM_Core_Page
::run();
138 * Browse all custom data groups.
142 * @throws \CRM_Core_Exception
144 public function browse($action = NULL) {
145 CRM_Core_Resources
::singleton()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
147 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
151 if ($this->_sortByCharacter
== 1 ||
154 $this->_sortByCharacter
= '';
157 $status = CRM_PCP_BAO_PCP
::buildOptions('status_id', 'create');
159 $pcpSummary = $params = [];
162 if (!empty($_POST) ||
!empty($_GET['page_type'])) {
163 if (!empty($_POST['status_id'])) {
164 $whereClause = ' AND cp.status_id = %1';
165 $params['1'] = [$_POST['status_id'], 'Integer'];
168 if (!empty($_POST['page_type'])) {
169 $whereClause .= ' AND cp.page_type = %2';
170 $params['2'] = [$_POST['page_type'], 'String'];
172 elseif (!empty($_GET['page_type'])) {
173 $whereClause .= ' AND cp.page_type = %2';
174 $params['2'] = [$_GET['page_type'], 'String'];
177 if (!empty($_POST['page_id'])) {
178 $whereClause .= ' AND cp.page_id = %4 AND cp.page_type = "contribute"';
179 $params['4'] = [$_POST['page_id'], 'Integer'];
182 if (!empty($_POST['event_id'])) {
183 $whereClause .= ' AND cp.page_id = %5 AND cp.page_type = "event"';
184 $params['5'] = [$_POST['event_id'], 'Integer'];
188 $this->set('whereClause', $whereClause);
189 $this->set('params', $params);
192 $this->set('whereClause', NULL);
193 $this->set('params', NULL);
197 $approvedId = CRM_Core_PseudoConstant
::getKey('CRM_PCP_BAO_PCP', 'status_id', 'Approved');
199 //check for delete CRM-4418
200 $allowToDelete = CRM_Core_Permission
::check('delete in CiviContribute');
202 // get all contribution pages
203 $query = "SELECT id, title, start_date, end_date FROM civicrm_contribution_page WHERE (1)";
204 $cpages = CRM_Core_DAO
::executeQuery($query);
205 while ($cpages->fetch()) {
206 $pages['contribute'][$cpages->id
]['id'] = $cpages->id
;
207 $pages['contribute'][$cpages->id
]['title'] = $cpages->title
;
208 $pages['contribute'][$cpages->id
]['start_date'] = $cpages->start_date
;
209 $pages['contribute'][$cpages->id
]['end_date'] = $cpages->end_date
;
212 // get all event pages. pcp campaign start and end dates for event related pcp's use the online registration start and end dates,
213 // although if target is contribution page this might not be correct. fixme? dgg
214 $query = "SELECT id, title, start_date, end_date, registration_start_date, registration_end_date
216 WHERE is_template IS NULL OR is_template != 1";
217 $epages = CRM_Core_DAO
::executeQuery($query);
218 while ($epages->fetch()) {
219 $pages['event'][$epages->id
]['id'] = $epages->id
;
220 $pages['event'][$epages->id
]['title'] = $epages->title
;
221 $pages['event'][$epages->id
]['start_date'] = $epages->registration_start_date
;
222 $pages['event'][$epages->id
]['end_date'] = $epages->registration_end_date
;
225 $params = $this->get('params') ?
$this->get('params') : [];
228 if ($this->_sortByCharacter
!== NULL) {
229 $clauses[] = "cp.title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
233 SELECT cp.id, cp.contact_id , cp.status_id, cp.title, cp.is_active, cp.page_type, cp.page_id
235 WHERE $title" . $this->get('whereClause') . " ORDER BY cp.status_id";
237 $pcp = CRM_Core_DAO
::executeQuery($query, $params);
238 while ($pcp->fetch()) {
239 $action = array_sum(array_keys($this->links()));
240 $contact = CRM_Contact_BAO_Contact
::getDisplayAndImage($pcp->contact_id
);
244 if ($pcp->status_id
!= $approvedId ||
$pcp->is_active
!= 1) {
248 switch ($pcp->status_id
) {
250 $action -= CRM_Core_Action
::RENEW
;
254 $action -= CRM_Core_Action
::REVERT
;
258 switch ($pcp->is_active
) {
260 $action -= CRM_Core_Action
::ENABLE
;
264 $action -= CRM_Core_Action
::DISABLE
;
268 if (!$allowToDelete) {
269 $action -= CRM_Core_Action
::DELETE
;
272 $page_type = $pcp->page_type
;
273 $page_id = (int) $pcp->page_id
;
274 if ($pages[$page_type][$page_id]['title'] == '' ||
$pages[$page_type][$page_id]['title'] == NULL) {
275 $title = '(no title found for ' . $page_type . ' id ' . $page_id . ')';
278 $title = $pages[$page_type][$page_id]['title'];
281 if ($pcp->page_type
== 'contribute') {
282 $pageUrl = CRM_Utils_System
::url('civicrm/' . $page_type . '/transact', 'reset=1&id=' . $pcp->page_id
);
285 $pageUrl = CRM_Utils_System
::url('civicrm/' . $page_type . '/register', 'reset=1&id=' . $pcp->page_id
);
288 $pcpSummary[$pcp->id
] = [
290 'start_date' => $pages[$page_type][$page_id]['start_date'],
291 'end_date' => $pages[$page_type][$page_id]['end_date'],
292 'supporter' => $contact['0'],
293 'supporter_id' => $pcp->contact_id
,
294 'status_id' => $status[$pcp->status_id
],
295 'page_id' => $page_id,
296 'page_title' => $title,
297 'page_url' => $pageUrl,
298 'page_type' => $page_type,
299 'action' => CRM_Core_Action
::formLink(self
::links(), $action,
300 ['id' => $pcp->id
], ts('more'), FALSE, 'contributionpage.pcp.list', 'PCP', $pcp->id
302 'title' => $pcp->title
,
308 $this->pagerAToZ($this->get('whereClause'), $params);
310 $this->assign('rows', $pcpSummary);
312 // Let template know if user has run a search or not
313 if ($this->get('whereClause')) {
314 $this->assign('isSearch', 1);
317 $this->assign('isSearch', 0);
321 public function search() {
322 if ($this->_action
& CRM_Core_Action
::DELETE
) {
326 $form = new CRM_Core_Controller_Simple('CRM_PCP_Form_PCP', ts('Search Campaign Pages'), CRM_Core_Action
::ADD
);
327 $form->setEmbedded(TRUE);
328 $form->setParent($this);
334 * Get name of edit form.
337 * Classname of edit form.
339 public function editForm() {
340 return 'CRM_PCP_Form_PCP';
344 * Get edit form name.
349 public function editName() {
350 return ts('Personal Campaign Page');
361 public function userContext($mode = NULL) {
362 return 'civicrm/admin/pcp';
366 * @TODO this function changed, debug this at runtime
367 * @param $whereClause
368 * @param array $whereParams
370 public function pagerAtoZ($whereClause, $whereParams) {
373 if (strpos($whereClause, ' AND') == 0) {
374 $whereClause = substr($whereClause, 4);
376 $where = 'WHERE ' . $whereClause;
380 SELECT UPPER(LEFT(cp.title, 1)) as sort_name
383 ORDER BY LEFT(cp.title, 1);
386 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
388 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
389 $this->assign('aToZ', $aToZBar);