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