Ejemplo n.º 1
0
 public static function getBookedDates($roomSlug = null)
 {
     // Retrieve room id from slug
     if (isset($roomSlug)) {
         $room = Room::select('id')->where('slug', '=', $roomSlug)->first();
         $roomId = $room->id;
     }
     // Select booked dates
     // don't know why this doesn't work when separate requests oO
     if (isset($roomSlug)) {
         $booking = self::select('arrival', 'departure')->where('room_id', '=', $roomId)->whereValidated(1)->get();
     } else {
         // No room id ? Get all booked dates of all rooms (in this case we consider that only one room exists)
         $booking = self::select('arrival', 'departure')->whereValidated(1)->get();
     }
     // Construct array of booked dates
     $bookedDates = [];
     foreach ($booking as $d) {
         $arrival = explode('-', $d->{"arrival"});
         $departure = explode('-', $d->{"departure"});
         if (isset($arrival[0]) && !empty($arrival[0]) && isset($departure[0]) && !empty($departure[0])) {
             // Compute difference between arrival and departure, how many nights are booked ?
             $aDate = Carbon::create($arrival[0], $arrival[1], $arrival[2], 0);
             $dDate = Carbon::create($departure[0], $departure[1], $departure[2], 0);
             $diffInDays = $dDate->diffInDays($aDate);
             // for each booked day, add entry in the array
             for ($i = 1; $i <= $diffInDays; $i++) {
                 $nextDate = $aDate->addDay()->format("Y-m-d");
                 $nextDate = explode('-', $nextDate);
                 // Place year into array
                 if (!in_array((int) $nextDate[2], $bookedDates)) {
                     $bookedDates[''] = [(int) $nextDate[2] => []];
                 }
                 // Place month into array
                 if (!isset($bookedDates[(int) $nextDate[0]][(int) $nextDate[1]])) {
                     $bookedDates[(int) $nextDate[0]][(int) $nextDate[1]] = [];
                 }
                 // Place day into array
                 if (!isset($bookedDates[(int) $nextDate[0]][(int) $nextDate[1]][(int) $nextDate[2]])) {
                     $bookedDates[(int) $nextDate[0]][(int) $nextDate[1]][] = (int) $nextDate[2];
                 }
             }
         }
     }
     return $bookedDates;
 }
 public static function getBookedDates($room_slug = null)
 {
     // Retrieve room id from slug
     if (isset($room_slug)) {
         $room = Room::select('id')->whereSlug($room_slug)->first();
         $room_id = $room->id;
     }
     // Select booked dates
     $booking = self::select('arrival', 'departure');
     if (isset($room_slug)) {
         $booking = $booking->whereRoomId($room_id);
     }
     $booking = $booking->whereValidated(1)->get();
     // Construct array of booked dates
     $bookedDates = [];
     foreach ($booking as $d) {
         $arrival = explode('-', $d->{"arrival"});
         $departure = explode('-', $d->{"departure"});
         if (isset($arrival[0]) && !empty($arrival[0]) && isset($departure[0]) && !empty($departure[0])) {
             // Compute difference between arrival and departure, how many nights are booked ?
             $aDate = Carbon::create($arrival[0], $arrival[1], $arrival[2], 0);
             $dDate = Carbon::create($departure[0], $departure[1], $departure[2], 0);
             $diffInDays = $dDate->diffInDays($aDate);
             // for each booked day, add entry in the array
             for ($i = 1; $i <= $diffInDays; $i++) {
                 $nextDate = $aDate->addDay()->format("Y-m-d");
                 $nextDate = explode('-', $nextDate);
                 // Place year into array
                 if (!in_array((int) $nextDate[2], $bookedDates)) {
                     $bookedDates[''] = [(int) $nextDate[2] => []];
                 }
                 // Place month into array
                 if (!isset($bookedDates[(int) $nextDate[0]][(int) $nextDate[1]])) {
                     $bookedDates[(int) $nextDate[0]][(int) $nextDate[1]] = [];
                 }
                 // Place day into array
                 if (!isset($bookedDates[(int) $nextDate[0]][(int) $nextDate[1]][(int) $nextDate[2]])) {
                     $bookedDates[(int) $nextDate[0]][(int) $nextDate[1]][] = (int) $nextDate[2];
                 }
             }
         }
     }
     return $bookedDates;
 }
 public function boot()
 {
     /*
      * Register menu items for the RainLab.Pages and RainLab.Sitemap plugin
      */
     Event::listen('pages.menuitem.listTypes', function () {
         return ['all-rooms' => 'All rooms'];
     });
     Event::listen('pages.menuitem.getTypeInfo', function ($type) {
         if ($type == 'all-rooms') {
             return Room::getMenuTypeInfo($type);
         }
     });
     Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) {
         if ($type == 'all-rooms') {
             return Room::resolveMenuItem($item, $url, $theme);
         }
     });
 }
 /**
  * {@inheritDoc}
  */
 public function render()
 {
     $this->vars['preview_html'] = Room::formatHtml($this->model->content, true);
     return $this->makePartial('preview');
 }
Ejemplo n.º 5
0
 protected function listRooms()
 {
     return Room::make()->listFrontEnd(['room' => $this->propertyOrParam('roomParam')]);
 }
Ejemplo n.º 6
0
 protected function loadRoom()
 {
     $slug = $this->propertyOrParam('idParam');
     return RoomDetails::where('slug', '=', $slug)->first();
 }
 protected function listRooms()
 {
     return Room::make()->listFrontEnd(['room' => Settings::get('room_page_slug'), 'perPage' => $this->property('roomsPerPage')]);
 }
Ejemplo n.º 8
0
 public function onRefreshPreview()
 {
     $data = post('Room');
     $previewHtml = Room::formatHtml($data['content'], true);
     return ['preview' => $previewHtml];
 }