copyright and version fixes
[civicrm-core.git] / CRM / Event / Page / ParticipantListing / NameStatusAndDate.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35 class 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;
44
45 function preProcess() {
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 );
62 CRM_Utils_System::setTitle(ts('%1 - Participants', array(1 => $this->_eventTitle)));
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
68 function run() {
69 $this->preProcess();
70
71 $fromClause = "
72 FROM civicrm_contact
73 INNER JOIN civicrm_participant ON civicrm_contact.id = civicrm_participant.contact_id
74 INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id
75 ";
76
77 $whereClause = "
78 WHERE civicrm_event.id = %1";
79
80 $params = array(1 => array($this->_id, 'Integer'));
81 $this->pager($fromClause, $whereClause, $params);
82 $orderBy = $this->orderBy();
83
84 list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount();
85
86 $query = "
87 SELECT civicrm_contact.id as contact_id ,
88 civicrm_contact.display_name as name ,
89 civicrm_contact.sort_name as sort_name ,
90 civicrm_participant.id as participant_id,
91 civicrm_participant.status_id as status_id ,
92 civicrm_participant.register_date as register_date
93 $fromClause
94 $whereClause
95 ORDER BY $orderBy
96 LIMIT $offset, $rowCount";
97
98 $rows = array();
99 $object = CRM_Core_DAO::executeQuery($query, $params);
100 $statusLookup = CRM_Event_PseudoConstant::participantStatus();
101 while ($object->fetch()) {
102 $status = CRM_Utils_Array::value($object->status_id, $statusLookup);
103 if ($status) {
104 $status = ts($status);
105 }
106 $row = array(
107 'id' => $object->contact_id,
108 'participantID' => $object->participant_id,
109 'name' => $object->name,
110 'status' => $status,
111 'date' => $object->register_date,
112 );
113 $rows[] = $row;
114 }
115 $this->assign_by_ref('rows', $rows);
116
117 return parent::run();
118 }
119
120 function pager($fromClause, $whereClause, $whereParams) {
121
122 $params = array();
123
124 $params['status'] = ts('Group') . ' %%StatusMessage%%';
125 $params['csvString'] = NULL;
126 $params['buttonTop'] = 'PagerTopButton';
127 $params['buttonBottom'] = 'PagerBottomButton';
128 $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT);
129 if (!$params['rowCount']) {
130 $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
131 }
132
133 $query = "
134 SELECT count( civicrm_contact.id )
135 $fromClause
136 $whereClause";
137
138 $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams);
139 $this->_pager = new CRM_Utils_Pager($params);
140 $this->assign_by_ref('pager', $this->_pager);
141 }
142
143 function orderBy() {
144 static $headers = NULL;
145 if (!$headers) {
146 $headers = array();
147 $headers[1] = array('name' => ts('Name'),
148 'sort' => 'civicrm_contact.sort_name',
149 'direction' => CRM_Utils_Sort::ASCENDING,
150 );
151 $headers[2] = array('name' => ts('Status'),
152 'sort' => 'civicrm_participant.status_id',
153 'direction' => CRM_Utils_Sort::DONTCARE,
154 );
155 $headers[3] = array('name' => ts('Register Date'),
156 'sort' => 'civicrm_participant.register_date',
157 'direction' => CRM_Utils_Sort::DONTCARE,
158 );
159 }
160 $sortID = NULL;
161 if ($this->get(CRM_Utils_Sort::SORT_ID)) {
162 $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
163 $this->get(CRM_Utils_Sort::SORT_DIRECTION)
164 );
165 }
166 $sort = new CRM_Utils_Sort($headers, $sortID);
167 $this->assign_by_ref('headers', $headers);
168 $this->assign_by_ref('sort', $sort);
169 $this->set(CRM_Utils_Sort::SORT_ID,
170 $sort->getCurrentSortID()
171 );
172 $this->set(CRM_Utils_Sort::SORT_DIRECTION,
173 $sort->getCurrentSortDirection()
174 );
175
176 return $sort->orderBy();
177 }
178 }
179