Commit | Line | Data |
---|---|---|
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 | */ |
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; | |
5dff0278 | 26 | |
00be9182 | 27 | public function preProcess() { |
6a488035 TO |
28 | $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this, TRUE); |
29 | ||
d20ece63 | 30 | // ensure that there is a participant type for this |
6a488035 TO |
31 | $this->_participantListingID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', |
32 | $this->_id, | |
33 | 'participant_listing_id' | |
34 | ); | |
35 | if (!$this->_participantListingID) { | |
beb414cc | 36 | CRM_Core_Error::statusBounce(ts("The Participant Listing feature is not currently enabled for this event.")); |
6a488035 TO |
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 | ); | |
be2fb01f | 44 | CRM_Utils_System::setTitle(ts('%1 - Participants', [1 => $this->_eventTitle])); |
6a488035 TO |
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 | ||
0cf587a7 EM |
50 | /** |
51 | * @return string | |
52 | */ | |
00be9182 | 53 | public function run() { |
6a488035 TO |
54 | $this->preProcess(); |
55 | ||
56 | $fromClause = " | |
57 | FROM civicrm_contact | |
5dff0278 | 58 | INNER JOIN civicrm_participant ON civicrm_contact.id = civicrm_participant.contact_id |
6a488035 TO |
59 | INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id |
60 | "; | |
61 | ||
62 | $whereClause = " | |
63 | WHERE civicrm_event.id = %1"; | |
64 | ||
be2fb01f | 65 | $params = [1 => [$this->_id, 'Integer']]; |
6a488035 TO |
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 | ||
be2fb01f | 83 | $rows = []; |
353ffa53 | 84 | $object = CRM_Core_DAO::executeQuery($query, $params); |
6dabf459 | 85 | $statusLookup = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); |
6a488035 | 86 | while ($object->fetch()) { |
9c1bc317 | 87 | $status = $statusLookup[$object->status_id] ?? NULL; |
be2fb01f | 88 | $row = [ |
6a488035 TO |
89 | 'id' => $object->contact_id, |
90 | 'participantID' => $object->participant_id, | |
91 | 'name' => $object->name, | |
5dff0278 | 92 | 'status' => $status, |
6a488035 | 93 | 'date' => $object->register_date, |
be2fb01f | 94 | ]; |
6a488035 TO |
95 | $rows[] = $row; |
96 | } | |
97 | $this->assign_by_ref('rows', $rows); | |
98 | ||
99 | return parent::run(); | |
100 | } | |
101 | ||
0cf587a7 EM |
102 | /** |
103 | * @param $fromClause | |
104 | * @param $whereClause | |
100fef9d | 105 | * @param array $whereParams |
0cf587a7 | 106 | */ |
00be9182 | 107 | public function pager($fromClause, $whereClause, $whereParams) { |
6a488035 | 108 | |
be2fb01f | 109 | $params = []; |
6a488035 TO |
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']) { | |
7fa7c084 | 117 | $params['rowCount'] = Civi::settings()->get('default_pager_size'); |
6a488035 TO |
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 | ||
0cf587a7 EM |
130 | /** |
131 | * @return string | |
132 | */ | |
00be9182 | 133 | public function orderBy() { |
6a488035 TO |
134 | static $headers = NULL; |
135 | if (!$headers) { | |
be2fb01f CW |
136 | $headers = []; |
137 | $headers[1] = [ | |
353ffa53 | 138 | 'name' => ts('Name'), |
6a488035 TO |
139 | 'sort' => 'civicrm_contact.sort_name', |
140 | 'direction' => CRM_Utils_Sort::ASCENDING, | |
be2fb01f CW |
141 | ]; |
142 | $headers[2] = [ | |
353ffa53 | 143 | 'name' => ts('Status'), |
6a488035 TO |
144 | 'sort' => 'civicrm_participant.status_id', |
145 | 'direction' => CRM_Utils_Sort::DONTCARE, | |
be2fb01f CW |
146 | ]; |
147 | $headers[3] = [ | |
353ffa53 | 148 | 'name' => ts('Register Date'), |
6a488035 TO |
149 | 'sort' => 'civicrm_participant.register_date', |
150 | 'direction' => CRM_Utils_Sort::DONTCARE, | |
be2fb01f | 151 | ]; |
6a488035 TO |
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 | } | |
96025800 | 171 | |
6a488035 | 172 | } |