Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-10-02-11-18-44
[civicrm-core.git] / CRM / Event / Page / ParticipantListing / Simple.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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
43 protected $_pager;
44
45 function preProcess() {
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
59 function run() {
60 $this->preProcess();
61
62 $fromClause = "
63 FROM civicrm_contact
64 INNER JOIN civicrm_participant ON ( civicrm_contact.id = civicrm_participant.contact_id
65 AND civicrm_contact.is_deleted = 0 )
66 INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id
67 LEFT JOIN civicrm_email ON ( civicrm_contact.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1 )
68 ";
69
70 $whereClause = "
71 WHERE civicrm_event.id = %1
72 AND civicrm_participant.is_test = 0
73 AND civicrm_participant.status_id IN ( 1, 2 )";
74 $params = array(1 => array($this->_id, 'Integer'));
75 $this->pager($fromClause, $whereClause, $params);
76 $orderBy = $this->orderBy();
77
78 list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount();
79
80 $query = "
81 SELECT civicrm_contact.id as contact_id ,
82 civicrm_contact.display_name as name ,
83 civicrm_contact.sort_name as sort_name ,
84 civicrm_participant.id as participant_id,
85 civicrm_email.email as email
86 $fromClause
87 $whereClause
88 ORDER BY $orderBy
89 LIMIT $offset, $rowCount";
90
91 $rows = array();
92 $object = CRM_Core_DAO::executeQuery($query, $params);
93 while ($object->fetch()) {
94 $row = array(
95 'id' => $object->contact_id,
96 'participantID' => $object->participant_id,
97 'name' => $object->name,
98 'email' => $object->email,
99 );
100 $rows[] = $row;
101 }
102 $this->assign_by_ref('rows', $rows);
103
104 return parent::run();
105 }
106
107 function pager($fromClause, $whereClause, $whereParams) {
108
109 $params = array();
110
111 $params['status'] = ts('Group') . ' %%StatusMessage%%';
112 $params['csvString'] = NULL;
113 $params['buttonTop'] = 'PagerTopButton';
114 $params['buttonBottom'] = 'PagerBottomButton';
115 $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT);
116 if (!$params['rowCount']) {
117 $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
118 }
119
120 $query = "
121 SELECT count( civicrm_contact.id )
122 $fromClause
123 $whereClause
124 ";
125
126 $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams);
127 $this->_pager = new CRM_Utils_Pager($params);
128 $this->assign_by_ref('pager', $this->_pager);
129 }
130
131 function orderBy() {
132 static $headers = NULL;
133 if (!$headers) {
134 $headers = array();
135 $headers[1] = array('name' => ts('Name'),
136 'sort' => 'civicrm_contact.sort_name',
137 'direction' => CRM_Utils_Sort::ASCENDING,
138 );
139 if ($this->_participantListingType == 'Name and Email') {
140 $headers[2] = array('name' => ts('Email'),
141 'sort' => 'civicrm_email.email',
142 'direction' => CRM_Utils_Sort::DONTCARE,
143 );
144 }
145 }
146 $sortID = NULL;
147 if ($this->get(CRM_Utils_Sort::SORT_ID)) {
148 $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
149 $this->get(CRM_Utils_Sort::SORT_DIRECTION)
150 );
151 }
152 $sort = new CRM_Utils_Sort($headers, $sortID);
153 $this->assign_by_ref('headers', $headers);
154 $this->assign_by_ref('sort', $sort);
155 $this->set(CRM_Utils_Sort::SORT_ID,
156 $sort->getCurrentSortID()
157 );
158 $this->set(CRM_Utils_Sort::SORT_DIRECTION,
159 $sort->getCurrentSortDirection()
160 );
161
162 return $sort->orderBy();
163 }
164 }
165