Merge pull request #16005 from magnolia61/Contribution_Invoice_Privacy
[civicrm-core.git] / CRM / Event / Page / ParticipantListing / Simple.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 * $Id$
17 *
18 */
19 class CRM_Event_Page_ParticipantListing_Simple extends CRM_Core_Page {
20
21 protected $_id;
22
23 protected $_participantListingType;
24
25 protected $_eventTitle;
26
27 protected $_pager;
28
29 public function preProcess() {
30 $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this, TRUE);
31
32 // retrieve Event Title and include it in page title
33 $this->_eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
34 $this->_id,
35 'title'
36 );
37 CRM_Utils_System::setTitle(ts('%1 - Participants', [1 => $this->_eventTitle]));
38
39 // we do not want to display recently viewed contacts since this is potentially a public page
40 $this->assign('displayRecent', FALSE);
41 }
42
43 /**
44 * @return string
45 */
46 public function run() {
47 $this->preProcess();
48
49 $fromClause = "
50 FROM civicrm_contact
51 INNER JOIN civicrm_participant ON ( civicrm_contact.id = civicrm_participant.contact_id
52 AND civicrm_contact.is_deleted = 0 )
53 INNER JOIN civicrm_event ON civicrm_participant.event_id = civicrm_event.id
54 LEFT JOIN civicrm_email ON ( civicrm_contact.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1 )
55 ";
56
57 $whereClause = "
58 WHERE civicrm_event.id = %1
59 AND civicrm_participant.is_test = 0
60 AND civicrm_participant.status_id IN ( 1, 2 )";
61 $params = [1 => [$this->_id, 'Integer']];
62 $this->pager($fromClause, $whereClause, $params);
63 $orderBy = $this->orderBy();
64
65 list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount();
66
67 $query = "
68 SELECT civicrm_contact.id as contact_id ,
69 civicrm_contact.display_name as name ,
70 civicrm_contact.sort_name as sort_name ,
71 civicrm_participant.id as participant_id,
72 civicrm_email.email as email
73 $fromClause
74 $whereClause
75 ORDER BY $orderBy
76 LIMIT $offset, $rowCount";
77
78 $rows = [];
79 $object = CRM_Core_DAO::executeQuery($query, $params);
80 while ($object->fetch()) {
81 $row = [
82 'id' => $object->contact_id,
83 'participantID' => $object->participant_id,
84 'name' => $object->name,
85 'email' => $object->email,
86 ];
87 $rows[] = $row;
88 }
89 $this->assign_by_ref('rows', $rows);
90
91 return parent::run();
92 }
93
94 /**
95 * @param $fromClause
96 * @param $whereClause
97 * @param array $whereParams
98 */
99 public function pager($fromClause, $whereClause, $whereParams) {
100
101 $params = [];
102
103 $params['status'] = ts('Group') . ' %%StatusMessage%%';
104 $params['csvString'] = NULL;
105 $params['buttonTop'] = 'PagerTopButton';
106 $params['buttonBottom'] = 'PagerBottomButton';
107 $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT);
108 if (!$params['rowCount']) {
109 $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
110 }
111
112 $query = "
113 SELECT count( civicrm_contact.id )
114 $fromClause
115 $whereClause
116 ";
117
118 $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams);
119 $this->_pager = new CRM_Utils_Pager($params);
120 $this->assign_by_ref('pager', $this->_pager);
121 }
122
123 /**
124 * @return string
125 */
126 public function orderBy() {
127 static $headers = NULL;
128 if (!$headers) {
129 $headers = [];
130 $headers[1] = [
131 'name' => ts('Name'),
132 'sort' => 'civicrm_contact.sort_name',
133 'direction' => CRM_Utils_Sort::ASCENDING,
134 ];
135 if ($this->_participantListingType == 'Name and Email') {
136 $headers[2] = [
137 'name' => ts('Email'),
138 'sort' => 'civicrm_email.email',
139 'direction' => CRM_Utils_Sort::DONTCARE,
140 ];
141 }
142 }
143 $sortID = NULL;
144 if ($this->get(CRM_Utils_Sort::SORT_ID)) {
145 $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
146 $this->get(CRM_Utils_Sort::SORT_DIRECTION)
147 );
148 }
149 $sort = new CRM_Utils_Sort($headers, $sortID);
150 $this->assign_by_ref('headers', $headers);
151 $this->assign_by_ref('sort', $sort);
152 $this->set(CRM_Utils_Sort::SORT_ID,
153 $sort->getCurrentSortID()
154 );
155 $this->set(CRM_Utils_Sort::SORT_DIRECTION,
156 $sort->getCurrentSortDirection()
157 );
158
159 return $sort->orderBy();
160 }
161
162 }