3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 * This class generates form components for processing Event
25 class CRM_Event_Form_Registration_ParticipantConfirm
extends CRM_Event_Form_Registration
{
26 // optional credit card return status code
31 protected $_cc = NULL;
34 * Set variables up before form is built.
38 public function preProcess() {
39 $this->_participantId
= CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
41 $this->_cc
= CRM_Utils_Request
::retrieve('cc', 'String', $this);
43 //get the contact and event id and assing to session.
46 if ($this->_participantId
) {
47 $params = ['id' => $this->_participantId
];
48 CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Participant', $params, $values,
49 ['contact_id', 'event_id', 'status_id']
53 $this->_participantStatusId
= CRM_Utils_Array
::value('status_id', $values);
54 $this->_eventId
= CRM_Utils_Array
::value('event_id', $values);
55 $csContactId = CRM_Utils_Array
::value('contact_id', $values);
57 // make sure we have right permission to edit this user
58 $this->_csContactID
= NULL;
59 if ($csContactId && $this->_eventId
) {
60 $session = CRM_Core_Session
::singleton();
61 if ($csContactId == $session->get('userID')) {
62 $this->_csContactID
= $csContactId;
65 if (CRM_Contact_BAO_Contact_Permission
::validateChecksumContact($csContactId, $this)) {
66 //since we have landing page so get this contact
67 //id in session if user really want to walk wizard.
68 $this->_csContactID
= $csContactId;
73 if (!$this->_csContactID
) {
74 $config = CRM_Core_Config
::singleton();
75 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
);
80 * Build the form object.
84 public function buildQuickForm() {
85 $params = ['id' => $this->_eventId
];
87 CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Event', $params, $values,
92 // only pending status class family able to confirm.
95 if (array_key_exists($this->_participantStatusId
,
96 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'")
99 //need to confirm that though participant confirming
100 //registration - but is there enough space to confirm.
101 $emptySeats = CRM_Event_BAO_Participant
::pendingToConfirmSpaces($this->_eventId
);
102 $additonalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_participantId
);
103 $requireSpace = 1 +
count($additonalIds);
104 if ($emptySeats !== NULL && ($requireSpace > $emptySeats)) {
105 $statusMsg = ts("Oops, it looks like there are currently no available spaces for the %1 event.", [1 => $values['title']]);
108 if ($this->_cc
== 'fail') {
109 $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.', [
110 1 => $values['title'],
114 $statusMsg = '<div class="bold">' . ts('Confirm your registration for %1.', [
115 1 => $values['title'],
116 ]) . '</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>';
118 $buttons = array_merge($buttons, [
121 'name' => ts('Confirm Registration'),
122 'spacing' => ' ',
129 // status class other than Negative should be able to cancel registration.
130 if (array_key_exists($this->_participantStatusId
,
131 CRM_Event_PseudoConstant
::participantStatus(NULL, "class != 'Negative'")
133 $cancelConfirm = ts('Are you sure you want to cancel your registration for this event?');
134 $buttons = array_merge($buttons, [
137 'name' => ts('Cancel Registration'),
138 'spacing' => ' ',
139 'js' => ['onclick' => 'return confirm(\'' . $cancelConfirm . '\');'],
143 $statusMsg = ts('You can cancel your registration for %1 by clicking "Cancel Registration".', [1 => $values['title']]);
147 $statusMsg = ts("Oops, it looks like your registration for %1 has already been cancelled.",
148 [1 => $values['title']]
151 $this->assign('statusMsg', $statusMsg);
153 $this->addButtons($buttons);
157 * Process the form submission.
162 public function postProcess() {
164 $buttonName = $this->controller
->getButtonName();
165 $participantId = $this->_participantId
;
167 if ($buttonName == '_qf_ParticipantConfirm_next') {
168 //lets get contact id in session.
169 $session = CRM_Core_Session
::singleton();
170 $session->set('userID', $this->_csContactID
);
172 $this->postProcessHook();
174 //check user registration status is from pending class
175 $url = CRM_Utils_System
::url('civicrm/event/register',
176 "reset=1&id={$this->_eventId}&participantId={$participantId}"
178 CRM_Utils_System
::redirect($url);
180 elseif ($buttonName == '_qf_ParticipantConfirm_submit') {
181 //need to registration status to 'cancelled'.
183 $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'"));
184 $additionalParticipantIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($participantId);
186 $participantIds = array_merge([$participantId], $additionalParticipantIds);
187 $results = CRM_Event_BAO_Participant
::transitionParticipants($participantIds, $cancelledId, NULL, TRUE);
189 if (count($participantIds) > 1) {
190 $statusMessage = ts("%1 Event registration(s) have been cancelled.", [1 => count($participantIds)]);
193 $statusMessage = ts("Your Event Registration has been cancelled.");
196 if (!empty($results['mailedParticipants'])) {
197 foreach ($results['mailedParticipants'] as $key => $displayName) {
198 $statusMessage .= "<br />" . ts("Email has been sent to : %1", [1 => $displayName]);
202 $this->postProcessHook();
203 CRM_Core_Session
::setStatus($statusMessage);
204 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/event/info',
205 "reset=1&id={$this->_eventId}&noFullMsg=1",
206 FALSE, NULL, FALSE, TRUE