From a3120fac1b6155373380426a4a83b56b7bc30847 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 23 Aug 2024 12:02:40 +0530 Subject: [PATCH 1/4] Updated: Hotel features assigning process for the admin --- .../admin/AdminAddHotelController.php | 36 +++ .../admin/AdminAssignHotelFeatures.php | 229 ------------------ .../admin/AdminHotelfeaturesController.php | 5 - .../hotelreservationsystem.php | 1 - .../admin/add_hotel/helpers/form/form.tpl | 25 ++ 5 files changed, 61 insertions(+), 235 deletions(-) delete mode 100644 modules/hotelreservationsystem/controllers/admin/AdminAssignHotelFeatures.php diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index ded152095..ac90c2cd2 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -171,6 +171,35 @@ class AdminAddHotelController extends ModuleAdminController } } $smartyVars['order_restrict_date_info'] = $restrictDateInfo; + $objHotelFeatures = new HotelFeatures(); + $hotelFeatures = $this->object->getFeaturesOfHotelByHotelId($this->object->id); + if ($features = $objHotelFeatures->HotelBranchSelectedFeaturesArray($hotelFeatures)) { + foreach ($features as $idFeature => $feature) { + $features[$idFeature]['value'] = $idFeature; + $features[$idFeature]['input_name'] = 'id_feature_parents'; + if (isset($feature['children']) && $feature['children']) { + $selectedChildFeatures = 0; + foreach ($feature['children'] as $childKey => $childFeature) { + $features[$idFeature]['children'][$childKey]['value'] = $childFeature['id']; + $features[$idFeature]['children'][$childKey]['input_name'] = 'id_features'; + if (isset($childFeature['selected']) && $childFeature['selected']) { + $selectedChildFeatures++; + } + } + + if ($selectedChildFeatures == count($feature['children'])) { + $features[$idFeature]['selected'] = true; + } + } + } + } + + $tree = new HelperTree('hotel-features-tree', $features); + $tree->setShowCollapseExpandButton(true) + ->setUseCheckBox(true) + ->setUseBulkActions(true); + $treeContent = $tree->render(); + $smartyVars['hotel_feature_tree'] = $treeContent; } else { $idCountry = Tools::getValue('hotel_country'); } @@ -226,6 +255,7 @@ class AdminAddHotelController extends ModuleAdminController $longitude = Tools::getValue('loclongitude'); $map_formated_address = Tools::getValue('locformatedAddr'); $map_input_text = Tools::getValue('googleInputField'); + $hotelFeatures = Tools::getValue('id_features', array()); // check if field is atleast in default language. Not available in default prestashop $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); @@ -640,6 +670,12 @@ class AdminAddHotelController extends ModuleAdminController $objHotelOrderRestrictDate->preparation_time = $preparationTime; } $objHotelOrderRestrictDate->save(); + + $objHotelFeatures = new HotelBranchFeatures(); + $objHotelFeatures->deleteBranchFeaturesByHotelId($idHotel); + if (!$objHotelFeatures->assignFeaturesToHotel($idHotel, $hotelFeatures)) { + $this->errors[] = $this->l('Some problem occurred while assigning features to the hotel.'); + } } if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAssignHotelFeatures.php b/modules/hotelreservationsystem/controllers/admin/AdminAssignHotelFeatures.php deleted file mode 100644 index 171dd1a08..000000000 --- a/modules/hotelreservationsystem/controllers/admin/AdminAssignHotelFeatures.php +++ /dev/null @@ -1,229 +0,0 @@ - -* @copyright 2010-2020 Webkul IN -* @license https://store.webkul.com/license.html -*/ - -class AdminAssignHotelFeaturesController extends ModuleAdminController -{ - public function __construct() - { - $this->bootstrap = true; - $this->table = 'htl_branch_features'; - $this->className = 'HotelBranchFeatures'; - $this->identifier = 'id'; - $this->context = Context::getContext(); - - // START send access query information to the admin controller - $this->access_select = ' SELECT a.`id` FROM '._DB_PREFIX_.'htl_branch_features a'; - $this->access_join = ' INNER JOIN '._DB_PREFIX_.'htl_branch_info hbi ON (hbi.id = a.id_hotel)'; - if ($acsHtls = HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1, 1)) { - $this->access_where = ' WHERE hbi.id IN ('.implode(',', $acsHtls).')'; - } - - parent::__construct(); - - $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'htl_branch_info` hi ON (hi.`id` = a.`id_hotel`)'; - $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'htl_branch_info_lang` hil - ON (hi.`id` = hil.`id` AND hil.id_lang = '.(int)$this->context->language->id.')'; - $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'address` addr ON (addr.`id_hotel` = hi.`id`)'; - $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = addr.`id_state`)'; - $this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (cl.`id_country` = addr.`id_country` - AND cl.`id_lang` = '.(int)$this->context->language->id.')'; - - $this->_select .= 'addr.`city` as htl_city, hi.`id` as htl_id, hil.`hotel_name` as htl_name, - s.`name` as `state_name`, cl.`name`'; - $this->_group = 'GROUP BY a.`id_hotel`'; - - $this->fields_list = array( - 'htl_id' => array( - 'title' => $this->l('Hotel ID'), - 'align' => 'center', - 'filter_key' => 'hi!id', - ), - 'htl_name' => array( - 'title' => $this->l('Hotel Name'), - 'align' => 'center', - 'filter_key' => 'hil!hotel_name', - ), - 'htl_city' => array( - 'title' => $this->l('City'), - 'align' => 'center', - 'filter_key' => 'addr!city', - ), - - 'state_name' => array( - 'title' => $this->l('State'), - 'align' => 'center', - 'filter_key' => 's!name', - ), - 'name' => array( - 'title' => $this->l('Country'), - 'align' => 'center', - 'filter_key' => 'cl!name', - ), - 'date_add' => array( - 'title' => $this->l('Date Added'), - 'align' => 'center', - 'type' => 'datetime', - 'filter_key' => 'a!date_add', - ) - ); - - $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(); - - $this->page_header_toolbar_btn['new_feature'] = array( - 'href' => $this->context->link->getAdminLink('AdminHotelFeatures'), - 'desc' => $this->l('Hotel Features'), - 'imgclass' => 'back' - ); - - $this->page_header_toolbar_btn['assignfeatures'] = array( - 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, - 'desc' => $this->l('Assign Features'), - 'imgclass' => 'new' - ); - } - - public function renderList() - { - $this->addRowAction('edit'); - $this->addRowAction('delete'); - - return parent::renderList(); - } - - public function renderForm() - { - $smartyVars = array(); - if ($this->display == 'add') { - $objHotelFeatures = new HotelFeatures(); - $featuresList = $objHotelFeatures->HotelAllCommonFeaturesArray(); - $objBranchInfo = new HotelBranchInformation(); - $unassignedFtrsHotels = $objBranchInfo->getUnassignedFeaturesHotelIds(); - // filter hotels as per accessed hotels - $unassignedFtrsHotels = HotelBranchInformation::filterDataByHotelAccess( - $unassignedFtrsHotels, - $this->context->employee->id_profile, - 1 - ); - - $smartyVars['hotels'] = $unassignedFtrsHotels; - $smartyVars['features_list'] = $featuresList; - } elseif ($this->display == 'edit') { - $id = Tools::getValue('id'); - $objBranchFeatures = new HotelBranchFeatures($id); - $smartyVars['edit'] = 1; - $objHotelFeatures = new HotelFeatures(); - $objBranchInfo = new HotelBranchInformation(); - - $features_hotel = $objBranchInfo->getFeaturesOfHotelByHotelId($objBranchFeatures->id_hotel); - $featuresList = $objHotelFeatures->HotelBranchSelectedFeaturesArray($features_hotel); - - $hotels = $objBranchInfo->hotelsNameAndId(); - $smartyVars['hotel_id'] = $objBranchFeatures->id_hotel; - $smartyVars['hotels'] = $hotels; - $smartyVars['features_list'] = $featuresList; - } - - $this->context->smarty->assign($smartyVars); - - $this->fields_form = array( - 'submit' => array( - 'title' => $this->l('Save') - ) - ); - return parent::renderForm(); - } - - public function processSave() - { - if ($editId = Tools::getValue('edit_hotel_id')) { - $objBranchFeatures = new HotelBranchFeatures(); - $objBranchFeatures->deleteBranchFeaturesByHotelId($editId); - } - if (!$hotelFeatures = Tools::getValue('hotel_fac')) { - $this->errors[] = $this->l('Please select at least one feature to assign to a hotel.'); - } - if (!$idHotel = Tools::getValue('id_hotel')) { - $this->errors[] = $this->l('Please select a hotel first.'); - } - if (!count($this->errors)) { - $objHotelFeatures = new HotelBranchFeatures(); - if (!$objHotelFeatures->assignFeaturesToHotel($idHotel, $hotelFeatures)) { - $this->errors[] = $this->l('Some problem occure while assigning Features to the hotel.'); - } - if (empty($this->errors)) { - if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { - Tools::redirectAdmin( - self::$currentIndex.'&id='.(int)$idHotel.'&update'.$this->table.'&conf=3&token='.$this->token - ); - } else { - Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); - } - } - } else { - $this->display = 'add'; - } - } - - public function processDelete() - { - if (Validate::isLoadedObject($object = $this->loadObject())) { - $object = $this->loadObject(); - if ($object->id) { - $objBranchFeatures = new HotelBranchFeatures(); - $objBranchFeatures->deleteBranchFeaturesByHotelId($object->id_hotel); - } - } else { - $this->errors[] = $this->l('An error occurred while deleting the object.').''.$this->table.' '. - $this->l('(cannot load object)'); - } - parent::processDelete(); - } - - protected function processBulkDelete() - { - if (is_array($this->boxes) && !empty($this->boxes)) { - foreach ($this->boxes as $key => $value) { - $objBranchFeatures = new HotelBranchFeatures($value); - $objBranchFeatures->deleteBranchFeaturesByHotelId($objBranchFeatures->id_hotel); - } - parent::processBulkDelete(); - } else { - $this->errors[] = $this->l('You must select at least one element to delete.'); - } - } - - public function setMedia() - { - parent::setMedia(); - $this->addJs(_MODULE_DIR_.'hotelreservationsystem/views/js/HotelReservationAdmin.js'); - $this->addCSS(_MODULE_DIR_.'hotelreservationsystem/views/css/HotelReservationAdmin.css'); - } -} \ No newline at end of file diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelfeaturesController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelfeaturesController.php index 77d352ac0..8d7611c62 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelfeaturesController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelfeaturesController.php @@ -41,11 +41,6 @@ class AdminHotelFeaturesController extends ModuleAdminController 'desc' => $this->l('Add new Features'), 'imgclass' => 'new' ); - - $this->page_header_toolbar_btn['new'] = array( - 'href' => $this->context->link->getAdminLink('AdminAssignHotelFeatures'), - 'desc' => $this->l('Assign Features To Hotel'), - ); } public function renderView() diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 757825c77..873bae98e 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -576,7 +576,6 @@ class HotelReservationSystem extends Module $this->installTab('AdminHotelGeneralSettings', 'Hotel General Configuration', 'AdminHotelConfigurationSetting', false); $this->installTab('AdminHotelFeaturePricesSettings', 'Advanced Price Rules', 'AdminHotelConfigurationSetting', false); $this->installTab('AdminRoomTypeGlobalDemand', 'Additional Demand Configuration', 'AdminHotelConfigurationSetting', false); - $this->installTab('AdminAssignHotelFeatures', 'Assign Hotel Features', false, false); $this->installTab('AdminBookingDocument', 'Booking Documents', false, false); return true; diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index d35e517cf..b1ed02008 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -83,6 +83,12 @@ {l s='Refund Policies' mod='hotelreservationsystem'} +
  • + + + {l s='Features' mod='hotelreservationsystem'} + +
  • {hook h='displayAdminAddHotelFormTab' id_hotel=$hook_arg_id_hotel}
    @@ -488,6 +494,25 @@ {hook h='displayAdminAddHotelFormRefundPoliciesTabAfter' id_hotel=$hook_arg_id_hotel}
    +
    + {hook h='displayAdminAddHotelFormFeaturesTabBefore' id_hotel=$hook_arg_id_hotel} + {if isset($hotel_info.id) && $hotel_info.id} +
    + +
    + {$hotel_feature_tree} +
    +
    + {else} +
    + {l s='Please save hotel information before assigning hotel features.' mod='hotelreservationsystem'} +
    + {/if} + + {hook h='displayAdminAddHotelFormFeaturesTabAfter' id_hotel=$hook_arg_id_hotel} +
    {hook h='displayAdminAddHotelFormTabContent' id_hotel=$hook_arg_id_hotel} From 09a9660739d49b96b945530f566b8e8fe62bf6d1 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 27 Aug 2024 10:15:22 +0530 Subject: [PATCH 2/4] optmizied hotel features assinging process, handled the case when no features are created --- .../controllers/admin/AdminAddHotelController.php | 14 +++++++------- .../admin/add_hotel/helpers/form/form.tpl | 6 +++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index ac90c2cd2..86804666a 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -192,14 +192,14 @@ class AdminAddHotelController extends ModuleAdminController } } } - } - $tree = new HelperTree('hotel-features-tree', $features); - $tree->setShowCollapseExpandButton(true) - ->setUseCheckBox(true) - ->setUseBulkActions(true); - $treeContent = $tree->render(); - $smartyVars['hotel_feature_tree'] = $treeContent; + $tree = new HelperTree('hotel-features-tree', $features); + $tree->setShowCollapseExpandButton(true) + ->setUseCheckBox(true) + ->setUseBulkActions(true); + $treeContent = $tree->render(); + $smartyVars['hotel_feature_tree'] = $treeContent; + } } else { $idCountry = Tools::getValue('hotel_country'); } diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index b1ed02008..c53fb31bb 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -496,7 +496,7 @@
    {hook h='displayAdminAddHotelFormFeaturesTabBefore' id_hotel=$hook_arg_id_hotel} - {if isset($hotel_info.id) && $hotel_info.id} + {if isset($hotel_feature_tree)}
    + {elseif isset($hotel_info.id) && $hotel_info.id} +
    + {l s='No features created yet.' mod='hotelreservationsystem'} {l s='You can create features by visiting ' mod='hotelreservationsystem'} {l s='manage hotel features.' mod='hotelreservationsystem'} +
    {else}
    {l s='Please save hotel information before assigning hotel features.' mod='hotelreservationsystem'} From e4895fc18b82749bc48a9bbfa07115e6b7ded4df Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 27 Aug 2024 16:59:36 +0530 Subject: [PATCH 3/4] Added: auto select childrens for the features tree --- .../controllers/admin/AdminAddHotelController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 86804666a..526701c08 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -196,6 +196,7 @@ class AdminAddHotelController extends ModuleAdminController $tree = new HelperTree('hotel-features-tree', $features); $tree->setShowCollapseExpandButton(true) ->setUseCheckBox(true) + ->setAutoSelectChildren(true) ->setUseBulkActions(true); $treeContent = $tree->render(); $smartyVars['hotel_feature_tree'] = $treeContent; From c84cee59f29953a2f8e52035db11f628c2030a1e Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 27 Aug 2024 19:00:32 +0530 Subject: [PATCH 4/4] Added: Auto select child nodes for the helper tree and auto unselect parent nodes for helper tree --- .../default/template/helpers/tree/tree.tpl | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/admin/themes/default/template/helpers/tree/tree.tpl b/admin/themes/default/template/helpers/tree/tree.tpl index 30c4283c6..1eab06591 100644 --- a/admin/themes/default/template/helpers/tree/tree.tpl +++ b/admin/themes/default/template/helpers/tree/tree.tpl @@ -86,16 +86,27 @@ {if isset($auto_select_children) && $auto_select_children == true} $('#{$id|escape:'html':'UTF-8'}').find(':input[type=checkbox]').on('click', function(){ - if ($(this).is(":checked")) { - $(this).closest('.tree-folder').find(':input[type=checkbox]').each(function(){ - $(this).prop('checked', true); - $(this).parent().addClass('tree-selected'); - }); - } else { - $(this).closest('.tree-folder').find(':input[type=checkbox]').each(function(){ - $(this).prop('checked', false); - $(this).parent().removeClass('tree-selected'); - }); + if ($(this).closest('.tree-item').length ==0) { + if ($(this).is(":checked")) { + $(this).closest('.tree-folder').find(':input[type=checkbox]').each(function(){ + $(this).prop('checked', true); + $(this).parent().addClass('tree-selected'); + }); + } else { + $(this).closest('.tree-folder').find(':input[type=checkbox]').each(function(){ + $(this).prop('checked', false); + $(this).parent().removeClass('tree-selected'); + }); + } + } + + if ($(this).closest('.tree-item').length) { + if (!$(this).is(":checked")) { + $(this).parents('.tree-folder').find(':input[type=checkbox]:first').each(function(){ + $(this).prop('checked', false); + $(this).parent().removeClass('tree-selected'); + }); + } } }); {/if}