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