Merge pull request #18008 from civicrm/5.28
[civicrm-core.git] / CRM / Event / Page / ParticipantListing / NameStatusAndDate.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Event_Page_ParticipantListing_NameStatusAndDate extends CRM_Core_Page {
18
19 protected $_id;
20
21 protected $_participantListingID;
22
23 protected $_eventTitle;
24
25 protected $_pager;
26
27 public function preProcess() {
28 $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this, TRUE);
29
30 // ensure that there is a particpant type for this
31 $this->_participantListingID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
32 $this->_id,
33 'participant_listing_id'
34 );
35 if (!$this->_participantListingID) {
36 CRM_Core_Error::statusBounce(ts("The Participant Listing feature is not currently enabled for this event."));
37 }
38
39 // retrieve Event Title and include it in page title
40 $this->_eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
41 $this->_id,
42 'title'
43 );
44 CRM_Utils_System::setTitle(ts('%1 - Participants', [1 => $this->_eventTitle]));
45
46 // we do not want to display recently viewed contacts since this is potentially a public page
47 $this->assign('displayRecent', FALSE);
48 }
49
50 /**
51 * @return string
52 */
53 public function run() {
54 $this->preProcess();
55
56 $fromClause = "
57 FROM civicrm_contact
58 INNER JOIN civicrm_participant ON civicrm_contact.id = civicrm_participant.contact_id
59 INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id
60 ";
61
62 $whereClause = "
63 WHERE civicrm_event.id = %1";
64
65 $params = [1 => [$this->_id, 'Integer']];
66 $this->pager($fromClause, $whereClause, $params);
67 $orderBy = $this->orderBy();
68
69 list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount();
70
71 $query = "
72 SELECT civicrm_contact.id as contact_id ,
73 civicrm_contact.display_name as name ,
74 civicrm_contact.sort_name as sort_name ,
75 civicrm_participant.id as participant_id,
76 civicrm_participant.status_id as status_id ,
77 civicrm_participant.register_date as register_date
78 $fromClause
79 $whereClause
80 ORDER BY $orderBy
81 LIMIT $offset, $rowCount";
82
83 $rows = [];
84 $object = CRM_Core_DAO::executeQuery($query, $params);
85 $statusLookup = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
86 while ($object->fetch()) {
87 $status = $statusLookup[$object->status_id] ?? NULL;
88 $row = [
89 'id' => $object->contact_id,
90 'participantID' => $object->participant_id,
91 'name' => $object->name,
92 'status' => $status,
93 'date' => $object->register_date,
94 ];
95 $rows[] = $row;
96 }
97 $this->assign_by_ref('rows', $rows);
98
99 return parent::run();
100 }
101
102 /**
103 * @param $fromClause
104 * @param $whereClause
105 * @param array $whereParams
106 */
107 public function pager($fromClause, $whereClause, $whereParams) {
108
109 $params = [];
110
111 $params['status'] = ts('Group') . ' %%StatusMessage%%';
112 $params['csvString'] = NULL;
113 $params['buttonTop'] = 'PagerTopButton';
114 $params['buttonBottom'] = 'PagerBottomButton';
115 $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT);
116 if (!$params['rowCount']) {
117 $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
118 }
119
120 $query = "
121 SELECT count( civicrm_contact.id )
122 $fromClause
123 $whereClause";
124
125 $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams);
126 $this->_pager = new CRM_Utils_Pager($params);
127 $this->assign_by_ref('pager', $this->_pager);
128 }
129
130 /**
131 * @return string
132 */
133 public function orderBy() {
134 static $headers = NULL;
135 if (!$headers) {
136 $headers = [];
137 $headers[1] = [
138 'name' => ts('Name'),
139 'sort' => 'civicrm_contact.sort_name',
140 'direction' => CRM_Utils_Sort::ASCENDING,
141 ];
142 $headers[2] = [
143 'name' => ts('Status'),
144 'sort' => 'civicrm_participant.status_id',
145 'direction' => CRM_Utils_Sort::DONTCARE,
146 ];
147 $headers[3] = [
148 'name' => ts('Register Date'),
149 'sort' => 'civicrm_participant.register_date',
150 'direction' => CRM_Utils_Sort::DONTCARE,
151 ];
152 }
153 $sortID = NULL;
154 if ($this->get(CRM_Utils_Sort::SORT_ID)) {
155 $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
156 $this->get(CRM_Utils_Sort::SORT_DIRECTION)
157 );
158 }
159 $sort = new CRM_Utils_Sort($headers, $sortID);
160 $this->assign_by_ref('headers', $headers);
161 $this->assign_by_ref('sort', $sort);
162 $this->set(CRM_Utils_Sort::SORT_ID,
163 $sort->getCurrentSortID()
164 );
165 $this->set(CRM_Utils_Sort::SORT_DIRECTION,
166 $sort->getCurrentSortDirection()
167 );
168
169 return $sort->orderBy();
170 }
171
172 }