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