diff --git a/modules/hotelreservationsystem/classes/HotelImage.php b/modules/hotelreservationsystem/classes/HotelImage.php
index 1a94b8744a..0e153dea7b 100644
--- a/modules/hotelreservationsystem/classes/HotelImage.php
+++ b/modules/hotelreservationsystem/classes/HotelImage.php
@@ -99,7 +99,7 @@ public function deleteImage($force_delete = false)
* @param [int] $n [number of images per page for paginated images data]
* @return [array|boolean] [if data found returns array containing information of the images of the hotel which id is passed]
*/
- public function getImagesByHotelId($id_hotel, $p = 1, $n = null)
+ public function getImagesByHotelId($id_hotel, $p = 1, $n = null, $idLang = null)
{
$p = (int) $p;
$n = $n !== null ? (int) $n : $n; // n = null for no pagination
@@ -107,9 +107,16 @@ public function getImagesByHotelId($id_hotel, $p = 1, $n = null)
$p = 1;
}
- $sql = 'SELECT *
- FROM `'._DB_PREFIX_.'htl_image`
- WHERE `id_hotel` = '.(int) $id_hotel.
+ if (!$idLang) {
+ $idLang = (int) Context::getContext()->language->id;
+ }
+
+ $sql = 'SELECT hi.*, hicl.`name` AS `category_name`
+ FROM `'._DB_PREFIX_.'htl_image` hi
+ LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hicl
+ ON (hicl.`id_htl_image_category` = hi.`id_htl_image_category`
+ AND hicl.`id_lang` = '.(int) $idLang.')
+ WHERE hi.`id_hotel` = '.(int) $id_hotel.
($n ? ' LIMIT '.(int) (($p - 1) * $n).', '.(int) ($n) : '');
return Db::getInstance()->executeS($sql);
@@ -174,11 +181,12 @@ public static function getImageHotelId($id)
);
}
- public function uploadHotelImages($images, $idHotel)
+ public function uploadHotelImages($images, $idHotel, $idHtlImageCategory = 0)
{
if (isset($images) && $idHotel) {
$objHotelHelper = new HotelHelper();
$hotelImages = $images['tmp_name'];
+ $idHtlImageCategory = (int) $idHtlImageCategory;
if (is_array($images['tmp_name'])) {
foreach ($hotelImages as $image) {
$objHtlImage = new HotelImage();
@@ -189,6 +197,7 @@ public function uploadHotelImages($images, $idHotel)
$objHtlImage->cover = 1;
}
if ($objHtlImage->save()) {
+ self::updateImageCategory($objHtlImage->id, $idHtlImageCategory ?: null);
if ($path = $objHtlImage->getPathForCreation()) {
if (ImageManager::resize(
$image,
@@ -234,6 +243,7 @@ public function uploadHotelImages($images, $idHotel)
$objHtlImage->cover = 1;
}
if ($objHtlImage->save()) {
+ self::updateImageCategory($objHtlImage->id, $idHtlImageCategory ?: null);
if ($path = $objHtlImage->getPathForCreation()) {
if (ImageManager::resize(
$hotelImages,
@@ -265,6 +275,8 @@ public function uploadHotelImages($images, $idHotel)
$addedImage = array(
'id' => $objHtlImage->id,
'cover' => $objHtlImage->cover,
+ 'id_htl_image_category' => $idHtlImageCategory,
+ 'category_name' => HotelImageCategory::getCategoryName($idHtlImageCategory),
'image_link' => Context::getContext()->link->getMediaLink($objHtlImage->getImageLink($objHtlImage->id)),
);
return $addedImage;
@@ -312,4 +324,16 @@ public function getAllImages()
{
return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'htl_image`');
}
+
+ public static function updateImageCategory($idImage, $idHtlImageCategory = null)
+ {
+ return Db::getInstance()->update('htl_image',
+ array(
+ 'id_htl_image_category' => $idHtlImageCategory ? (int) $idHtlImageCategory : null,
+ ),
+ '`id` = '.(int) $idImage,
+ 0,
+ true
+ );
+ }
}
diff --git a/modules/hotelreservationsystem/classes/HotelImageCategory.php b/modules/hotelreservationsystem/classes/HotelImageCategory.php
new file mode 100644
index 0000000000..4f8f443892
--- /dev/null
+++ b/modules/hotelreservationsystem/classes/HotelImageCategory.php
@@ -0,0 +1,89 @@
+ 'htl_image_category',
+ 'primary' => 'id_htl_image_category',
+ 'multilang' => true,
+ 'fields' => array(
+ 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 128),
+ 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
+ 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
+ ),
+ );
+
+ public static function getImageCategories($idLang = null)
+ {
+ if (!$idLang) {
+ $idLang = (int) Context::getContext()->language->id;
+ }
+
+ $defaultLangId = (int) Configuration::get('PS_LANG_DEFAULT');
+
+ return Db::getInstance()->executeS(
+ 'SELECT hic.`id_htl_image_category`, COALESCE(hicl.`name`, hiclDefault.`name`) AS `name`
+ FROM `'._DB_PREFIX_.'htl_image_category` hic
+ LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hicl
+ ON (hicl.`id_htl_image_category` = hic.`id_htl_image_category`
+ AND hicl.`id_lang` = '.(int) $idLang.')
+ LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hiclDefault
+ ON (hiclDefault.`id_htl_image_category` = hic.`id_htl_image_category`
+ AND hiclDefault.`id_lang` = '.(int) $defaultLangId.')
+ WHERE COALESCE(hicl.`name`, hiclDefault.`name`) IS NOT NULL
+ ORDER BY `name` ASC'
+ );
+ }
+
+ public static function getCategoryName($idHtlImageCategory, $idLang = null)
+ {
+ $idHtlImageCategory = (int) $idHtlImageCategory;
+ if (!$idHtlImageCategory) {
+ return '';
+ }
+
+ if (!$idLang) {
+ $idLang = (int) Context::getContext()->language->id;
+ }
+
+ $defaultLangId = (int) Configuration::get('PS_LANG_DEFAULT');
+
+ return (string) Db::getInstance()->getValue(
+ 'SELECT COALESCE(hicl.`name`, hiclDefault.`name`) AS `name`
+ FROM `'._DB_PREFIX_.'htl_image_category` hic
+ LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hicl
+ ON (hicl.`id_htl_image_category` = hic.`id_htl_image_category`
+ AND hicl.`id_lang` = '.(int) $idLang.')
+ LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hiclDefault
+ ON (hiclDefault.`id_htl_image_category` = hic.`id_htl_image_category`
+ AND hiclDefault.`id_lang` = '.(int) $defaultLangId.')
+ WHERE hic.`id_htl_image_category` = '.(int) $idHtlImageCategory
+ );
+ }
+}
diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php
index ca44a28267..b81a27d782 100644
--- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php
+++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php
@@ -87,10 +87,27 @@ public function getModuleSql()
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_hotel` int(10) unsigned NOT NULL,
+ `id_htl_image_category` int(10) unsigned DEFAULT NULL,
`cover` tinyint(1) NOT NULL DEFAULT '0',
+ KEY `id_hotel` (`id_hotel`),
+ KEY `id_htl_image_category` (`id_htl_image_category`),
PRIMARY KEY (`id`)
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
+ "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image_category` (
+ `id_htl_image_category` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `date_add` datetime NOT NULL,
+ `date_upd` datetime NOT NULL,
+ PRIMARY KEY (`id_htl_image_category`)
+ ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
+
+ "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image_category_lang` (
+ `id_htl_image_category` int(10) unsigned NOT NULL,
+ `id_lang` int(10) unsigned NOT NULL,
+ `name` varchar(128) NOT NULL,
+ PRIMARY KEY (`id_htl_image_category`, `id_lang`)
+ ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;",
+
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_branch_features` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_hotel` int(10) unsigned NOT NULL,
@@ -578,6 +595,8 @@ public function dropTables()
`'._DB_PREFIX_.'htl_branch_info`,
`'._DB_PREFIX_.'htl_branch_info_lang`,
`'._DB_PREFIX_.'htl_image`,
+ `'._DB_PREFIX_.'htl_image_category`,
+ `'._DB_PREFIX_.'htl_image_category_lang`,
`'._DB_PREFIX_.'htl_branch_features`,
`'._DB_PREFIX_.'htl_features`,
`'._DB_PREFIX_.'htl_features_lang`,
diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php
index a2b5136766..ceaa20804c 100644
--- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php
+++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php
@@ -210,6 +210,8 @@ public function renderForm()
$idCountry = Tools::getValue('hotel_country');
}
+ $smartyVars['hotelImageCategories'] = HotelImageCategory::getImageCategories((int) $this->context->language->id);
+
// manage state option
$stateOptions = null;
if ($idCountry) {
@@ -869,7 +871,15 @@ public function ajaxProcessUploadHotelImages()
{
$response = array('success' => false);
$idHotel = Tools::getValue('id_hotel');
+ $idHtlImageCategory = (int) Tools::getValue('id_htl_image_category');
if ($idHotel) {
+ if ($idHtlImageCategory) {
+ if (!Validate::isLoadedObject(new HotelImageCategory($idHtlImageCategory))) {
+ $response['errors'][] = $this->l('Selected image category is invalid.');
+ $this->ajaxDie(json_encode($response));
+ }
+ }
+
$invalidImg = ImageManager::validateUpload(
$_FILES['hotel_image'],
Tools::getMaxUploadSize()
@@ -877,11 +887,15 @@ public function ajaxProcessUploadHotelImages()
if (!$invalidImg) {
// Add Hotel images
$objHotelImage = new HotelImage();
- $imageDetail = $objHotelImage->uploadHotelImages($_FILES['hotel_image'], $idHotel);
+ $imageDetail = $objHotelImage->uploadHotelImages($_FILES['hotel_image'],$idHotel,$idHtlImageCategory);
if ($imageDetail) {
$response['success'] = true;
$imageDetail['image_link'] = $this->context->link->getMediaLink($objHotelImage->getImageLink($imageDetail['id'],ImageType::getFormatedName('large')));
$imageDetail['image_link_small'] = $this->context->link->getMediaLink($objHotelImage->getImageLink($imageDetail['id'], ImageType::getFormatedName('small')));
+ $imageDetail['id_htl_image_category'] = $idHtlImageCategory;
+ if (!isset($imageDetail['category_name'])) {
+ $imageDetail['category_name'] = HotelImageCategory::getCategoryName($idHtlImageCategory);
+ }
$response['data']['image_info'] = $imageDetail;
// get image row
$this->context->smarty->assign(array(
diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php
new file mode 100644
index 0000000000..d35cd573bc
--- /dev/null
+++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php
@@ -0,0 +1,140 @@
+bootstrap = true;
+ $this->table = 'htl_image_category';
+ $this->className = 'HotelImageCategory';
+ $this->identifier = 'id_htl_image_category';
+ $this->lang = true;
+ $this->context = Context::getContext();
+
+ parent::__construct();
+
+ $this->_new_list_header_design = true;
+ $this->addRowAction('edit');
+ $this->addRowAction('delete');
+
+ $this->fields_list = array(
+ 'id_htl_image_category' => array(
+ 'title' => $this->l('ID'),
+ 'align' => 'center',
+ 'class' => 'fixed-width-xs',
+ ),
+ 'name' => array(
+ 'title' => $this->l('Name'),
+ 'align' => 'center',
+ ),
+ 'date_add' => array(
+ 'title' => $this->l('Created On'),
+ 'type' => 'datetime',
+ 'align' => 'center',
+ ),
+ );
+
+ $this->bulk_actions = array(
+ 'delete' => array(
+ 'text' => $this->l('Delete selected'),
+ 'icon' => 'icon-trash',
+ 'confirm' => $this->l('Delete selected items?'),
+ ),
+ );
+ }
+
+ public function initToolbar()
+ {
+ parent::initToolbar();
+ if (!$this->display || $this->display == 'list') {
+ $this->page_header_toolbar_btn['new'] = array(
+ 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
+ 'desc' => $this->l('Add new category'),
+ );
+ }
+ }
+
+ public function renderForm()
+ {
+ if (!$this->loadObject(true)) {
+ return;
+ }
+
+ $this->fields_form = array(
+ 'legend' => array(
+ 'title' => $this->l('Hotel Image Category'),
+ 'icon' => 'icon-tags',
+ ),
+ 'input' => array(
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Name'),
+ 'name' => 'name',
+ 'required' => true,
+ 'lang' => true,
+ 'col' => 4,
+ 'hint' => $this->l('Enter the name of the hotel image category.'),
+ ),
+ ),
+ 'submit' => array(
+ 'title' => $this->l('Save'),
+ ),
+ 'buttons' => array(
+ 'save-and-stay' => array(
+ 'title' => $this->l('Save and stay'),
+ 'name' => 'submitAdd'.$this->table.'AndStay',
+ 'type' => 'submit',
+ 'class' => 'btn btn-default pull-right',
+ 'icon' => 'process-icon-save',
+ ),
+ ),
+ );
+
+ return parent::renderForm();
+ }
+
+ public function processSave()
+ {
+ if (!$this->loadObject(true)) {
+ return;
+ }
+
+ $defaultLangId = (int) Configuration::get('PS_LANG_DEFAULT');
+ $defaultLanguage = Language::getLanguage($defaultLangId);
+ $languages = Language::getLanguages(false);
+
+ if (!trim(Tools::getValue('name_'.$defaultLangId))) {
+ $this->errors[] = $this->l('Category name is required at least in ').$defaultLanguage['name'];
+ } else {
+ foreach ($languages as $lang) {
+ $langName = trim(Tools::getValue('name_'.$lang['id_lang']));
+ if ($langName && !Validate::isCatalogName($langName)) {
+ $this->errors[] = $this->l('Invalid category name in ').$lang['name'];
+ }
+ }
+ }
+
+ return parent::processSave();
+ }
+}
diff --git a/modules/hotelreservationsystem/define.php b/modules/hotelreservationsystem/define.php
index e8a7cc909c..e7b41db6c5 100644
--- a/modules/hotelreservationsystem/define.php
+++ b/modules/hotelreservationsystem/define.php
@@ -26,6 +26,7 @@
require_once 'classes/HotelRoomInformation.php';
require_once 'classes/HotelBranchInformation.php';
require_once 'classes/HotelImage.php';
+require_once 'classes/HotelImageCategory.php';
require_once 'classes/HotelFeatures.php';
require_once 'classes/HotelBranchFeatures.php';
require_once 'classes/HotelBookingDetail.php';
diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php
index baa85790c9..f70a5c5b4c 100644
--- a/modules/hotelreservationsystem/hotelreservationsystem.php
+++ b/modules/hotelreservationsystem/hotelreservationsystem.php
@@ -33,7 +33,7 @@ public function __construct()
{
$this->name = 'hotelreservationsystem';
$this->tab = 'administration';
- $this->version = '1.7.0';
+ $this->version = '1.7.1';
$this->author = 'Webkul';
$this->need_instance = 0;
$this->bootstrap = true;
@@ -557,6 +557,7 @@ public function callInstallTab()
$this->installTab('AdminHotelFeatures', 'Manage Hotel Features', 'AdminHotelReservationSystemManagement');
$this->installTab('AdminOrderRefundRules', 'Manage Order Refund Rules', 'AdminHotelReservationSystemManagement');
$this->installTab('AdminOrderRefundRequests', 'Manage Order Refund Requests', 'AdminHotelReservationSystemManagement');
+ $this->installTab('AdminHotelImageCategory', 'Manage Hotel Image Category', 'AdminHotelReservationSystemManagement');
$this->installTab('AdminHotelConfigurationSetting', 'General Settings', 'AdminHotelReservationSystemManagement');
$this->installTab('AdminHotelBedTypes', 'Bed Types', 'AdminCatalog');
diff --git a/modules/hotelreservationsystem/views/js/hotelImage.js b/modules/hotelreservationsystem/views/js/hotelImage.js
index c1fd5f6666..5a5373e291 100644
--- a/modules/hotelreservationsystem/views/js/hotelImage.js
+++ b/modules/hotelreservationsystem/views/js/hotelImage.js
@@ -21,32 +21,61 @@
*/
$(document).ready(function () {
- $('.htl-img-preview').fancybox({
- width: 'auto',
- height: 'auto',
- autoSize : false,
- maxWidth: 700,
- 'hideOnContentClick': false,
- });
+ function initHotelImagePreview()
+ {
+ $('.htl-img-preview').fancybox({
+ width: 'auto',
+ height: 'auto',
+ autoSize : false,
+ maxWidth: 700,
+ 'hideOnContentClick': false,
+ });
+ }
- $("#hotel_images").on("change", function(event) {
- const files = Array.from(event.target.files);
- uploadSelectedImages(files);
+ initHotelImagePreview();
+
+ $('body').on('click', '#upload_hotel_images_btn', function(event) {
+ event.preventDefault();
+ var files = Array.from($('#hotel_images')[0].files || []);
+ var idHtlImageCategory = parseInt($('#id_htl_image_category').val(), 10);
+ var triggerElement = $(this);
+
+ if (isNaN(idHtlImageCategory) || idHtlImageCategory < 0) {
+ idHtlImageCategory = 0;
+ }
+
+ if (!files.length) {
+ showErrorMessage(imgSelectErrorMsg);
+ return;
+ }
+
+ triggerElement.prop('disabled', true).addClass('disabled');
+ uploadSelectedImages(files, idHtlImageCategory).then(function() {
+ $('#hotel_images').val('');
+ showSuccessMessage(imgUploadSuccessMsg);
+ }, function(errorMsg) {
+ showErrorMessage(errorMsg || imgUploadErrorMsg);
+ }).then(function() {
+ triggerElement.prop('disabled', false).removeClass('disabled');
+ });
});
- function uploadSelectedImages(files)
+ function uploadSelectedImages(files, idHtlImageCategory)
{
- if (files.length == 0) return; // all done
+ if (files.length == 0) {
+ return Promise.resolve();
+ }
+
let file = files[0];
files.splice(0, 1);
- createImageUploadRequest(file).then((formData) => {
- uploadHotelImages(formData).then(() => {
- uploadSelectedImages(files)
+ return createImageUploadRequest(file, idHtlImageCategory).then((formData) => {
+ return uploadHotelImages(formData).then(() => {
+ return uploadSelectedImages(files, idHtlImageCategory);
});
- })
+ });
}
- function createImageUploadRequest(file)
+ function createImageUploadRequest(file, idHtlImageCategory)
{
return new Promise((resolve, reject) => {
if (typeof file != 'undefined') {
@@ -57,10 +86,13 @@ $(document).ready(function () {
var idHotel = $("#id-hotel").val();
formData.append('hotel_image', file);
formData.append('id_hotel', idHotel);
+ formData.append('id_htl_image_category', idHtlImageCategory);
formData.append('ajax', true);
formData.append('action', 'uploadHotelImages');
resolve(formData);
}
+ } else {
+ reject(imgUploadErrorMsg);
}
});
}
@@ -79,20 +111,17 @@ $(document).ready(function () {
if (response.success) {
$('.list-empty-tr').remove();
$("#hotel-image-table tbody").append(response.data.image_row);
- showSuccessMessage(imgUploadSuccessMsg);
- resolve(imgUploadSuccessMsg);
+ initHotelImagePreview();
+ resolve(response);
} else {
- if (typeof response.errors != 'undefined') {
- showErrorMessage(response.errors);
- reject(response.errors);
+ if (typeof response.errors != 'undefined' && response.errors.length) {
+ reject(response.errors.join('
'));
} else {
- showErrorMessage(imgUploadErrorMsg);
reject(imgUploadErrorMsg);
}
}
},
error: function(data) {
- showErrorMessage(imgUploadErrorMsg);
reject(imgUploadErrorMsg);
}
});
@@ -184,4 +213,4 @@ $(document).ready(function () {
showErrorMessage(deleteImgErrorMsg);
}
});
-});
\ No newline at end of file
+});
diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl
index 4a28112c70..316f343eef 100644
--- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl
+++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl
@@ -27,6 +27,13 @@
+