NFC - Fix @return annotation in CRM_Utils_Check_Component_*
[civicrm-core.git] / CRM / Event / Form / Registration / ParticipantConfirm.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
17 */
18
19/**
20 * This class generates form components for processing Event
21 *
22 */
23class CRM_Event_Form_Registration_ParticipantConfirm extends CRM_Event_Form_Registration {
24 // optional credit card return status code
90b461f1
SL
25 /**
26 * CRM-6060
27 * @var string
28 */
6a488035
TO
29 protected $_cc = NULL;
30
31 /**
66f9e52b 32 * Set variables up before form is built.
6a488035
TO
33 *
34 * @return void
6a488035
TO
35 */
36 public function preProcess() {
37 $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this);
38
39 $this->_cc = CRM_Utils_Request::retrieve('cc', 'String', $this);
40
41 //get the contact and event id and assing to session.
be2fb01f 42 $values = [];
af72b8c7 43 $csContactID = NULL;
6a488035 44 if ($this->_participantId) {
be2fb01f 45 $params = ['id' => $this->_participantId];
6a488035 46 CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Participant', $params, $values,
be2fb01f 47 ['contact_id', 'event_id', 'status_id']
6a488035
TO
48 );
49 }
50
9c1bc317
CW
51 $this->_participantStatusId = $values['status_id'] ?? NULL;
52 $this->_eventId = $values['event_id'] ?? NULL;
53 $csContactId = $values['contact_id'] ?? NULL;
6a488035
TO
54
55 // make sure we have right permission to edit this user
56 $this->_csContactID = NULL;
57 if ($csContactId && $this->_eventId) {
58 $session = CRM_Core_Session::singleton();
59 if ($csContactId == $session->get('userID')) {
60 $this->_csContactID = $csContactId;
61 }
62 else {
63 if (CRM_Contact_BAO_Contact_Permission::validateChecksumContact($csContactId, $this)) {
64 //since we have landing page so get this contact
65 //id in session if user really want to walk wizard.
66 $this->_csContactID = $csContactId;
67 }
68 }
69 }
70
71 if (!$this->_csContactID) {
72 $config = CRM_Core_Config::singleton();
73 CRM_Core_Error::statusBounce(ts('You do not have permission to access this event registration. Contact the site administrator if you need assistance.'), $config->userFrameworkBaseURL);
74 }
75 }
76
77 /**
66f9e52b 78 * Build the form object.
6a488035 79 *
355ba699 80 * @return void
6a488035
TO
81 */
82 public function buildQuickForm() {
be2fb01f
CW
83 $params = ['id' => $this->_eventId];
84 $values = [];
6a488035 85 CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $params, $values,
be2fb01f 86 ['title']
6a488035
TO
87 );
88
be2fb01f 89 $buttons = [];
6a488035
TO
90 // only pending status class family able to confirm.
91
92 $statusMsg = NULL;
93 if (array_key_exists($this->_participantStatusId,
353ffa53
TO
94 CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'")
95 )) {
6a488035 96
6a488035
TO
97 //need to confirm that though participant confirming
98 //registration - but is there enough space to confirm.
49f3a6ff 99 $emptySeats = CRM_Event_BAO_Participant::eventFull($this->_eventId, TRUE, FALSE, TRUE, FALSE, TRUE);
6a488035
TO
100 $additonalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId);
101 $requireSpace = 1 + count($additonalIds);
102 if ($emptySeats !== NULL && ($requireSpace > $emptySeats)) {
be2fb01f 103 $statusMsg = ts("Oops, it looks like there are currently no available spaces for the %1 event.", [1 => $values['title']]);
6a488035
TO
104 }
105 else {
106 if ($this->_cc == 'fail') {
be2fb01f 107 $statusMsg = '<div class="bold">' . ts('Your Credit Card transaction was not successful. No money has yet been charged to your card.') . '</div><div><br />' . ts('Click the "Confirm Registration" button to complete your registration in %1, or click "Cancel Registration" if you are no longer interested in attending this event.', [
90b461f1
SL
108 1 => $values['title'],
109 ]) . '</div>';
6a488035
TO
110 }
111 else {
be2fb01f 112 $statusMsg = '<div class="bold">' . ts('Confirm your registration for %1.', [
90b461f1
SL
113 1 => $values['title'],
114 ]) . '</div><div><br />' . ts('Click the "Confirm Registration" button to begin, or click "Cancel Registration" if you are no longer interested in attending this event.') . '</div>';
6a488035 115 }
be2fb01f
CW
116 $buttons = array_merge($buttons, [
117 [
353ffa53
TO
118 'type' => 'next',
119 'name' => ts('Confirm Registration'),
120 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
121 'isDefault' => TRUE,
be2fb01f
CW
122 ],
123 ]);
6a488035
TO
124 }
125 }
126
127 // status class other than Negative should be able to cancel registration.
128 if (array_key_exists($this->_participantStatusId,
353ffa53
TO
129 CRM_Event_PseudoConstant::participantStatus(NULL, "class != 'Negative'")
130 )) {
6a488035 131 $cancelConfirm = ts('Are you sure you want to cancel your registration for this event?');
be2fb01f
CW
132 $buttons = array_merge($buttons, [
133 [
353ffa53
TO
134 'type' => 'submit',
135 'name' => ts('Cancel Registration'),
136 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
be2fb01f
CW
137 'js' => ['onclick' => 'return confirm(\'' . $cancelConfirm . '\');'],
138 ],
139 ]);
6a488035 140 if (!$statusMsg) {
be2fb01f 141 $statusMsg = ts('You can cancel your registration for %1 by clicking "Cancel Registration".', [1 => $values['title']]);
6a488035
TO
142 }
143 }
144 if (!$statusMsg) {
145 $statusMsg = ts("Oops, it looks like your registration for %1 has already been cancelled.",
be2fb01f 146 [1 => $values['title']]
6a488035
TO
147 );
148 }
149 $this->assign('statusMsg', $statusMsg);
150
151 $this->addButtons($buttons);
152 }
153
154 /**
66f9e52b 155 * Process the form submission.
6a488035 156 *
6a488035 157 *
355ba699 158 * @return void
6a488035
TO
159 */
160 public function postProcess() {
161 //get the button.
353ffa53 162 $buttonName = $this->controller->getButtonName();
6a488035
TO
163 $participantId = $this->_participantId;
164
165 if ($buttonName == '_qf_ParticipantConfirm_next') {
166 //lets get contact id in session.
167 $session = CRM_Core_Session::singleton();
168 $session->set('userID', $this->_csContactID);
169
170 $this->postProcessHook();
171
172 //check user registration status is from pending class
173 $url = CRM_Utils_System::url('civicrm/event/register',
af72b8c7 174 "reset=1&id={$this->_eventId}&participantId={$participantId}"
6a488035
TO
175 );
176 CRM_Utils_System::redirect($url);
177 }
178 elseif ($buttonName == '_qf_ParticipantConfirm_submit') {
179 //need to registration status to 'cancelled'.
180
181 $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
182 $additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId);
183
be2fb01f 184 $participantIds = array_merge([$participantId], $additionalParticipantIds);
6a488035
TO
185 $results = CRM_Event_BAO_Participant::transitionParticipants($participantIds, $cancelledId, NULL, TRUE);
186
187 if (count($participantIds) > 1) {
be2fb01f 188 $statusMessage = ts("%1 Event registration(s) have been cancelled.", [1 => count($participantIds)]);
6a488035
TO
189 }
190 else {
6c68db9f 191 $statusMessage = ts("Your Event Registration has been cancelled.");
6a488035
TO
192 }
193
a7488080 194 if (!empty($results['mailedParticipants'])) {
6a488035 195 foreach ($results['mailedParticipants'] as $key => $displayName) {
be2fb01f 196 $statusMessage .= "<br />" . ts("Email has been sent to : %1", [1 => $displayName]);
6a488035
TO
197 }
198 }
199
200 $this->postProcessHook();
d6c219af 201 CRM_Core_Session::setStatus($statusMessage);
202 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/info',
6a488035
TO
203 "reset=1&id={$this->_eventId}&noFullMsg=1",
204 FALSE, NULL, FALSE, TRUE
205 )
206 );
207 }
208 }
96025800 209
6a488035 210}