Merge pull request #18969 from seamuslee001/dev_core_2187
[civicrm-core.git] / CRM / Event / Page / ParticipantListing / Simple.php
CommitLineData
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 */
17class CRM_Event_Page_ParticipantListing_Simple extends CRM_Core_Page {
18
19 protected $_id;
20
21 protected $_participantListingType;
22
23 protected $_eventTitle;
24
430ae6dd
TO
25 protected $_pager;
26
00be9182 27 public function preProcess() {
6a488035
TO
28 $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this, TRUE);
29
30 // retrieve Event Title and include it in page title
31 $this->_eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
32 $this->_id,
33 'title'
34 );
be2fb01f 35 CRM_Utils_System::setTitle(ts('%1 - Participants', [1 => $this->_eventTitle]));
6a488035
TO
36
37 // we do not want to display recently viewed contacts since this is potentially a public page
38 $this->assign('displayRecent', FALSE);
39 }
40
0cf587a7
EM
41 /**
42 * @return string
43 */
00be9182 44 public function run() {
6a488035
TO
45 $this->preProcess();
46
47 $fromClause = "
48FROM civicrm_contact
03e04002 49INNER JOIN civicrm_participant ON ( civicrm_contact.id = civicrm_participant.contact_id
50 AND civicrm_contact.is_deleted = 0 )
6a488035
TO
51INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id
52LEFT JOIN civicrm_email ON ( civicrm_contact.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1 )
53";
54
55 $whereClause = "
56WHERE civicrm_event.id = %1
57AND civicrm_participant.is_test = 0
58AND civicrm_participant.status_id IN ( 1, 2 )";
be2fb01f 59 $params = [1 => [$this->_id, 'Integer']];
6a488035
TO
60 $this->pager($fromClause, $whereClause, $params);
61 $orderBy = $this->orderBy();
62
63 list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount();
64
65 $query = "
66SELECT civicrm_contact.id as contact_id ,
67 civicrm_contact.display_name as name ,
68 civicrm_contact.sort_name as sort_name ,
69 civicrm_participant.id as participant_id,
70 civicrm_email.email as email
71 $fromClause
72 $whereClause
73ORDER BY $orderBy
74LIMIT $offset, $rowCount";
75
be2fb01f 76 $rows = [];
6a488035
TO
77 $object = CRM_Core_DAO::executeQuery($query, $params);
78 while ($object->fetch()) {
be2fb01f 79 $row = [
6a488035
TO
80 'id' => $object->contact_id,
81 'participantID' => $object->participant_id,
82 'name' => $object->name,
83 'email' => $object->email,
be2fb01f 84 ];
6a488035
TO
85 $rows[] = $row;
86 }
87 $this->assign_by_ref('rows', $rows);
88
89 return parent::run();
90 }
91
0cf587a7
EM
92 /**
93 * @param $fromClause
94 * @param $whereClause
100fef9d 95 * @param array $whereParams
0cf587a7 96 */
00be9182 97 public function pager($fromClause, $whereClause, $whereParams) {
6a488035 98
be2fb01f 99 $params = [];
6a488035
TO
100
101 $params['status'] = ts('Group') . ' %%StatusMessage%%';
102 $params['csvString'] = NULL;
103 $params['buttonTop'] = 'PagerTopButton';
104 $params['buttonBottom'] = 'PagerBottomButton';
105 $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT);
106 if (!$params['rowCount']) {
7fa7c084 107 $params['rowCount'] = Civi::settings()->get('default_pager_size');
6a488035
TO
108 }
109
110 $query = "
111SELECT count( civicrm_contact.id )
112 $fromClause
113 $whereClause
114";
115
116 $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams);
117 $this->_pager = new CRM_Utils_Pager($params);
118 $this->assign_by_ref('pager', $this->_pager);
119 }
120
0cf587a7
EM
121 /**
122 * @return string
123 */
00be9182 124 public function orderBy() {
6a488035
TO
125 static $headers = NULL;
126 if (!$headers) {
be2fb01f
CW
127 $headers = [];
128 $headers[1] = [
353ffa53 129 'name' => ts('Name'),
6a488035
TO
130 'sort' => 'civicrm_contact.sort_name',
131 'direction' => CRM_Utils_Sort::ASCENDING,
be2fb01f 132 ];
6a488035 133 if ($this->_participantListingType == 'Name and Email') {
be2fb01f 134 $headers[2] = [
353ffa53 135 'name' => ts('Email'),
6a488035
TO
136 'sort' => 'civicrm_email.email',
137 'direction' => CRM_Utils_Sort::DONTCARE,
be2fb01f 138 ];
6a488035
TO
139 }
140 }
141 $sortID = NULL;
142 if ($this->get(CRM_Utils_Sort::SORT_ID)) {
143 $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
144 $this->get(CRM_Utils_Sort::SORT_DIRECTION)
145 );
146 }
147 $sort = new CRM_Utils_Sort($headers, $sortID);
148 $this->assign_by_ref('headers', $headers);
149 $this->assign_by_ref('sort', $sort);
150 $this->set(CRM_Utils_Sort::SORT_ID,
151 $sort->getCurrentSortID()
152 );
153 $this->set(CRM_Utils_Sort::SORT_DIRECTION,
154 $sort->getCurrentSortDirection()
155 );
156
157 return $sort->orderBy();
158 }
96025800 159
6a488035 160}