Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions modules/hotelreservationsystem/classes/HotelImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,24 @@ 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
if ($p <= 1) {
$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);
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}
}
89 changes: 89 additions & 0 deletions modules/hotelreservationsystem/classes/HotelImageCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License version 3.0
* that is bundled with this package in the file LICENSE.md
* It is also available through the world-wide-web at this URL:
* https://opensource.org/license/osl-3-0-php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to support@qloapps.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to a newer
* versions in the future. If you wish to customize this module for your needs
* please refer to https://store.webkul.com/customisation-guidelines for more information.
*
* @author Webkul IN
* @copyright Since 2010 Webkul
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*/

class HotelImageCategory extends ObjectModel
{
public $id_htl_image_category;
public $name;
public $date_add;
public $date_upd;

public static $definition = array(
'table' => '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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -869,19 +871,31 @@ 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()
);
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(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License version 3.0
* that is bundled with this package in the file LICENSE.md
* It is also available through the world-wide-web at this URL:
* https://opensource.org/license/osl-3-0-php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to support@qloapps.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to a newer
* versions in the future. If you wish to customize this module for your needs
* please refer to https://store.webkul.com/customisation-guidelines for more information.
*
* @author Webkul IN
* @copyright Since 2010 Webkul
* @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0
*/

class AdminHotelImageCategoryController extends ModuleAdminController
{
public function __construct()
{
$this->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();
}
}
Loading