/**
  * Handles validating the final step and writing the tickets data to the
  * registration object.
  */
 public function finish($data, $form)
 {
     parent::finish($data, $form);
     $step = $this->getCurrentStep();
     $datetime = $this->getController()->getDateTime();
     $registration = $this->session->getRegistration();
     $ticketsStep = $this->getSavedStepByClass('EventRegisterTicketsStep');
     $tickets = $ticketsStep->loadData();
     // Check that the requested tickets are still available.
     if (!$this->validateTickets($tickets['Tickets'], $form)) {
         Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
         $this->controller->redirectBack();
         return false;
     }
     // Validate the final step.
     if (!$step->validateStep($data, $form)) {
         Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
         $this->controller->redirectBack();
         return false;
     }
     $this->session->delete();
     // If the registrations is already valid, then send a details email.
     if ($registration->Status == 'Valid') {
         EventRegistrationDetailsEmail::factory($registration)->send();
     }
     $this->extend('onRegistrationComplete', $registration);
     $this->controller->redirect(Controller::join_links($datetime->Event()->Link(), 'registration', $registration->ID, '?token=' . $registration->Token));
 }
 /**
  * Handles validating the final step and writing the tickets data to the
  * registration object.
  */
 public function finish($data, $form)
 {
     $step = $this->getCurrentStep();
     $datetime = $this->getController()->getDateTime();
     $registration = $this->session->getRegistration();
     $ticketsStep = $this->getSavedStepByClass('EventRegisterTicketsStep');
     $tickets = $ticketsStep->loadData();
     // Check that the requested tickets are still available.
     if (!$this->validateTickets($tickets['Tickets'], $form)) {
         Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
         $this->controller->redirectBack();
         return false;
     }
     $success = parent::finish($data, $form);
     if ($success === false) {
         return false;
     }
     // see whether we've been redirected by the step (most typically with Payment steps)
     $controller = Controller::curr();
     /* @var $controller Controller */
     if ($controller->redirectedTo()) {
         return;
     }
     $this->session->delete();
     // If the registrations is already valid, then send a details email.
     if ($registration->Status == 'Valid') {
         EventRegistrationDetailsEmail::factory($registration)->send();
     }
     $this->extend('onRegistrationComplete', $registration);
     $this->controller->redirect(Controller::join_links($datetime->Event()->Link(), 'registration', $registration->ID, '?token=' . $registration->Token));
 }
 /**
  * Handles a user clicking on a registration confirmation link in an email.
  */
 public function confirm($request)
 {
     $id = $request->param('ID');
     $token = $request->getVar('token');
     if (!($rego = DataObject::get_by_id('EventRegistration', $id))) {
         return $this->httpError(404);
     }
     if ($rego->Token != $token) {
         return $this->httpError(403);
     }
     if ($rego->Status != 'Unconfirmed') {
         return $this->redirect($rego->Link());
     }
     try {
         $rego->Status = 'Valid';
         $rego->write();
         EventRegistrationDetailsEmail::factory($rego)->send();
     } catch (ValidationException $e) {
         return array('Title' => 'Could Not Confirm Registration', 'Content' => '<p>' . $e->getResult()->message() . '</p>');
     }
     return array('Title' => $this->datetime->Event()->AfterConfirmTitle, 'Content' => $this->datetime->Event()->obj('AfterConfirmContent'));
 }
 /**
  * Handles validating the final step and writing the tickets data to the
  * registration object.
  */
 public function finish($data, $form)
 {
     parent::finish($data, $form);
     $step = $this->getCurrentStep();
     $datetime = $this->getController()->getDateTime();
     $registration = $this->session->getRegistration();
     $ticketsStep = $this->getSavedStepByClass('EventRegisterTicketsStep');
     $tickets = $ticketsStep->loadData();
     // Check that the requested tickets are still available.
     if (!$this->validateTickets($tickets['Tickets'], $form)) {
         Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
         Director::redirectBack();
         return false;
     }
     // Validate the final step.
     if (!$step->validateStep($data, $form)) {
         Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
         Director::redirectBack();
         return false;
     }
     // Reload the first step fields into a form, then save it into the
     // registration object.
     $ticketsStep->setForm($form);
     $fields = $ticketsStep->getFields();
     $form = new Form($this, '', $fields, new FieldSet());
     $form->loadDataFrom($tickets);
     $form->saveInto($registration);
     if ($member = Member::currentUser()) {
         $registration->Name = $member->getName();
         $registration->Email = $member->Email;
     }
     $registration->TimeID = $datetime->ID;
     $registration->MemberID = Member::currentUserID();
     $total = $ticketsStep->getTotal();
     $registration->Total->setCurrency($total->getCurrency());
     $registration->Total->setAmount($total->getAmount());
     foreach ($tickets['Tickets'] as $id => $quantity) {
         if ($quantity) {
             $registration->Tickets()->add($id, array('Quantity' => $quantity));
         }
     }
     $registration->write();
     $this->session->delete();
     // If the registrations is already valid, then send a details email.
     if ($registration->Status == 'Valid') {
         EventRegistrationDetailsEmail::factory($registration)->send();
     }
     $this->extend('onRegistrationComplete', $registration);
     return Director::redirect(Controller::join_links($datetime->Event()->Link(), 'registration', $registration->ID, '?token=' . $registration->Token));
 }