/**
  * Read ShortURL key from request and redirect to the full URL from the matching
  * CheckfrontShortenedURL record.
  *
  * @param SS_HTTPRequest $request
  *
  * @return SS_HTTPResponse
  */
 public function redirect(SS_HTTPRequest $request)
 {
     if ($shortURL = $request->param('ShortURL')) {
         if ($fullURL = CheckfrontShortenedURL::get_url_by_key($shortURL)) {
             return parent::redirect($fullURL);
         }
     }
     $this->httpError("Bad URL");
 }
 public static function key_exists($key)
 {
     return CheckfrontShortenedURL::get()->filter('Key', $key)->count() != 0;
 }
 /**
  * Returns and shortened URL which will redirect from CheckfrontModule.config.shortened_endpoint to
  * the full booking path when hit.
  *
  * @param $accessKey
  * @param $itemID
  * @param $startDate
  * @param $endDate
  * @param $linkType
  * @param $userType
  * @param $paymentType
  *
  * @return String
  * @throws ValidationException
  * @throws null
  */
 protected static function makeLink($accessKey, $itemID, $startDate, $endDate, $linkType, $userType, $paymentType)
 {
     $endPoint = Controller::join_links(CheckfrontModule::PrivateEndPoint, 'package');
     $fullURL = CheckfrontModule::make_link($accessKey, $endPoint, $itemID, $startDate, $endDate, $linkType, $userType, $paymentType);
     $shortURL = new CheckfrontShortenedURL(array('URL' => $fullURL));
     $shortURL->write();
     return Controller::join_links(Director::absoluteBaseURL(), CheckfrontModule::shorturl_endpoint(), $shortURL->Key);
 }