commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / CRM / Event / Page / ParticipantListing / NameStatusAndDate.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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 public 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 /**
69 * @return string
70 */
71 public function run() {
72 $this->preProcess();
73
74 $fromClause = "
75 FROM civicrm_contact
76 INNER JOIN civicrm_participant ON civicrm_contact.id = civicrm_participant.contact_id
77 INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id
78 ";
79
80 $whereClause = "
81 WHERE civicrm_event.id = %1";
82
83 $params = array(1 => array($this->_id, 'Integer'));
84 $this->pager($fromClause, $whereClause, $params);
85 $orderBy = $this->orderBy();
86
87 list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount();
88
89 $query = "
90 SELECT 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
98 ORDER BY $orderBy
99 LIMIT $offset, $rowCount";
100
101 $rows = array();
102 $object = CRM_Core_DAO::executeQuery($query, $params);
103 $statusLookup = CRM_Event_PseudoConstant::participantStatus();
104 while ($object->fetch()) {
105 $status = CRM_Utils_Array::value($object->status_id, $statusLookup);
106 if ($status) {
107 $status = ts($status);
108 }
109 $row = array(
110 'id' => $object->contact_id,
111 'participantID' => $object->participant_id,
112 'name' => $object->name,
113 'status' => $status,
114 'date' => $object->register_date,
115 );
116 $rows[] = $row;
117 }
118 $this->assign_by_ref('rows', $rows);
119
120 return parent::run();
121 }
122
123 /**
124 * @param $fromClause
125 * @param $whereClause
126 * @param array $whereParams
127 */
128 public function pager($fromClause, $whereClause, $whereParams) {
129
130 $params = array();
131
132 $params['status'] = ts('Group') . ' %%StatusMessage%%';
133 $params['csvString'] = NULL;
134 $params['buttonTop'] = 'PagerTopButton';
135 $params['buttonBottom'] = 'PagerBottomButton';
136 $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT);
137 if (!$params['rowCount']) {
138 $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
139 }
140
141 $query = "
142 SELECT count( civicrm_contact.id )
143 $fromClause
144 $whereClause";
145
146 $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams);
147 $this->_pager = new CRM_Utils_Pager($params);
148 $this->assign_by_ref('pager', $this->_pager);
149 }
150
151 /**
152 * @return string
153 */
154 public function orderBy() {
155 static $headers = NULL;
156 if (!$headers) {
157 $headers = array();
158 $headers[1] = array(
159 'name' => ts('Name'),
160 'sort' => 'civicrm_contact.sort_name',
161 'direction' => CRM_Utils_Sort::ASCENDING,
162 );
163 $headers[2] = array(
164 'name' => ts('Status'),
165 'sort' => 'civicrm_participant.status_id',
166 'direction' => CRM_Utils_Sort::DONTCARE,
167 );
168 $headers[3] = array(
169 'name' => ts('Register Date'),
170 'sort' => 'civicrm_participant.register_date',
171 'direction' => CRM_Utils_Sort::DONTCARE,
172 );
173 }
174 $sortID = NULL;
175 if ($this->get(CRM_Utils_Sort::SORT_ID)) {
176 $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
177 $this->get(CRM_Utils_Sort::SORT_DIRECTION)
178 );
179 }
180 $sort = new CRM_Utils_Sort($headers, $sortID);
181 $this->assign_by_ref('headers', $headers);
182 $this->assign_by_ref('sort', $sort);
183 $this->set(CRM_Utils_Sort::SORT_ID,
184 $sort->getCurrentSortID()
185 );
186 $this->set(CRM_Utils_Sort::SORT_DIRECTION,
187 $sort->getCurrentSortDirection()
188 );
189
190 return $sort->orderBy();
191 }
192
193 }