public function hookDisplayLeftColumn() { if ($this->context->controller->php_self == 'category') { $this->context->controller->addJS(_PS_MODULE_DIR_ . $this->name . '/views/js/wkhotelfilterblock.js'); $this->context->controller->addCSS(_PS_MODULE_DIR_ . $this->name . '/views/css/wkhotelfilterblock.css'); $all_feat = FeatureCore::getFeatures($this->context->language->id); $htl_id_category = Tools::getValue('id_category'); $id_hotel = HotelBranchInformation::getHotelIdByIdCategory($htl_id_category); $max_adult = HotelRoomType::getMaxAdults($id_hotel); $max_child = HotelRoomType::getMaxChild($id_hotel); $category = new Category($htl_id_category); if (!($date_from = Tools::getValue('date_from'))) { $date_from = date('Y-m-d'); $date_to = date('Y-m-d', strtotime($date_from) + 86400); } if (!($date_to = Tools::getValue('date_to'))) { $date_to = date('Y-m-d', strtotime($date_from) + 86400); } $obj_rm_type = new HotelRoomType(); $room_types = $obj_rm_type->getIdProductByHotelId($id_hotel); $prod_price = array(); if ($room_types) { foreach ($room_types as $key => $value) { $prod_price[] = Product::getPriceStatic($value['id_product']); } } if (Configuration::get('PS_REWRITING_SETTINGS')) { $cat_link = $this->context->link->getCategoryLink($category) . '?date_from=' . $date_from . '&date_to=' . $date_to; } else { $cat_link = $this->context->link->getCategoryLink($category) . '&date_from=' . $date_from . '&date_to=' . $date_to; } $currency = $this->context->currency; $config = $this->getConfigFieldsValues(); $obj_booking_detail = new HotelBookingDetail(); $num_days = $obj_booking_detail->getNumberOfDays($date_from, $date_to); $ratting_img = _MODULE_DIR_ . $this->name . '/views/img/stars-sprite-image.png'; $this->context->smarty->assign(array('all_feat' => $all_feat, 'max_adult' => $max_adult, 'max_child' => $max_child, 'cat_link' => $cat_link, 'ratting_img' => $ratting_img, 'currency' => $currency, 'date_from' => $date_from, 'date_to' => $date_to, 'num_days' => $num_days, 'config' => $config, 'min_price' => $prod_price ? min($prod_price) : 0, 'max_price' => $prod_price ? max($prod_price) : 0)); return $this->display(__FILE__, 'htlfilterblock.tpl'); } }
public function getBookingData($date_from, $date_to, $hotel_id, $room_type, $adult = 0, $children = 0, $num_rooms = 1, $for_calendar = 0, $search_available = 1, $search_partial = 1, $search_booked = 1, $search_unavai = 1, $id_cart = 0, $id_guest = 0, $search_cart_rms = 0) { $date_from = date('Y-m-d H:i:s', strtotime($date_from)); $date_to = date('Y-m-d H:i:s', strtotime($date_to)); $obj_room_info = new HotelRoomInformation(); //For check-in and check-out time // // $obj_hotel_info = new HotelBranchInformation(); // $hotel_info = $obj_hotel_info->hotelBranchInfoById($hotel_id); // $date_from = date('Y-m-d H:i:s', strtotime("$date_from +".date('H',strtotime($hotel_info['check_in']))." hours +".date('i', strtotime($hotel_info['check_in']))." minutes")); // $date_to = date('Y-m-d H:i:s', strtotime("$date_to +".date('H', strtotime($hotel_info['check_out']))." hours +".date('i', strtotime($hotel_info['check_out']))." minutes")); $obj_rm_type = new HotelRoomType(); $room_types = $obj_rm_type->getIdProductByHotelId($hotel_id, $room_type); if ($room_types) { $total_rooms = 0; $num_booked = 0; $num_unavail = 0; $num_avail = 0; $num_part_avai = 0; $num_cart = 0; foreach ($room_types as $key => $room_type) { $total_rooms += $obj_room_info->getHotelRoomInfo($room_type['id_product'], $hotel_id, 1); $product_name = (new Product((int) $room_type['id_product']))->name[Configuration::get('PS_LANG_DEFAULT')]; if ($search_cart_rms) { $sql = "SELECT cbd.id_product, cbd.id_room, cbd.id_hotel, cbd.booking_type, cbd.comment, rf.room_num, cbd.date_from, cbd.date_to \n\t\t\t\t\t\t\tFROM `" . _DB_PREFIX_ . "htl_cart_booking_data` AS cbd\n\t\t\t\t\t\t\tINNER JOIN `" . _DB_PREFIX_ . "htl_room_information` AS rf ON (rf.id = cbd.id_room)\n\t\t\t\t\t\t\tWHERE cbd.id_hotel=" . $hotel_id . " AND cbd.id_product =" . $room_type['id_product'] . " AND cbd.id_cart = " . $id_cart . " AND cbd.id_guest =" . $id_guest; $cart_rooms = Db::getInstance()->executeS($sql); $num_cart += count($cart_rooms); } if ($search_booked) { $sql = "SELECT bd.id_product, bd.id_room, bd.id_hotel, bd.id_customer, bd.booking_type, bd.id_status AS booking_status, bd.comment, rf.room_num, bd.date_from, bd.date_to \n\t\t\t\t\t\t\tFROM `" . _DB_PREFIX_ . "htl_booking_detail` AS bd\n\t\t\t\t\t\t\tINNER JOIN `" . _DB_PREFIX_ . "htl_room_information` AS rf ON (rf.id = bd.id_room)\n\t\t\t\t\t\t\tWHERE bd.id_hotel=" . $hotel_id . " AND bd.id_product =" . $room_type['id_product'] . " AND bd.date_from <= '{$date_from}' AND bd.date_to >='{$date_to}'"; $booked_rooms = Db::getInstance()->executeS($sql); $num_booked += count($booked_rooms); } if ($search_unavai) { $sql = "SELECT `id_product`, `id_hotel`, `room_num`, `comment` AS `room_comment` FROM `" . _DB_PREFIX_ . "htl_room_information` WHERE id_hotel=" . $hotel_id . " AND id_product =" . $room_type['id_product'] . " AND id_status = 2"; $unavail_rooms = Db::getInstance()->executeS($sql); $num_unavail += count($unavail_rooms); } if ($search_available) { $exclude_ids = "SELECT id_room \n\t\t\t\t\t\t\t\tFROM " . _DB_PREFIX_ . "htl_booking_detail \n\t\t\t\t\t\t\t\tWHERE (date_from <= '{$date_from}' AND date_to > '{$date_from}' AND date_to <= '{$date_to}') OR (date_from > '{$date_from}' AND date_to < '{$date_to}') OR (date_from >= '{$date_from}' AND date_from < '{$date_to}' AND date_to >= '{$date_to}') OR (date_from < '{$date_from}' AND date_to > '{$date_to}')"; if (!empty($id_cart) && !empty($id_guest)) { $exclude_ids .= " UNION\n\t\t\t\t\t\t\t\tSELECT id_room \n\t\t\t\t\t\t\t\tFROM " . _DB_PREFIX_ . "htl_cart_booking_data \n\t\t\t\t\t\t\t\tWHERE id_cart=" . $id_cart . " AND id_guest=" . $id_guest . " AND ((date_from <= '{$date_from}' AND date_to > '{$date_from}' AND date_to <= '{$date_to}') OR (date_from > '{$date_from}' AND date_to < '{$date_to}') OR (date_from >= '{$date_from}' AND date_from < '{$date_to}' AND date_to >= '{$date_to}') OR (date_from < '{$date_from}' AND date_to > '{$date_to}'))"; } $sql = "SELECT ri.`id` AS `id_room`, ri.`id_product`, ri.`id_hotel`, ri.`room_num`, ri.`comment` AS `room_comment` \n\t\t\t\t\t\t\tFROM `" . _DB_PREFIX_ . "htl_room_information` AS ri "; if ($adult || $children) { $sql .= "INNER JOIN " . _DB_PREFIX_ . "htl_room_type AS rt ON (rt.id_product = ri.id_product AND rt.id_hotel = ri.id_hotel"; if ($adult) { $sql .= " AND rt.adult >= " . $adult; } if ($children) { $sql .= " AND rt.children >= " . $children; } $sql .= ")"; } $sql .= " WHERE ri.id_hotel=" . $hotel_id . " AND ri.id_product=" . $room_type['id_product'] . " AND ri.id_status = 1 AND ri.id NOT IN (" . $exclude_ids . ")"; $avai_rooms = Db::getInstance()->executeS($sql); $num_avail += count($avai_rooms); } if ($search_partial) { $sql = "SELECT bd.id_product, bd.id_room, bd.id_hotel, bd.id_customer, bd.booking_type, bd.id_status AS booking_status, bd.comment AS `room_comment`, rf.room_num, bd.date_from, bd.date_to\n\t\t\t\t\t\t\tFROM `" . _DB_PREFIX_ . "htl_booking_detail` AS bd \n\t\t\t\t\t\t\tINNER JOIN `" . _DB_PREFIX_ . "htl_room_information` AS rf ON (rf.id = bd.id_room AND rf.id_status = 1)\n\t\t\t\t\t\t\tWHERE bd.id_hotel=" . $hotel_id . " AND bd.id_product=" . $room_type['id_product'] . " AND ((bd.date_from <= '{$date_from}' AND bd.date_to > '{$date_from}' AND bd.date_to < '{$date_to}') OR (bd.date_from > '{$date_from}' AND bd.date_from < '{$date_to}' AND bd.date_to >= '{$date_to}') OR (bd.date_from > '{$date_from}' AND bd.date_from < '{$date_to}' AND bd.date_to < '{$date_to}'))"; $partial_avai_rooms = Db::getInstance()->executeS($sql); $rm_part_avai = count($partial_avai_rooms); $this->all_dates_arr = $this->createDateRangeArray($date_from, $date_to, 1); if (!$for_calendar) { foreach ($partial_avai_rooms as $r_key => $r_val) { if ($r_val['date_from'] <= $date_from && $r_val['date_to'] > $date_from && $r_val['date_to'] < $date_to) { $forRange = $this->createDateRangeArray($r_val['date_to'], $date_to); $available_dates = $this->getPartialRange($forRange); } elseif ($r_val['date_from'] > $date_from && $r_val['date_from'] < $date_to && $r_val['date_to'] >= $date_to) { $forRange = $this->createDateRangeArray($date_from, $r_val['date_from']); $available_dates = $this->getPartialRange($forRange); } elseif ($r_val['date_from'] > $date_from && $r_val['date_from'] < $date_to && $r_val['date_to'] > $date_from && $r_val['date_to'] < $date_to) { $forRange1 = $this->createDateRangeArray($date_from, $r_val['date_from']); $init_range = $this->getPartialRange($forRange1); $forRange2 = $this->createDateRangeArray($r_val['date_to'], $date_to); $last_range = $this->getPartialRange($forRange2); $available_dates = array_merge($init_range, $last_range); } $partial_avai_rooms[$r_key]['avai_dates'] = $available_dates; } if (!empty($this->all_dates_arr)) { $num_unavail += $rm_part_avai; $rm_part_avai = 0; $unavail_rooms = array_merge($unavail_rooms, $partial_avai_rooms); $partial_avai_rooms = false; } $num_part_avai += $rm_part_avai; } } if (!$for_calendar) { $booking_data['rm_data'][$key]['name'] = $product_name; $booking_data['rm_data'][$key]['id_product'] = (new Product((int) $room_type['id_product']))->id; if ($search_available) { $booking_data['rm_data'][$key]['data']['available'] = $avai_rooms; } if ($search_unavai) { $booking_data['rm_data'][$key]['data']['unavailable'] = $unavail_rooms; } if ($search_booked) { $booking_data['rm_data'][$key]['data']['booked'] = $booked_rooms; } if ($search_partial) { $booking_data['rm_data'][$key]['data']['partially_available'] = $partial_avai_rooms; } if ($search_cart_rms) { $booking_data['rm_data'][$key]['data']['cart_rooms'] = $cart_rooms; } } } $booking_data['stats']['total_rooms'] = $total_rooms; if ($search_booked) { $booking_data['stats']['num_booked'] = $num_booked; } if ($search_unavai) { $booking_data['stats']['num_unavail'] = $num_unavail; } if ($search_available) { $booking_data['stats']['num_avail'] = $num_avail; } if ($search_partial) { $booking_data['stats']['num_part_avai'] = $num_part_avai; } if ($search_partial) { $booking_data['stats']['num_cart'] = $num_cart; } return $booking_data; } }
public function processStatus() { if (Validate::isLoadedObject($object = $this->loadObject())) { if ($object->id && $object->active) { $obj_htl_rm_info = new HotelRoomType(); $ids_product = $obj_htl_rm_info->getIdProductByHotelId($object->id); if (isset($ids_product) && $ids_product) { foreach ($ids_product as $key_prod => $value_prod) { $obj_product = new Product($value_prod['id_product']); if ($obj_product->active) { $obj_product->toggleStatus(); } } } } } else { $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } parent::processStatus(); }