Source of file EventRegisterController.php
Size: 3,725 Bytes - Last Modified: 2021-12-23T10:25:27+00:00
/var/www/docs.ssmods.com/process/src/code/controllers/EventRegisterController.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 | <?php /** * Handles collecting the users details and creating a registration to an event * for them. * * @package silverstripe-eventmanagement */ class EventRegisterController extends Page_Controller { public static $url_handlers = array( '' => 'index' ); public static $allowed_actions = array( 'RegisterForm', 'confirm' ); protected $parent; protected $datetime; /** * Constructs a new controller for creating a registration. * * @param ContentController $parent * @param RegistrableDateTime $datetime */ public function __construct($parent, $datetime) { $this->parent = $parent; $this->datetime = $datetime; parent::__construct($parent->data()); } public function init() { parent::init(); if ($this->datetime->Event()->RequireLoggedIn && !Member::currentUserID()) { return Security::permissionFailure($this, array( 'default' => 'Please log in to register for this event.' )); } $form = $this->RegisterForm(); $expiry = $form->getExpiryDateTime(); if ($expiry && $expiry->InPast()) { $form->getSession()->Registration()->delete(); $form->getSession()->delete(); $message = _t('EventManagement.REGSESSIONEXPIRED', 'Your' . ' registration expired before it was completed. Please' . ' try ordering your tickets again.'); $form->sessionMessage($message, 'bad'); $this->redirect($this->Link()); } else { $form->clearMessage(); } } public function index() { $datetime = $this->datetime; $exclude = null; // If we have a current multiform ID, then exclude the linked // registration from the capacity calculation. if (isset($_GET['MultiFormSessionID'])) { $exclude = $this->RegisterForm()->getSession()->RegistrationID; } if ($datetime->getStartDateTime()->getTimestamp() < time()) { $data = array( 'Title' => $datetime->Event()->Title . ' Has Already Happened', 'Content' => '<p>You can no longer register for this event.</p>' ); } elseif ($datetime->getRemainingCapacity($exclude)) { $data = array( 'Title' => 'Register For ' . $datetime->Event()->Title, 'Form' => $this->RegisterForm() ); } else { $data = array( 'Title' => $datetime->Event()->Title . ' Is Full', 'Content' => '<p>There are no more places available at this event.</p>' ); } return $this->getViewer('index')->process($this->customise($data)); } /** * 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') ); } /** * @return RegistrableDateTime */ public function getDateTime() { return $this->datetime; } /** * @return EventRegisterForm */ public function RegisterForm() { return new EventRegisterForm($this, 'RegisterForm'); } /** * @param string $action * @return string */ public function Link($action = null) { return Controller::join_links( $this->parent->Link(), 'register', $action ); } } |