Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Event_Page_ParticipantListing_Simple extends CRM_Core_Page { | |
36 | ||
37 | protected $_id; | |
38 | ||
39 | protected $_participantListingType; | |
40 | ||
41 | protected $_eventTitle; | |
42 | ||
430ae6dd TO |
43 | protected $_pager; |
44 | ||
00be9182 | 45 | public function preProcess() { |
6a488035 TO |
46 | $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this, TRUE); |
47 | ||
48 | // retrieve Event Title and include it in page title | |
49 | $this->_eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', | |
50 | $this->_id, | |
51 | 'title' | |
52 | ); | |
53 | CRM_Utils_System::setTitle(ts('%1 - Participants', array(1 => $this->_eventTitle))); | |
54 | ||
55 | // we do not want to display recently viewed contacts since this is potentially a public page | |
56 | $this->assign('displayRecent', FALSE); | |
57 | } | |
58 | ||
0cf587a7 EM |
59 | /** |
60 | * @return string | |
61 | */ | |
00be9182 | 62 | public function run() { |
6a488035 TO |
63 | $this->preProcess(); |
64 | ||
65 | $fromClause = " | |
66 | FROM civicrm_contact | |
03e04002 | 67 | INNER JOIN civicrm_participant ON ( civicrm_contact.id = civicrm_participant.contact_id |
68 | AND civicrm_contact.is_deleted = 0 ) | |
6a488035 TO |
69 | INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id |
70 | LEFT JOIN civicrm_email ON ( civicrm_contact.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1 ) | |
71 | "; | |
72 | ||
73 | $whereClause = " | |
74 | WHERE civicrm_event.id = %1 | |
75 | AND civicrm_participant.is_test = 0 | |
76 | AND civicrm_participant.status_id IN ( 1, 2 )"; | |
77 | $params = array(1 => array($this->_id, 'Integer')); | |
78 | $this->pager($fromClause, $whereClause, $params); | |
79 | $orderBy = $this->orderBy(); | |
80 | ||
81 | list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount(); | |
82 | ||
83 | $query = " | |
84 | SELECT civicrm_contact.id as contact_id , | |
85 | civicrm_contact.display_name as name , | |
86 | civicrm_contact.sort_name as sort_name , | |
87 | civicrm_participant.id as participant_id, | |
88 | civicrm_email.email as email | |
89 | $fromClause | |
90 | $whereClause | |
91 | ORDER BY $orderBy | |
92 | LIMIT $offset, $rowCount"; | |
93 | ||
94 | $rows = array(); | |
95 | $object = CRM_Core_DAO::executeQuery($query, $params); | |
96 | while ($object->fetch()) { | |
97 | $row = array( | |
98 | 'id' => $object->contact_id, | |
99 | 'participantID' => $object->participant_id, | |
100 | 'name' => $object->name, | |
101 | 'email' => $object->email, | |
102 | ); | |
103 | $rows[] = $row; | |
104 | } | |
105 | $this->assign_by_ref('rows', $rows); | |
106 | ||
107 | return parent::run(); | |
108 | } | |
109 | ||
0cf587a7 EM |
110 | /** |
111 | * @param $fromClause | |
112 | * @param $whereClause | |
100fef9d | 113 | * @param array $whereParams |
0cf587a7 | 114 | */ |
00be9182 | 115 | public function pager($fromClause, $whereClause, $whereParams) { |
6a488035 TO |
116 | |
117 | $params = array(); | |
118 | ||
119 | $params['status'] = ts('Group') . ' %%StatusMessage%%'; | |
120 | $params['csvString'] = NULL; | |
121 | $params['buttonTop'] = 'PagerTopButton'; | |
122 | $params['buttonBottom'] = 'PagerBottomButton'; | |
123 | $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT); | |
124 | if (!$params['rowCount']) { | |
125 | $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; | |
126 | } | |
127 | ||
128 | $query = " | |
129 | SELECT count( civicrm_contact.id ) | |
130 | $fromClause | |
131 | $whereClause | |
132 | "; | |
133 | ||
134 | $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams); | |
135 | $this->_pager = new CRM_Utils_Pager($params); | |
136 | $this->assign_by_ref('pager', $this->_pager); | |
137 | } | |
138 | ||
0cf587a7 EM |
139 | /** |
140 | * @return string | |
141 | */ | |
00be9182 | 142 | public function orderBy() { |
6a488035 TO |
143 | static $headers = NULL; |
144 | if (!$headers) { | |
145 | $headers = array(); | |
0479b4c8 TO |
146 | $headers[1] = array( |
147 | 'name' => ts('Name'), | |
6a488035 TO |
148 | 'sort' => 'civicrm_contact.sort_name', |
149 | 'direction' => CRM_Utils_Sort::ASCENDING, | |
150 | ); | |
151 | if ($this->_participantListingType == 'Name and Email') { | |
0479b4c8 TO |
152 | $headers[2] = array( |
153 | 'name' => ts('Email'), | |
6a488035 TO |
154 | 'sort' => 'civicrm_email.email', |
155 | 'direction' => CRM_Utils_Sort::DONTCARE, | |
156 | ); | |
157 | } | |
158 | } | |
159 | $sortID = NULL; | |
160 | if ($this->get(CRM_Utils_Sort::SORT_ID)) { | |
161 | $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), | |
162 | $this->get(CRM_Utils_Sort::SORT_DIRECTION) | |
163 | ); | |
164 | } | |
165 | $sort = new CRM_Utils_Sort($headers, $sortID); | |
166 | $this->assign_by_ref('headers', $headers); | |
167 | $this->assign_by_ref('sort', $sort); | |
168 | $this->set(CRM_Utils_Sort::SORT_ID, | |
169 | $sort->getCurrentSortID() | |
170 | ); | |
171 | $this->set(CRM_Utils_Sort::SORT_DIRECTION, | |
172 | $sort->getCurrentSortDirection() | |
173 | ); | |
174 | ||
175 | return $sort->orderBy(); | |
176 | } | |
177 | } |