Exemplo n.º 1
0
 public function submit($data, $form)
 {
     $automap = Catalogue::create();
     $form->saveInto($automap);
     $automap->ID = $data['ID'];
     $automap->Last_updated = SS_Datetime::now()->format('Y-m-d H:i:s');
     $automap->validate == false ? $id = $automap->write() : ($id = null);
     if ($id !== null) {
         Session::setFormMessage($form->FormName(), $data['Video_title'], 'has been saved to the catalogue. <br><a href="video-profile/' . $id . '">Preview changes</a>', 'success');
         $this->redirect($this->Link() . "edit/{$id}");
     } elseif ($id === null) {
         Session::setFormMessage($form->FormName(), $data['Video_title'], " is already in the catalogue.", 'bad');
         $this->redirect($this->Link());
     } else {
         Session::setFormMessage($form->FormName(), 'Something went wrong.');
     }
 }
 /**
  * Parse URL parameters and set the filters
  *
  * @param boolean $produceErrorMessages Set to false to omit session messages.
  * @return array
  */
 public function parseParams($produceErrorMessages = true)
 {
     $tag = $this->request->getVar('tag');
     $from = $this->request->getVar('from');
     $to = $this->request->getVar('to');
     $year = $this->request->getVar('year');
     $month = $this->request->getVar('month');
     if ($tag == '') {
         $tag = null;
     }
     if ($from == '') {
         $from = null;
     }
     if ($to == '') {
         $to = null;
     }
     if ($year == '') {
         $year = null;
     }
     if ($month == '') {
         $month = null;
     }
     if (isset($tag)) {
         $tag = (int) $tag;
     }
     if (isset($from)) {
         $from = urldecode($from);
         $parser = new SS_Datetime();
         $parser->setValue($from);
         $from = $parser->Format('Y-m-d');
     }
     if (isset($to)) {
         $to = urldecode($to);
         $parser = new SS_Datetime();
         $parser->setValue($to);
         $to = $parser->Format('Y-m-d');
     }
     if (isset($year)) {
         $year = (int) $year;
     }
     if (isset($month)) {
         $month = (int) $month;
     }
     // If only "To" has been provided filter by single date. Normalise by swapping with "From".
     if (isset($to) && !isset($from)) {
         list($to, $from) = array($from, $to);
     }
     // Flip the dates if the order is wrong.
     if (isset($to) && isset($from) && strtotime($from) > strtotime($to)) {
         list($to, $from) = array($from, $to);
         if ($produceErrorMessages) {
             Session::setFormMessage('Form_DateRangeForm', _t('DateUpdateHolder.FilterAppliedMessage', 'Filter has been applied with the dates reversed.'), 'warning');
         }
     }
     // Notify the user that filtering by single date is taking place.
     if (isset($from) && !isset($to)) {
         if ($produceErrorMessages) {
             Session::setFormMessage('Form_DateRangeForm', _t('DateUpdateHolder.DateRangeFilterMessage', 'Filtered by a single date.'), 'warning');
         }
     }
     return array('tag' => $tag, 'from' => $from, 'to' => $to, 'year' => $year, 'month' => $month);
 }
 /**
  * -    setup session in checkfront
  * -    add package to session
  * -    add items to session
  * -    call the 'book' endpoint to make the booking
  *
  * @param SS_HTTPRequest $request
  *
  * @return CheckfrontForm
  */
 protected function book(SS_HTTPRequest $request)
 {
     $message = '';
     $messageType = '';
     $result = array();
     // only post request should route here
     $postVars = $request->postVars();
     try {
         $this->clearCheckfrontSession();
         $packageID = $this->getTokenInfo(CheckfrontModule::TokenItemIDIndex, $postVars[CheckfrontForm::AccessKeyFieldName]);
         if ($request->isPOST()) {
             $startDate = $request->postVar('StartDate');
             $endDate = $request->postVar('EndDate');
             $ratedPackageResponse = $this->api()->fetchPackage($packageID, $startDate, $endDate);
             if ($ratedPackageResponse->isValid()) {
                 $package = $ratedPackageResponse->getPackage();
                 $this->api()->addPackageToSession($package);
                 foreach ($postVars['ItemID'] as $index => $itemID) {
                     if (isset($postVars['Quantity'][$index])) {
                         if ($quantity = $postVars['Quantity'][$index]) {
                             /**
                              * CheckfrontAPIItemResponse
                              */
                             $response = $this->api()->fetchItem($itemID, $quantity, $startDate, $endDate);
                             if ($response->isValid()) {
                                 if ($item = $response->getItem()) {
                                     $this->api()->addItemToSession($item);
                                 }
                             } else {
                                 throw new CheckfrontBookingException($response->getMessage(), CheckfrontException::TypeError);
                             }
                         }
                     }
                 }
                 $bookingResponse = $this->api()->makeBooking(CheckfrontBookingModel::create_from_checkfront($postVars, 'from-form'));
                 if ($bookingResponse->isValid()) {
                     $paymentMethod = $this->getTokenInfo(CheckfrontModule::TokenPaymentTypeIndex, $postVars[CheckfrontForm::AccessKeyFieldName]);
                     if ($paymentMethod == CheckfrontModule::PaymentPayNow) {
                         $message = 'Thanks for booking, please click the link below to complete payment on your booking';
                         $messageType = CheckfrontException::TypeOK;
                         if ($paymentURL = $bookingResponse->getPaymentURL()) {
                             $result = array('PaymentURL' => $paymentURL);
                             $this()->redirect($paymentURL);
                         }
                     } else {
                         $message = 'Thanks for booking, you will receive email confirmation shortly';
                         $messageType = CheckfrontException::TypeOK;
                         $result = array('CurrentPackage' => $package, 'Booking' => $bookingResponse->getBooking(), 'Items' => $bookingResponse->getItems());
                     }
                 } else {
                     throw new CheckfrontBookingException($bookingResponse->getMessage(), CheckfrontException::TypeError);
                 }
             }
         }
     } catch (CheckfrontException $e) {
         $message = $e->getMessage();
         $messageType = $e->getType();
         $this->api()->clearSession();
         Session::setFormMessage(CheckfrontPackageBookingForm::FormName, $message, 'bad');
         $result = $this->buildBookingForm($request);
     }
     return array_merge(array(self::MessageKey => $message, self::MessageTypeKey => $messageType), $result);
 }