function generateCalendarData($year = 0, $month = 0) { $session = JFactory::getSession(); $userData = $_SESSION['userData']; $post = JRequest::get('post'); $get = JRequest::get('get'); if (!count($post)) { $post = $get; } if (!isset($post["hotel_id"])) { $post["hotel_id"] = JRequest::getInt('hotel_id'); } $year_start = $userData->year_start; $month_start = $userData->month_start; $day_start = 1; $year_end = $userData->year_end; $month_end = $userData->month_start; $day_end = date('t', mktime(0, 0, 0, $userData->month_start, 1, $userData->year_start)); $hotelId = $post["hotel_id"]; $currentRoom = $post["current_room"]; //dmp($currentRoom); $adults = $userData->adults; $children = $userData->children; //dmp($userData); if (isset($userData->roomGuests)) { $adults = $userData->roomGuests[$currentRoom - 1]; } $post["guest_adult"] = $adults; $post["guest_child"] = $userData->children; $post["rooms"] = $userData->rooms; if ($year != 0) { $post["year_start"] = $year; $post["year_end"] = $year; $year_start = $year; $year_end = $year; } if ($month != 0) { $post["month_start"] = $month; $post["month_end"] = $month; $month_start = $month; $month_end = $month; } $number_persons = $post["guest_adult"]; //dmp($post); $datasi = date("Y-m-d", mktime(0, 0, 0, $userData->month_start, $userData->day_start, $userData->year_start)); $dataei = date("Y-m-d", mktime(0, 0, 0, $userData->month_end, $userData->day_end, $userData->year_end)); $diff = abs(strtotime($dataei) - strtotime($datasi)); $years = floor($diff / (365 * 60 * 60 * 24)); $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24)); $initialNrDays = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24)); //dmp($initialNrDays); $datas = date("Y-m-d", mktime(0, 0, 0, $month_start, $day_start, $year_start)); $datae = date("Y-m-d", mktime(0, 0, 0, $month_end, $day_end + 7, $year_end)); //echo $adults." "; //dmp($adults); /* dmp($year_start); dmp($month_start); dmp($datas); dmp($datae); */ //exit; $offers = HotelService::getHotelOffers($hotelId, $datas, $datae, array(), $adults, $children); $rooms = HotelService::getHotelRooms($hotelId, $datas, $datae, array(), $adults, $children); $bookingsDays = BookingService::getNumberOfBookingsPerDay($hotelId, $datas, $datae); $hoteAvailability = HotelService::getHotelAvailabilyPerDay($hotelId, $datas, $datae); $temporaryReservedRooms = BookingService::getReservedRooms($userData->reservedItems); $temporaryReservedRooms["datas"] = $datasi; $temporaryReservedRooms["datae"] = $dataei; //dmp($temporaryReservedRooms); $roomsCalendar = HotelService::getRoomsCalendar($rooms, $initialNrDays, $adults, $children, $month_start, $year_start, $bookingsDays, $temporaryReservedRooms, $hoteAvailability); $offersCalendar = HotelService::getOffersCalendar($offers, $initialNrDays, $adults, $children, $month_start, $year_start, $bookingsDays, $temporaryReservedRooms, $hoteAvailability); //dmp($roomsCalendar); //dmp($offersCalendar); //combining the calendars $calendar = array_combine(array_merge(array_keys($roomsCalendar), array_keys($offersCalendar)), array_merge(array_values($roomsCalendar), array_values($offersCalendar))); //dmp($calendar); return $calendar; }
/** * Overrides the getItems method to attach additional metrics to the list. * * @return mixed An array of data items on success, false on failure. * * @since 1.6.1 */ public function getItems() { // Get a storage key. $store = $this->getStoreId('getItems'); // Try to load the data from internal storage. //if (!empty($this->cache[$store])) //{ // return $this->cache[$store]; //} // Load the list items. $items = parent::getItems(); // If emtpy or an error, just return. $month = $this->getState('filter.month'); $year = $month < date("n") ? date("Y") + 1 : date("Y"); $startDate = date("Y-m-d", mktime(0, 0, 0, $month, 1, $year)); $endDate = date("Y-m-d", mktime(0, 0, 0, $month + 1, 0, $year)); $app = JFactory::getApplication('administrator'); $hotelId = $app->getUserState('com_jhotelreservation.rooms.filter.hotel_id'); $roomId = $app->getUserState('com_jhotelreservation.edit.room.room_id'); $rId = JRequest::getVar("room_id", null); if (!empty($rId)) { $roomId = $rId; $app->setUserState('com_jhotelreservation.edit.room.room_id', $roomId); } if (empty($items)) { $items = $this->getDefaultRates($month, $year); $this->setState('filter.newRates', true); } $this->setState('filter.start_date', JHotelUtil::convertToFormat($startDate)); $this->setState('filter.end_date', JHotelUtil::convertToFormat($endDate)); JRequest::setVar("filter_start_date", $startDate); JRequest::setVar("filter_end_date", $endDate); JRequest::setVar("filter_room_type", $endDate); JRequest::setVar("hotel_id", $hotelId); JRequest::setVar("filter_room_type", $roomId); $hotelAvailability = HotelService::getHotelAvailabilyPerDay($hotelId, $startDate, $endDate); //dmp($roomId); $report = new JHotelReservationModelReports(); $availabilty = $report->getAvailabilityReport(); //dmp($availabilty); //dmp($roomId); foreach ($items as $item) { //dmp($item->date); if (isset($availabilty[$item->date][$roomId])) { $item->booked = $availabilty[$item->date][$roomId][1]; } else { $item->booked = 0; } //dmp($item->booked); if (isset($availabilty[$item->date][$roomId])) { $item->available = intval($item->availability) - intval($availabilty[$item->date][$roomId][1]); } else { $item->available = $item->availability; } $item->isHotelAvailable = $hotelAvailability[$item->date]; } // Add the items to the internal cache. $this->cache[$store] = $items; return $this->cache[$store]; }