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
20 * This class generates form components for processing Event
23 class CRM_Event_Form_Registration_ParticipantConfirm
extends CRM_Event_Form_Registration
{
26 * Optional credit card return status code
28 * @see https://issues.civicrm.org/jira/browse/CRM-6060
30 protected $_cc = NULL;
33 * Set variables up before form is built.
37 public function preProcess() {
38 $this->_participantId
= CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
40 $this->_cc
= CRM_Utils_Request
::retrieve('cc', 'String', $this);
42 //get the contact and event id and assing to session.
45 if ($this->_participantId
) {
46 $params = ['id' => $this->_participantId
];
47 CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Participant', $params, $values,
48 ['contact_id', 'event_id', 'status_id']
52 $this->_participantStatusId
= $values['status_id'] ??
NULL;
53 $this->_eventId
= $values['event_id'] ??
NULL;
54 $csContactId = $values['contact_id'] ??
NULL;
56 // make sure we have right permission to edit this user
57 $this->_csContactID
= NULL;
58 if ($csContactId && $this->_eventId
) {
59 $session = CRM_Core_Session
::singleton();
60 if ($csContactId == $session->get('userID')) {
61 $this->_csContactID
= $csContactId;
64 if (CRM_Contact_BAO_Contact_Permission
::validateChecksumContact($csContactId, $this)) {
65 //since we have landing page so get this contact
66 //id in session if user really want to walk wizard.
67 $this->_csContactID
= $csContactId;
72 if (!$this->_csContactID
) {
73 $config = CRM_Core_Config
::singleton();
74 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
);
79 * Build the form object.
83 public function buildQuickForm() {
84 $params = ['id' => $this->_eventId
];
86 CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Event', $params, $values,
91 // only pending status class family able to confirm.
94 if (array_key_exists($this->_participantStatusId
,
95 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'")
98 //need to confirm that though participant confirming
99 //registration - but is there enough space to confirm.
100 $emptySeats = CRM_Event_BAO_Participant
::eventFull($this->_eventId
, TRUE, FALSE, TRUE, FALSE, TRUE);
101 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_participantId
);
102 $requireSpace = 1 +
count($additionalIds);
103 if ($emptySeats !== NULL && ($requireSpace > $emptySeats)) {
104 $statusMsg = ts("Unfortunately there are currently no available spaces for the %1 event.", [1 => $values['title']]);
107 if ($this->_cc
== 'fail') {
108 $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.', [
109 1 => $values['title'],
113 $statusMsg = '<div class="bold">' . ts('Confirm your registration for %1.', [
114 1 => $values['title'],
115 ]) . '</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>';
117 $buttons = array_merge($buttons, [
120 'name' => ts('Confirm Registration'),
121 'spacing' => ' ',
128 // status class other than Negative should be able to cancel registration.
129 if (array_key_exists($this->_participantStatusId
,
130 CRM_Event_PseudoConstant
::participantStatus(NULL, "class != 'Negative'")
132 $cancelConfirm = ts('Are you sure you want to cancel your registration for this event?');
133 $buttons = array_merge($buttons, [
136 'name' => ts('Cancel Registration'),
137 'spacing' => ' ',
138 'js' => ['onclick' => 'return confirm(\'' . $cancelConfirm . '\');'],
142 $statusMsg = ts('You can cancel your registration for %1 by clicking "Cancel Registration".', [1 => $values['title']]);
146 $statusMsg = ts("Your registration for %1 has already been cancelled. No further action is needed.",
147 [1 => $values['title']]
150 $this->assign('statusMsg', $statusMsg);
152 $this->addButtons($buttons);
156 * Process the form submission.
161 public function postProcess() {
163 $buttonName = $this->controller
->getButtonName();
164 $participantId = $this->_participantId
;
166 if ($buttonName == '_qf_ParticipantConfirm_next') {
167 //lets get contact id in session.
168 $session = CRM_Core_Session
::singleton();
169 $session->set('userID', $this->_csContactID
);
171 $this->postProcessHook();
173 //check user registration status is from pending class
174 $url = CRM_Utils_System
::url('civicrm/event/register',
175 "reset=1&id={$this->_eventId}&participantId={$participantId}"
177 CRM_Utils_System
::redirect($url);
179 elseif ($buttonName == '_qf_ParticipantConfirm_submit') {
180 //need to registration status to 'cancelled'.
182 $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'"));
183 $additionalParticipantIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($participantId);
185 $participantIds = array_merge([$participantId], $additionalParticipantIds);
186 $results = CRM_Event_BAO_Participant
::transitionParticipants($participantIds, $cancelledId, NULL, TRUE);
188 if (count($participantIds) > 1) {
189 $statusMessage = ts("%1 Event registration(s) have been cancelled.", [1 => count($participantIds)]);
192 $statusMessage = ts("Your Event Registration has been cancelled.");
195 if (!empty($results['mailedParticipants'])) {
196 foreach ($results['mailedParticipants'] as $key => $displayName) {
197 $statusMessage .= "<br />" . ts("Email has been sent to : %1", [1 => $displayName]);
201 $this->postProcessHook();
202 CRM_Core_Session
::setStatus($statusMessage);
203 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/event/info',
204 "reset=1&id={$this->_eventId}&noFullMsg=1",
205 FALSE, NULL, FALSE, TRUE