From 530a52f0454fc94c84a97deba7ba668add7f9d82 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Fri, 2 Aug 2024 20:01:39 +0530 Subject: [PATCH 1/4] updated helper tree --- .../helpers/tree/tree_associated_hotels.tpl | 200 -------- .../{tree_header.tpl => tree_headere.tpl} | 0 .../helpers/tree/tree_toolbar.tpl | 31 -- .../default/template/helpers/tree/tree.tpl | 62 ++- .../template/helpers/tree/tree_categories.tpl | 4 +- .../template/helpers/tree/tree_hotels.tpl | 102 ---- .../tree/tree_node_folder_checkbox.tpl | 7 +- .../helpers/tree/tree_node_folder_radio.tpl | 6 +- .../tree/tree_node_hotel_folder_checkbox.tpl | 37 -- .../tree/tree_node_hotel_item_checkbox.tpl | 31 -- .../helpers/tree/tree_node_item_checkbox.tpl | 4 +- .../helpers/tree/tree_node_item_radio.tpl | 2 +- classes/helper/HelperTree.php | 135 +++++ classes/helper/HelperTreeCategories.php | 50 +- classes/helper/HelperTreeHotels.php | 485 ------------------ classes/helper/HelperTreeShops.php | 27 - classes/tree/Tree.php | 10 +- config/defines.inc.php | 2 +- .../admin/AdminNormalProductsController.php | 22 +- controllers/admin/AdminPatternsController.php | 2 +- controllers/admin/AdminSearchController.php | 2 +- .../classes/HotelHelper.php | 178 +++++++ .../classes/RoomTypeServiceProduct.php | 4 +- 23 files changed, 428 insertions(+), 975 deletions(-) delete mode 100644 admin/themes/default/template/controllers/normal_products/helpers/tree/tree_associated_hotels.tpl rename admin/themes/default/template/controllers/normal_products/helpers/tree/{tree_header.tpl => tree_headere.tpl} (100%) delete mode 100644 admin/themes/default/template/controllers/normal_products/helpers/tree/tree_toolbar.tpl delete mode 100644 admin/themes/default/template/helpers/tree/tree_hotels.tpl delete mode 100644 admin/themes/default/template/helpers/tree/tree_node_hotel_folder_checkbox.tpl delete mode 100644 admin/themes/default/template/helpers/tree/tree_node_hotel_item_checkbox.tpl create mode 100644 classes/helper/HelperTree.php delete mode 100644 classes/helper/HelperTreeHotels.php diff --git a/admin/themes/default/template/controllers/normal_products/helpers/tree/tree_associated_hotels.tpl b/admin/themes/default/template/controllers/normal_products/helpers/tree/tree_associated_hotels.tpl deleted file mode 100644 index 8789a990a..000000000 --- a/admin/themes/default/template/controllers/normal_products/helpers/tree/tree_associated_hotels.tpl +++ /dev/null @@ -1,200 +0,0 @@ -{* -* 2007-2017 PrestaShop -* -* NOTICE OF LICENSE -* -* This source file is subject to the Academic Free License (AFL 3.0) -* that is bundled with this package in the file LICENSE.txt. -* It is also available through the world-wide-web at this URL: -* http://opensource.org/licenses/afl-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 license@prestashop.com so we can send you a copy immediately. -* -* DISCLAIMER -* -* Do not edit or add to this file if you wish to upgrade PrestaShop to newer -* versions in the future. If you wish to customize PrestaShop for your -* needs please refer to http://www.prestashop.com for more information. -* -* @author PrestaShop SA -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} -
- {if isset($header)}{$header}{/if} - {if isset($nodes)} -
    - {$nodes} -
- {/if} -
- diff --git a/admin/themes/default/template/controllers/normal_products/helpers/tree/tree_header.tpl b/admin/themes/default/template/controllers/normal_products/helpers/tree/tree_headere.tpl similarity index 100% rename from admin/themes/default/template/controllers/normal_products/helpers/tree/tree_header.tpl rename to admin/themes/default/template/controllers/normal_products/helpers/tree/tree_headere.tpl diff --git a/admin/themes/default/template/controllers/normal_products/helpers/tree/tree_toolbar.tpl b/admin/themes/default/template/controllers/normal_products/helpers/tree/tree_toolbar.tpl deleted file mode 100644 index 0a817f113..000000000 --- a/admin/themes/default/template/controllers/normal_products/helpers/tree/tree_toolbar.tpl +++ /dev/null @@ -1,31 +0,0 @@ -{* -* 2007-2017 PrestaShop -* -* NOTICE OF LICENSE -* -* This source file is subject to the Academic Free License (AFL 3.0) -* that is bundled with this package in the file LICENSE.txt. -* It is also available through the world-wide-web at this URL: -* http://opensource.org/licenses/afl-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 license@prestashop.com so we can send you a copy immediately. -* -* DISCLAIMER -* -* Do not edit or add to this file if you wish to upgrade PrestaShop to newer -* versions in the future. If you wish to customize PrestaShop for your -* needs please refer to http://www.prestashop.com for more information. -* -* @author PrestaShop SA -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} -
- {if isset($actions)} - {foreach from=$actions item=action} - {$action->render()} - {/foreach} - {/if} -
\ No newline at end of file diff --git a/admin/themes/default/template/helpers/tree/tree.tpl b/admin/themes/default/template/helpers/tree/tree.tpl index 9f9e6839b..066863e89 100644 --- a/admin/themes/default/template/helpers/tree/tree.tpl +++ b/admin/themes/default/template/helpers/tree/tree.tpl @@ -29,4 +29,64 @@ {$nodes} {/if} - \ No newline at end of file + + \ No newline at end of file diff --git a/admin/themes/default/template/helpers/tree/tree_categories.tpl b/admin/themes/default/template/helpers/tree/tree_categories.tpl index 36b6f6602..e1291f627 100644 --- a/admin/themes/default/template/helpers/tree/tree_categories.tpl +++ b/admin/themes/default/template/helpers/tree/tree_categories.tpl @@ -69,7 +69,7 @@ $(this).parent().addClass("tree-selected"); $(this).parents('ul.tree').each(function(){ $(this).show(); - $(this).prev().find('.icon-folder-close').removeClass('icon-folder-close').addClass('icon-folder-open'); + $(this).prev().find('.icon-folder-close').removeClass('icon-folder-close').addClass('icon-folder-open'); }); } } @@ -92,7 +92,7 @@ $(this).parent().addClass("tree-selected"); $(this).parents('ul.tree').each(function(){ $(this).show(); - $(this).prev().find('.icon-folder-close').removeClass('icon-folder-close').addClass('icon-folder-open'); + $(this).prev().find('.icon-folder-close').removeClass('icon-folder-close').addClass('icon-folder-open'); }); } } diff --git a/admin/themes/default/template/helpers/tree/tree_hotels.tpl b/admin/themes/default/template/helpers/tree/tree_hotels.tpl deleted file mode 100644 index 36b6f6602..000000000 --- a/admin/themes/default/template/helpers/tree/tree_hotels.tpl +++ /dev/null @@ -1,102 +0,0 @@ -{* -* 2007-2017 PrestaShop -* -* NOTICE OF LICENSE -* -* This source file is subject to the Academic Free License (AFL 3.0) -* that is bundled with this package in the file LICENSE.txt. -* It is also available through the world-wide-web at this URL: -* http://opensource.org/licenses/afl-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 license@prestashop.com so we can send you a copy immediately. -* -* DISCLAIMER -* -* Do not edit or add to this file if you wish to upgrade PrestaShop to newer -* versions in the future. If you wish to customize PrestaShop for your -* needs please refer to http://www.prestashop.com for more information. -* -* @author PrestaShop SA -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} -
- {if isset($header)}{$header}{/if} - {if isset($nodes)} -
    - {$nodes} -
- {/if} -
- diff --git a/admin/themes/default/template/helpers/tree/tree_node_folder_checkbox.tpl b/admin/themes/default/template/helpers/tree/tree_node_folder_checkbox.tpl index 47c7c0ac6..a4452eb38 100644 --- a/admin/themes/default/template/helpers/tree/tree_node_folder_checkbox.tpl +++ b/admin/themes/default/template/helpers/tree/tree_node_folder_checkbox.tpl @@ -24,9 +24,10 @@ *}
  • - {if isset($node['id_category']) && $node['id_category'] != $root_category} - - {/if} + {* {if isset($node['value']) && $node['value'] != $root_category} *} + {if !isset($node['input_name'])}test{/if} + + {* {/if} *} diff --git a/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl b/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl index be55f981c..511d52458 100644 --- a/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl +++ b/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl @@ -24,9 +24,9 @@ *}
  • - {if $node['id_category'] != $root_category} - - {/if} + {* {if $node[$input_id] != $root_category} *} + + {* {/if} *} diff --git a/admin/themes/default/template/helpers/tree/tree_node_hotel_folder_checkbox.tpl b/admin/themes/default/template/helpers/tree/tree_node_hotel_folder_checkbox.tpl deleted file mode 100644 index 3e826b714..000000000 --- a/admin/themes/default/template/helpers/tree/tree_node_hotel_folder_checkbox.tpl +++ /dev/null @@ -1,37 +0,0 @@ -{* -* 2007-2017 PrestaShop -* -* NOTICE OF LICENSE -* -* This source file is subject to the Academic Free License (AFL 3.0) -* that is bundled with this package in the file LICENSE.txt. -* It is also available through the world-wide-web at this URL: -* http://opensource.org/licenses/afl-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 license@prestashop.com so we can send you a copy immediately. -* -* DISCLAIMER -* -* Do not edit or add to this file if you wish to upgrade PrestaShop to newer -* versions in the future. If you wish to customize PrestaShop for your -* needs please refer to http://www.prestashop.com for more information. -* -* @author PrestaShop SA -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} -
  • - - {if isset($node['id_hotel'])} - - {* {if isset($node['id_category']) && $node['id_category'] != $root_category} *} - {/if} - - - -
      - {$children|escape:'UTF-8'} -
    -
  • diff --git a/admin/themes/default/template/helpers/tree/tree_node_hotel_item_checkbox.tpl b/admin/themes/default/template/helpers/tree/tree_node_hotel_item_checkbox.tpl deleted file mode 100644 index 4353d6e88..000000000 --- a/admin/themes/default/template/helpers/tree/tree_node_hotel_item_checkbox.tpl +++ /dev/null @@ -1,31 +0,0 @@ -{* -* 2007-2017 PrestaShop -* -* NOTICE OF LICENSE -* -* This source file is subject to the Academic Free License (AFL 3.0) -* that is bundled with this package in the file LICENSE.txt. -* It is also available through the world-wide-web at this URL: -* http://opensource.org/licenses/afl-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 license@prestashop.com so we can send you a copy immediately. -* -* DISCLAIMER -* -* Do not edit or add to this file if you wish to upgrade PrestaShop to newer -* versions in the future. If you wish to customize PrestaShop for your -* needs please refer to http://www.prestashop.com for more information. -* -* @author PrestaShop SA -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} -
  • - - - - - -
  • \ No newline at end of file diff --git a/admin/themes/default/template/helpers/tree/tree_node_item_checkbox.tpl b/admin/themes/default/template/helpers/tree/tree_node_item_checkbox.tpl index ba4b7201c..e4db8e373 100644 --- a/admin/themes/default/template/helpers/tree/tree_node_item_checkbox.tpl +++ b/admin/themes/default/template/helpers/tree/tree_node_item_checkbox.tpl @@ -24,8 +24,8 @@ *}
  • - + -
  • \ No newline at end of file + diff --git a/admin/themes/default/template/helpers/tree/tree_node_item_radio.tpl b/admin/themes/default/template/helpers/tree/tree_node_item_radio.tpl index 68fdb1b3c..fd03456fa 100644 --- a/admin/themes/default/template/helpers/tree/tree_node_item_radio.tpl +++ b/admin/themes/default/template/helpers/tree/tree_node_item_radio.tpl @@ -24,7 +24,7 @@ *}
  • - + diff --git a/classes/helper/HelperTree.php b/classes/helper/HelperTree.php new file mode 100644 index 000000000..f3545e058 --- /dev/null +++ b/classes/helper/HelperTree.php @@ -0,0 +1,135 @@ + +* @copyright Since 2010 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +class HelperTreeCore extends TreeCore +{ + + const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder_radio.tpl'; + const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item_radio.tpl'; + + + private $_use_search; + private $_use_bulk_actions; + private $_use_checkbox; + private $_show_collapse_expand_button = true; + + + public function setUseSearch($value) + { + $this->_use_search = (bool)$value; + return $this; + } + + public function useSearch() + { + return (isset($this->_use_search) && $this->_use_search); + } + + public function setUseBulkActions($value) + { + $this->_use_bulk_actions = (bool)$value; + return $this; + } + + public function useBulkActions() + { + return (isset($this->_use_bulk_actions) && $this->_use_bulk_actions); + } + + public function setUseCheckBox($value) + { + $this->_use_checkbox = (bool)$value; + return $this; + } + + public function useCheckBox() + { + return (isset($this->_use_checkbox) && $this->_use_checkbox); + } + + public function setShowCollapseExpandButton($value) + { + $this->_show_collapse_expand_button = (bool)$value; + return $this; + } + + public function showCollapseExpandButton() + { + return (isset($this->_show_collapse_expand_button) && $this->_show_collapse_expand_button); + } + + public function render($data = null) + { + + if ($this->useCheckBox()) { + if($this->useBulkActions()) { + $check_all = new TreeToolbarLink( + 'Check All', + '#', + 'checkAll($(\'#'.$this->getId().'\')); return false;', + 'icon-check-sign'); + $check_all->setAttribute('id', 'check-all-'.$this->getId()); + $uncheck_all = new TreeToolbarLink( + 'Uncheck All', + '#', + 'uncheckAll($(\'#'.$this->getId().'\')); return false;', + 'icon-check-empty'); + $uncheck_all->setAttribute('id', 'uncheck-all-'.$this->getId()); + $this->addAction($check_all); + $this->addAction($uncheck_all); + } + $this->setNodeFolderTemplate('tree_node_folder_checkbox.tpl'); + $this->setNodeItemTemplate('tree_node_item_checkbox.tpl'); + $this->setAttribute('use_checkbox', $this->useCheckBox()); + } + + if ($this->useSearch()) { + $this->addAction(new TreeToolbarSearch( + 'dasdasd', + $this->getId().'-search') + ); + $this->setAttribute('use_search', $this->useSearch()); + } + + if ($this->showCollapseExpandButton()) { + $collapse_all = new TreeToolbarLink( + 'Collapse All', + '#', + '$(\'#'.$this->getId().'\').tree(\'collapseAll\');$(\'#collapse-all-'.$this->getId().'\').hide();$(\'#expand-all-'.$this->getId().'\').show(); return false;', + 'icon-collapse-alt'); + $collapse_all->setAttribute('id', 'collapse-all-'.$this->getId()); + $expand_all = new TreeToolbarLink( + 'Expand All', + '#', + '$(\'#'.$this->getId().'\').tree(\'expandAll\');$(\'#collapse-all-'.$this->getId().'\').show();$(\'#expand-all-'.$this->getId().'\').hide(); return false;', + 'icon-expand-alt'); + $expand_all->setAttribute('id', 'expand-all-'.$this->getId()); + $this->addAction($collapse_all); + $this->addAction($expand_all); + } + + + return parent::render($data); + } + + + + +} \ No newline at end of file diff --git a/classes/helper/HelperTreeCategories.php b/classes/helper/HelperTreeCategories.php index 7b9e04b0a..4c328122c 100644 --- a/classes/helper/HelperTreeCategories.php +++ b/classes/helper/HelperTreeCategories.php @@ -32,6 +32,7 @@ class HelperTreeCategoriesCore extends TreeCore private $_disabled_categories; private $_input_name; + private $_input_id; private $_lang; private $_root_category; private $_selected_categories; @@ -69,6 +70,8 @@ class HelperTreeCategoriesCore extends TreeCore foreach ($categories[$rootCategoryId] as $category) { $categoryId = (int)$category['id_category']; $tree[$categoryId] = $category; + $tree[$categoryId]['value'] = $category['id_category']; + $tree[$categoryId]['input_name'] = 'categoryBox'; if (Category::hasChildren($categoryId, $this->getLang(), false, $this->getShop()->id)) { $categoryChildren = Category::getChildren( @@ -144,7 +147,8 @@ class HelperTreeCategoriesCore extends TreeCore } $tree = Category::getCategoryInformations(array($root_category), $lang); - + $tree[$root_category]['value'] = $tree[$root_category]['id_category']; + $tree[$root_category]['input_name'] = 'categoryBox'; $children = $this->fillTree($categories, $root_category); if (!empty($children)) { @@ -214,6 +218,21 @@ class HelperTreeCategoriesCore extends TreeCore return $this->_input_name; } + public function setInputId($value) + { + $this->_input_id = $value; + return $this; + } + + public function getInputId() + { + if (!isset($this->_input_id)) { + $this->setInputId('id_category'); + } + + return $this->_input_id; + } + public function setLang($value) { $this->_lang = $value; @@ -229,24 +248,6 @@ class HelperTreeCategoriesCore extends TreeCore return $this->_lang; } - public function getNodeFolderTemplate() - { - if (!isset($this->_node_folder_template)) { - $this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE); - } - - return $this->_node_folder_template; - } - - public function getNodeItemTemplate() - { - if (!isset($this->_node_item_template)) { - $this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE); - } - - return $this->_node_item_template; - } - public function setRootCategory($value) { if (!Validate::isInt($value)) { @@ -304,15 +305,6 @@ class HelperTreeCategoriesCore extends TreeCore return $this->_shop; } - public function getTemplate() - { - if (!isset($this->_template)) { - $this->setTemplate(self::DEFAULT_TEMPLATE); - } - - return $this->_template; - } - public function setUseCheckBox($value) { $this->_use_checkbox = (bool)$value; @@ -449,6 +441,7 @@ class HelperTreeCategoriesCore extends TreeCore $this->getContext()->smarty )->assign(array( 'input_name' => $this->getInputName(), + 'input_id' => $this->getInputId(), 'children' => $this->renderNodes($item['children']), 'node' => $item ))->fetch(); @@ -458,6 +451,7 @@ class HelperTreeCategoriesCore extends TreeCore $this->getContext()->smarty )->assign(array( 'input_name' => $this->getInputName(), + 'input_id' => $this->getInputId(), 'node' => $item ))->fetch(); } diff --git a/classes/helper/HelperTreeHotels.php b/classes/helper/HelperTreeHotels.php deleted file mode 100644 index dd142943a..000000000 --- a/classes/helper/HelperTreeHotels.php +++ /dev/null @@ -1,485 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -class HelperTreeHotelsCore extends TreeCore -{ - const DEFAULT_TEMPLATE = 'tree_categories.tpl'; - const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder_radio.tpl'; - const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item_radio.tpl'; - - private $_disabled_categories; - private $_input_name; - private $_lang; - private $_root_category; - private $_selected_hotels; - private $_selected_room_types; - private $_full_tree = false; - private $_shop; - private $_use_checkbox; - private $_use_bulk_actions = true; - private $_use_search; - private $_use_shop_restriction; - private $_rooms_only = false; - private $_disable_all_categories = false; - private $_accessed_hotels = false; - - public function __construct($id, $title = null, $root_category = null, - $lang = null, $use_shop_restriction = true) - { - parent::__construct($id); - - if (isset($title)) { - $this->setTitle($title); - } - - if (isset($root_category)) { - $this->setRootCategory($root_category); - } - - $this->setLang($lang); - $this->setUseShopRestriction($use_shop_restriction); - } - - private function fillTree($hotels, $onlyRoomType = false) - { - $tree = array(); - $idLang = Context::getContext()->language->id; - $objRoomType = new HotelRoomType(); - foreach($hotels as $hotel) { - - if (!$onlyRoomType) { - $tree[$hotel['id_hotel']] = array( - 'id_hotel' => $hotel['id_hotel'], - 'id_category' => $hotel['id_category'], - 'name' => $hotel['hotel_name'], - 'children' => array() - ); - } - - if (!empty($roomTypes = $objRoomType->getRoomTypeByHotelId($hotel['id_hotel'], $idLang))) { - if ($onlyRoomType) { - $tree = array_merge($tree, $roomTypes); - } else { - $tree[$hotel['id_hotel']]['children'] = array_merge($tree[$hotel['id_hotel']]['children'], $roomTypes); - } - } - } - - return $tree; - } - - public function getData() - { - if (!isset($this->_data)) { - $shop = $this->getShop(); - $lang = $this->getLang(); - $root_category = (int)$this->getRootCategory(); - if (($hotels = $this->getAccessedHotels()) === false) { - $objHotelBanch = new HotelBranchInformation(); - $hotels = $objHotelBanch->hotelBranchesInfo(); - } - $tree = $this->fillTree($hotels, $this->_rooms_only); - if (!empty($children)) { - $tree[$root_category]['children'] = $children; - } - - $this->setData($tree); - $this->setDataSearch(Category::getAllCategoriesName($root_category, $lang, false, null, $this->useShopRestriction())); - } - - return $this->_data; - } - - public function setRoomsOnly($value) - { - $this->_rooms_only = $value; - return $this; - } - - public function setFullTree($value) - { - $this->_full_tree = $value; - return $this; - } - - public function getFullTree() - { - return $this->_full_tree; - } - - - public function setDisabledCategories($value) - { - $this->_disabled_categories = $value; - return $this; - } - - public function setAccessedHotels($values) - { - $this->_accessed_hotels = $values; - return $this; - } - - public function getAccessedHotels() - { - return $this->_accessed_hotels; - } - - public function setDisablAllCategories($value) - { - $this->_disable_all_categories = $value; - return $this; - } - - public function getDisabledCategories() - { - return $this->_disabled_categories; - } - - public function getDisablAllCategories() - { - return $this->_disable_all_categories; - } - - public function setInputName($value) - { - $this->_input_name = $value; - return $this; - } - - public function getInputName() - { - if (!isset($this->_input_name)) { - $this->setInputName('categoryBox'); - } - - return $this->_input_name; - } - - public function setLang($value) - { - $this->_lang = $value; - return $this; - } - - public function getLang() - { - if (!isset($this->_lang)) { - $this->setLang($this->getContext()->employee->id_lang); - } - - return $this->_lang; - } - - public function getNodeFolderTemplate() - { - if (!isset($this->_node_folder_template)) { - $this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE); - } - - return $this->_node_folder_template; - } - - public function getNodeItemTemplate() - { - if (!isset($this->_node_item_template)) { - $this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE); - } - - return $this->_node_item_template; - } - - public function setRootCategory($value) - { - if (!Validate::isInt($value)) { - throw new PrestaShopException('Root category must be an integer value'); - } - - $this->_root_category = $value; - return $this; - } - - public function getRootCategory() - { - return $this->_root_category; - } - - public function setSelectedHotels($value) - { - if (!is_array($value)) { - throw new PrestaShopException('Selected categories value must be an array'); - } - - $this->_selected_hotels = $value; - return $this; - } - - public function getSelectedHotels() - { - if (!isset($this->_selected_hotels)) { - $this->_selected_hotels = array(); - } - - return $this->_selected_hotels; - } - - public function setSelectedRoomTypes($value) - { - if (!is_array($value)) { - throw new PrestaShopException('Selected categories value must be an array'); - } - - $this->_selected_room_types = $value; - return $this; - } - - public function getSelectedRoomTypes() - { - if (!isset($this->_selected_room_types)) { - $this->_selected_room_types = array(); - } - - return $this->_selected_room_types; - } - - public function setShop($value) - { - $this->_shop = $value; - return $this; - } - - public function getShop() - { - if (!isset($this->_shop)) { - if (Tools::isSubmit('id_shop')) { - $this->setShop(new Shop(Tools::getValue('id_shop'))); - } elseif ($this->getContext()->shop->id) { - $this->setShop(new Shop($this->getContext()->shop->id)); - } elseif (!Shop::isFeatureActive()) { - $this->setShop(new Shop(Configuration::get('PS_SHOP_DEFAULT'))); - } else { - $this->setShop(new Shop(0)); - } - } - - return $this->_shop; - } - - public function getTemplate() - { - if (!isset($this->_template)) { - $this->setTemplate(self::DEFAULT_TEMPLATE); - } - - return $this->_template; - } - - public function setUseCheckBox($value) - { - $this->_use_checkbox = (bool)$value; - return $this; - } - - public function setUseBulkActions($value) - { - $this->_use_bulk_actions = (bool)$value; - return $this; - } - - public function setUseSearch($value) - { - $this->_use_search = (bool)$value; - return $this; - } - - public function setUseShopRestriction($value) - { - $this->_use_shop_restriction = (bool)$value; - return $this; - } - - public function useCheckBox() - { - return (isset($this->_use_checkbox) && $this->_use_checkbox); - } - - public function useBulkActions() - { - return (isset($this->_use_bulk_actions) && $this->_use_bulk_actions); - } - - public function useSearch() - { - return (isset($this->_use_search) && $this->_use_search); - } - - public function useShopRestriction() - { - return (isset($this->_use_shop_restriction) && $this->_use_shop_restriction); - } - - public function render($data = null) - { - if (!isset($data)) { - $data = $this->getData(); - } - - if (isset($this->_disabled_categories) - && !empty($this->_disabled_categories)) { - $this->_disableCategories($data, $this->getDisabledCategories()); - } - - if($this->getDisablAllCategories()) { - $this->_disableCategories($data); - } - - //Default bootstrap style of search is push-right, so we add this button first - if ($this->useSearch()) { - $this->addAction(new TreeToolbarSearchCategories( - 'Find a category:', - $this->getId().'-categories-search') - ); - $this->setAttribute('use_search', $this->useSearch()); - } - - $collapse_all = new TreeToolbarLink( - 'Collapse All', - '#', - '$(\'#'.$this->getId().'\').tree(\'collapseAll\');$(\'#collapse-all-'.$this->getId().'\').hide();$(\'#expand-all-'.$this->getId().'\').show(); return false;', - 'icon-collapse-alt'); - $collapse_all->setAttribute('id', 'collapse-all-'.$this->getId()); - - $expand_all = new TreeToolbarLink( - 'Expand All', - '#', - '$(\'#'.$this->getId().'\').tree(\'expandAll\');$(\'#collapse-all-'.$this->getId().'\').show();$(\'#expand-all-'.$this->getId().'\').hide(); return false;', - 'icon-expand-alt'); - $expand_all->setAttribute('id', 'expand-all-'.$this->getId()); - $this->addAction($collapse_all); - $this->addAction($expand_all); - - if ($this->useCheckBox()) { - if ($this->useBulkActions()) { - $check_all = new TreeToolbarLink( - 'Check All', - '#', - 'checkAllAssociatedHotels($(\'#'.$this->getId().'\'));return false;', - 'icon-check-sign'); - $check_all->setAttribute('id', 'check-all-'.$this->getId()); - $uncheck_all = new TreeToolbarLink( - 'Uncheck All', - '#', - 'uncheckAllAssociatedHotels($(\'#'.$this->getId().'\'));return false;', - 'icon-check-empty'); - $uncheck_all->setAttribute('id', 'uncheck-all-'.$this->getId()); - $this->addAction($check_all); - $this->addAction($uncheck_all); - } - - $this->setNodeFolderTemplate('tree_node_hotel_folder_checkbox.tpl'); - $this->setNodeItemTemplate('tree_node_hotel_item_checkbox.tpl'); - $this->setAttribute('use_checkbox', $this->useCheckBox()); - } - - $this->setAttribute('selected_hotels', $this->getSelectedHotels()); - $this->setAttribute('selected_roomtypes', $this->getSelectedRoomTypes()); - $this->getContext()->smarty->assign('root_category', Configuration::get('PS_ROOT_CATEGORY')); - $this->getContext()->smarty->assign('token', Tools::getAdminTokenLite('AdminProducts')); - return parent::render($data); - } - - /* Override */ - public function renderNodes($data = null) - { - if (!isset($data)) { - $data = $this->getData(); - } - - if (!is_array($data) && !$data instanceof Traversable) { - throw new PrestaShopException('Data value must be an traversable array'); - } - - $html = ''; - foreach ($data as $item) { - if (array_key_exists('children', $item)) { - $html .= $this->getContext()->smarty->createTemplate( - $this->getTemplateFile($this->getNodeFolderTemplate()), - $this->getContext()->smarty - )->assign(array( - 'input_name' => 'hotelBox', - 'children' => $this->renderNodes($item['children']), - 'node' => $item - ))->fetch(); - } else { - $html .= $this->getContext()->smarty->createTemplate( - $this->getTemplateFile($this->getNodeItemTemplate()), - $this->getContext()->smarty - )->assign(array( - 'input_name' => 'roomTypeBox', - 'node' => $item - ))->fetch(); - } - } - - return $html; - } - - private function _disableCategories(&$categories, $disabled_categories = null) - { - foreach ($categories as &$category) { - if (!isset($disabled_categories) || in_array($category['id_category'], $disabled_categories)) { - $category['disabled'] = true; - if (array_key_exists('children', $category) && is_array($category['children'])) { - self::_disableCategories($category['children']); - } - } elseif (array_key_exists('children', $category) && is_array($category['children'])) { - self::_disableCategories($category['children'], $disabled_categories); - } - } - } - - private function _getSelectedChildNumbers(&$categories, $selected, &$parent = null) - { - $selected_childs = 0; - - foreach ($categories as $key => &$category) { - if (isset($parent) && in_array($category['id_category'], $selected)) { - $selected_childs++; - } - - if (isset($category['children']) && !empty($category['children'])) { - $selected_childs += $this->_getSelectedChildNumbers($category['children'], $selected, $category); - } - } - - if (!isset($parent['selected_childs'])) { - $parent['selected_childs'] = 0; - } - - $parent['selected_childs'] = $selected_childs; - return $selected_childs; - } -} diff --git a/classes/helper/HelperTreeShops.php b/classes/helper/HelperTreeShops.php index dfda87060..1f66edab0 100644 --- a/classes/helper/HelperTreeShops.php +++ b/classes/helper/HelperTreeShops.php @@ -68,24 +68,6 @@ class HelperTreeShopsCore extends TreeCore return $this->_lang; } - public function getNodeFolderTemplate() - { - if (!isset($this->_node_folder_template)) { - $this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE); - } - - return $this->_node_folder_template; - } - - public function getNodeItemTemplate() - { - if (!isset($this->_node_item_template)) { - $this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE); - } - - return $this->_node_item_template; - } - public function setSelectedShops($value) { if (!is_array($value)) { @@ -105,15 +87,6 @@ class HelperTreeShopsCore extends TreeCore return $this->_selected_shops; } - public function getTemplate() - { - if (!isset($this->_template)) { - $this->setTemplate(self::DEFAULT_TEMPLATE); - } - - return $this->_template; - } - public function render($data = null, $use_default_actions = true, $use_selected_shop = true) { if (!isset($data)) { diff --git a/classes/tree/Tree.php b/classes/tree/Tree.php index db720f1de..fe5f7817f 100644 --- a/classes/tree/Tree.php +++ b/classes/tree/Tree.php @@ -191,7 +191,7 @@ class TreeCore public function getHeaderTemplate() { if (!isset($this->_headerTemplate)) { - $this->setHeaderTemplate(self::DEFAULT_HEADER_TEMPLATE); + $this->setHeaderTemplate(static::DEFAULT_HEADER_TEMPLATE); } return $this->_headerTemplate; @@ -217,7 +217,7 @@ class TreeCore public function getNodeFolderTemplate() { if (!isset($this->_node_folder_template)) { - $this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE); + $this->setNodeFolderTemplate(static::DEFAULT_NODE_FOLDER_TEMPLATE); } return $this->_node_folder_template; @@ -232,7 +232,7 @@ class TreeCore public function getNodeItemTemplate() { if (!isset($this->_node_item_template)) { - $this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE); + $this->setNodeItemTemplate(static::DEFAULT_NODE_ITEM_TEMPLATE); } return $this->_node_item_template; @@ -247,7 +247,7 @@ class TreeCore public function getTemplate() { if (!isset($this->_template)) { - $this->setTemplate(self::DEFAULT_TEMPLATE); + $this->setTemplate(static::DEFAULT_TEMPLATE); } return $this->_template; @@ -271,7 +271,7 @@ class TreeCore { if (!isset($this->_template_directory)) { $this->_template_directory = $this->_normalizeDirectory( - self::DEFAULT_TEMPLATE_DIRECTORY); + static::DEFAULT_TEMPLATE_DIRECTORY); } return $this->_template_directory; diff --git a/config/defines.inc.php b/config/defines.inc.php index 4a86b1930..3e319225f 100644 --- a/config/defines.inc.php +++ b/config/defines.inc.php @@ -26,7 +26,7 @@ /* Debug only */ if (!defined('_PS_MODE_DEV_')) { - define('_PS_MODE_DEV_', false); + define('_PS_MODE_DEV_', true); } /* Compatibility warning */ define('_PS_DISPLAY_COMPATIBILITY_WARNING_', false); diff --git a/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php index 29204f4e2..3d794c1a5 100644 --- a/controllers/admin/AdminNormalProductsController.php +++ b/controllers/admin/AdminNormalProductsController.php @@ -2875,7 +2875,7 @@ class AdminNormalProductsControllerCore extends AdminController { if (Validate::isLoadedObject($product)) { $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); - $associatedRoomTypes = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product->id)['room_types']; + $associatedRoomTypes = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product->id)['room_type']; if (Product::SERVICE_PRODUCT_WITH_ROOMTYPE == $product->service_product_type) { $selectedRoomTypes = Tools::getValue('roomTypeBox'); @@ -3499,18 +3499,16 @@ class AdminNormalProductsControllerCore extends AdminController $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); $selectedElements = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product->id); - $tree = new HelperTreeHotels('associated-hotels-tree', 'Associated hotels'); - $tree->setTemplate('tree_associated_hotels.tpl') - ->setHeaderTemplate('tree_associated_header.tpl') - ->setRootCategory((int)Configuration::get('PS_LOCATIONS_CATEGORY')) - ->setUseCheckBox(true) - ->setFullTree(true) - ->setRoomsOnly(false) - ->setSelectedHotels($selectedElements['hotels']) - ->setSelectedRoomTypes($selectedElements['room_types']) - ->setUseBulkActions(true) - ->setAccessedHotels(HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1, 0)); + $tree = new HelperTree('hotels-tree'); + $tree->setData(HotelHelper::generateTreeData([ + // 'rootNode' => HotelHelper::NODE_HOTEL, + // 'leafNode' => HotelHelper::NODE_ROOM_TYPE, + 'selectedElements' => $selectedElements + ])) + ->setUseCheckBox(true) + ->setUseBulkActions(true) + ->setUseSearch(true); $data->assign('hotel_tree', $tree->render()); // TinyMCE diff --git a/controllers/admin/AdminPatternsController.php b/controllers/admin/AdminPatternsController.php index 11456fcc1..d49df4cad 100644 --- a/controllers/admin/AdminPatternsController.php +++ b/controllers/admin/AdminPatternsController.php @@ -375,7 +375,7 @@ class AdminPatternsControllerCore extends AdminController 'root_category' => 1, 'id' => 'id_category', 'name' => 'name_category', - 'selected_categories' => array(3), + 'selected_categories' => array(3, 8), ) ), array( diff --git a/controllers/admin/AdminSearchController.php b/controllers/admin/AdminSearchController.php index 4d5cd5237..1b4812a05 100644 --- a/controllers/admin/AdminSearchController.php +++ b/controllers/admin/AdminSearchController.php @@ -246,7 +246,7 @@ class AdminSearchControllerCore extends AdminController } } else if ($associatedData = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product['id_product'])) { $count = 0; - foreach ($associatedData['room_types'] as $id_room_type) { + foreach ($associatedData['room_type'] as $id_room_type) { $objRoomType = new HotelRoomType($id_room_type); if (in_array($objRoomType->id_hotel, $accessibleHotels)) { $count += 1; diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 1b3057831..b6e6f1030 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -2521,4 +2521,182 @@ class HotelHelper return $isValid; } + + /** + * This function is a utility function for creating an associative array for generating tree + * provide tree structure in the following format + * country --> root + * state + * city + * hotel + * room_type + * room --> leaf + * + * You can edit the start and end point to generate tree for different levels + * @param $start + * @param $end + * @param $start_element_id int|array + * @param $selected_elements int|array + */ + + const NODE_COUNTRY = 1; + const NODE_STATE = 2; + const NODE_CITY = 3; + const NODE_HOTEL = 4; + const NODE_ROOM_TYPE = 5; + const NODE_ROOM = 6; + + public static function generateTreeData($params) + { + // $rootNode = 'country' + // $leafNode = 'room' + // $startElementId = false + // $selectedElements = array() + + + extract($params); + + if (!isset($rootNode)) { + $rootNode = self::NODE_COUNTRY; + } + if (!isset($leafNode)) { + $leafNode = self::NODE_ROOM; + } + if (!isset($leafNode)) { + $selectedElements = array(); + } + $rootNodeId = false; + $treeData = array(); + if ($rootNode <= self::NODE_COUNTRY && $leafNode >= self::NODE_COUNTRY) { + self::generateCountryTree($treeData, $rootNode, $rootNodeId, $selectedElements); + } + if ($rootNode <= self::NODE_STATE && $leafNode >= self::NODE_STATE) { + self::generateStateTree($treeData, $rootNode, $rootNodeId, $selectedElements); + + } + if ($rootNode <= self::NODE_CITY && $leafNode >= self::NODE_CITY) { + self::generateCityTree($treeData, $rootNode, $rootNodeId, $selectedElements); + + } + if ($rootNode <= self::NODE_HOTEL && $leafNode >= self::NODE_HOTEL) { + self::generateHotelTree($treeData, $rootNode, $rootNodeId, $selectedElements); + } + if ($rootNode <= self::NODE_ROOM_TYPE && $leafNode >= self::NODE_ROOM_TYPE) { + self::generateRoomTypeTree($treeData, $rootNode, $rootNodeId, $selectedElements); + + } + if ($rootNode <= self::NODE_ROOM && $leafNode >= self::NODE_ROOM) { + self::generateRoomTree($treeData, $rootNode, $rootNodeId, $selectedElements); + } + // $objHotelInfo = new HotelBranchInformation(); + // if ($hotels = $objHotelInfo->hotelBranchesInfo()) { + // foreach ($hotels as $hotel) { + // $objRoomType = new HotelRoomType(); + // if ($roomTypes = $objRoomType->getRoomTypeByHotelId($hotel['id'], Context::getContext()->language->id)) { + // foreach ($roomTypes as &$roomType) { + // $objHotelRoomInformation = new HotelRoomInformation(); + // if ($rooms = $objHotelRoomInformation->getHotelRoomInfoByProductId($roomType['id_product'])) { + // foreach ($rooms as &$room) { + // $room = array( + // 'name' => $room['room_num'], + // 'input_name' => 'room', + // 'value' => $room['id'] + // ); + + // if (isset($selectedElements['room']) && in_array($room['id'], $selectedElements['room'])) { + // $room['selected'] = true; + // } + // } + // } + // $roomType = array( + // 'name' => $roomType['room_type'], + // 'input_name' => 'roomTypeBox', + // 'value' => $roomType['id_product'], + // 'children' => $rooms + // ); + // if (isset($selectedElements['room_type']) && in_array($roomType['id_product'], $selectedElements['room_type'])) { + // $roomType['selected'] = true; + // } + // } + // } + + // $hotel = array( + // 'name' => $hotel['hotel_name'], + // 'input_name' => 'hotelBox', + // 'value' => $hotel['id'], + // 'children' => $roomTypes + // ); + // if (isset($selectedElements['hotel']) && in_array($hotel['id'], $selectedElements['hotel'])) { + // $hotel['selected'] = true; + // } + // $treeData[] = array( + // 'name' => $hotel['hotel_name'], + // 'input_name' => 'hotelBox', + // 'value' => $hotel['id'], + // 'children' => $roomTypes + // ); + // } + // } + ddd($treeData); + return $treeData; + } + + public static function generateHotelTree(&$treeData, $rootNode, $rootNodeId) + { + // $objHotelInfo = new HotelBranchInformation(); + // if ($hotels = $objHotelInfo->hotelBranchesInfo()) { + // } + + } + public static function generateRoomTypeTree(&$treeData, $rootNode, $rootNodeId) + { + + } + public static function generateRoomTree(&$treeData, $rootNode, $rootNodeId) + { + + } + + public static function generateCountryTree(&$treeData, $rootNode, $rootNodeId) + { + $locationCategory = new Category(Configuration::get('PS_LOCATIONS_CATEGORY')); + + if ($countries = Db::getInstance()->executeS( + 'SELECT cl.`id_category` as `value` , cl.`name` as `name` + FROM `'._DB_PREFIX_.'category_lang` AS cl + INNER JOIN `'._DB_PREFIX_.'category` AS c ON (cl.`id_category` = c.`id_category`) + WHERE c.`id_parent` = '.(int)Configuration::get('PS_LOCATIONS_CATEGORY').' and cl.`id_lang`='.(int)Context::getContext()->language->id.' + GROUP BY cl.`name`' + )) { + foreach ($countries as $country) { + $country['input_name'] = 'countryBox'; + if (isset($selectedElements['country']) && in_array($country['id'], $selectedElements['country'])) { + $country['selected'] = true; + } + $treeData[$country['value']] = $country; + } + } + } + public static function generateStateTree(&$treeData, $rootNode, $rootNodeId) + { + if ($states = Db::getInstance()->executeS( + 'SELECT cl.`id_category` as `value` , cl.`name` as `name` + FROM `'._DB_PREFIX_.'category_lang` AS cl + INNER JOIN `'._DB_PREFIX_.'category` AS c ON (cl.`id_category` = c.`id_category`) + WHERE c.`id_parent` = '.(int)Configuration::get('PS_LOCATIONS_CATEGORY').' and cl.`id_lang`='.(int)Context::getContext()->language->id.' + GROUP BY cl.`name`' + )) { + foreach ($states as $country) { + $country['input_name'] = 'countryBox'; + if (isset($selectedElements['country']) && in_array($country['id'], $selectedElements['country'])) { + $country['selected'] = true; + } + $treeData[$country['value']] = $country; + } + } + } + public static function generateCityTree(&$treeData, $rootNode, $rootNodeId) + { + + } } diff --git a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php index 5acb6ef60..d2e2ff350 100644 --- a/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php +++ b/modules/hotelreservationsystem/classes/RoomTypeServiceProduct.php @@ -107,9 +107,9 @@ class RoomTypeServiceProduct extends ObjectModel ); if ($formated) { - $response = array('hotels' => array(), 'room_types' => array()); + $response = array('hotel' => array(), 'room_type' => array()); foreach($rows as $row) { - $key = $row['element_type'] == self::WK_ELEMENT_TYPE_HOTEL ? 'hotels' : 'room_types'; + $key = $row['element_type'] == self::WK_ELEMENT_TYPE_HOTEL ? 'hotel' : 'room_type'; $response[$key][] = $row['id_element']; } return $response; From 10b299d8ed0239e020758b424ccb4003db85d4f6 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 5 Aug 2024 17:05:07 +0530 Subject: [PATCH 2/4] Updated helper tree| created new helper tree for generating tree --- admin/themes/default/sass/partials/_tree.sass | 5 + .../normal_products/helpers/tree/tree.tpl | 39 ++ .../normal_products/informations.tpl | 4 +- .../default/template/helpers/tree/tree.tpl | 121 +++--- .../helpers/tree/tree_node_folder.tpl | 6 + .../tree/tree_node_folder_checkbox.tpl | 13 +- .../helpers/tree/tree_node_folder_radio.tpl | 12 +- .../template/helpers/tree/tree_node_item.tpl | 6 + .../helpers/tree/tree_node_item_checkbox.tpl | 6 + .../helpers/tree/tree_node_item_radio.tpl | 6 + classes/helper/HelperTree.php | 21 +- classes/tree/Tree.php | 23 +- .../admin/AdminNormalProductsController.php | 6 +- .../classes/HotelHelper.php | 356 ++++++++++++------ 14 files changed, 430 insertions(+), 194 deletions(-) create mode 100644 admin/themes/default/template/controllers/normal_products/helpers/tree/tree.tpl diff --git a/admin/themes/default/sass/partials/_tree.sass b/admin/themes/default/sass/partials/_tree.sass index 897c29f85..9d382680e 100644 --- a/admin/themes/default/sass/partials/_tree.sass +++ b/admin/themes/default/sass/partials/_tree.sass @@ -7,6 +7,7 @@ font-size: $icon-size-base .tree list-style: none + overflow: auto @include padding(0, 0, 0, 20px) input vertical-align: baseline @@ -42,6 +43,10 @@ &:hover color: #ccc background-color: none + .node-hint + font-style: italic + color: #959595 + margin-left: 30px .tree-actions display: inline-block diff --git a/admin/themes/default/template/controllers/normal_products/helpers/tree/tree.tpl b/admin/themes/default/template/controllers/normal_products/helpers/tree/tree.tpl new file mode 100644 index 000000000..ce2479919 --- /dev/null +++ b/admin/themes/default/template/controllers/normal_products/helpers/tree/tree.tpl @@ -0,0 +1,39 @@ +{* +* Since 2010 Webkul. +* +* NOTICE OF LICENSE +* +* All right is reserved, +* Please go through this link for complete license : https://store.webkul.com/license.html +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade this module to 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 IN +* @license https://store.webkul.com/license.html +*} +{extends file="helpers/tree/tree.tpl"} + \ No newline at end of file diff --git a/admin/themes/default/template/controllers/normal_products/informations.tpl b/admin/themes/default/template/controllers/normal_products/informations.tpl index 49537d7dd..81088a6b0 100644 --- a/admin/themes/default/template/controllers/normal_products/informations.tpl +++ b/admin/themes/default/template/controllers/normal_products/informations.tpl @@ -234,13 +234,13 @@
    service_product_type == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE}style="display:none;"{/if}>
    {include file="controllers/products/multishop/checkbox.tpl" field="category_box" type="category_box"}
    -
  • - {* {if isset($node['value']) && $node['value'] != $root_category} *} - {if !isset($node['input_name'])}test{/if} - - {* {/if} *} + {if $selectable} + + {/if} + {if isset($node['badge'])} + {$node['badge']['title']} + {/if} + {if isset($node['hint'])} +
    {$node['hint']}
    + {/if}
      {$children|escape:'UTF-8'}
    diff --git a/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl b/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl index 511d52458..c0f7945d1 100644 --- a/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl +++ b/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl @@ -24,12 +24,18 @@ *}
  • - {* {if $node[$input_id] != $root_category} *} - - {* {/if} *} + {if $selectable} + + {/if} + {if isset($node['badge'])} + {$node['badge']['title']} + {/if} + {if isset($node['hint'])} +
    {$node['hint']}
    + {/if}
      {$children}
    diff --git a/admin/themes/default/template/helpers/tree/tree_node_item.tpl b/admin/themes/default/template/helpers/tree/tree_node_item.tpl index 0e2bed62a..b7553043a 100644 --- a/admin/themes/default/template/helpers/tree/tree_node_item.tpl +++ b/admin/themes/default/template/helpers/tree/tree_node_item.tpl @@ -28,4 +28,10 @@ + {if isset($node['badge'])} + {$node['badge']['title']} + {/if} + {if isset($node['hint'])} +
    {$node['hint']}
    + {/if}
  • \ No newline at end of file diff --git a/admin/themes/default/template/helpers/tree/tree_node_item_checkbox.tpl b/admin/themes/default/template/helpers/tree/tree_node_item_checkbox.tpl index e4db8e373..b0b7f42f5 100644 --- a/admin/themes/default/template/helpers/tree/tree_node_item_checkbox.tpl +++ b/admin/themes/default/template/helpers/tree/tree_node_item_checkbox.tpl @@ -28,4 +28,10 @@ + {if isset($node['badge'])} + {$node['badge']['title']} + {/if} + {if isset($node['hint'])} +
    {$node['hint']}
    + {/if} diff --git a/admin/themes/default/template/helpers/tree/tree_node_item_radio.tpl b/admin/themes/default/template/helpers/tree/tree_node_item_radio.tpl index fd03456fa..9053a3cea 100644 --- a/admin/themes/default/template/helpers/tree/tree_node_item_radio.tpl +++ b/admin/themes/default/template/helpers/tree/tree_node_item_radio.tpl @@ -28,4 +28,10 @@ + {if isset($node['badge'])} + {$node['badge']['title']} + {/if} + {if isset($node['hint'])} +
    {$node['hint']}
    + {/if} \ No newline at end of file diff --git a/classes/helper/HelperTree.php b/classes/helper/HelperTree.php index f3545e058..7c5d25e7f 100644 --- a/classes/helper/HelperTree.php +++ b/classes/helper/HelperTree.php @@ -29,6 +29,7 @@ class HelperTreeCore extends TreeCore private $_use_bulk_actions; private $_use_checkbox; private $_show_collapse_expand_button = true; + private $_max_height = 350; public function setUseSearch($value) @@ -70,6 +71,18 @@ class HelperTreeCore extends TreeCore return $this; } + public function setMaxHeight($value) + { + $this->_max_height = (bool)$value; + return $this; + } + + public function maxHeight() + { + return $this->_max_height; + } + + public function showCollapseExpandButton() { return (isset($this->_show_collapse_expand_button) && $this->_show_collapse_expand_button); @@ -77,7 +90,6 @@ class HelperTreeCore extends TreeCore public function render($data = null) { - if ($this->useCheckBox()) { if($this->useBulkActions()) { $check_all = new TreeToolbarLink( @@ -125,11 +137,10 @@ class HelperTreeCore extends TreeCore $this->addAction($expand_all); } + $this->setAttribute('max_height', $this->maxHeight()); + $this->setAttribute('root_selectable', $this->rootElementSelectable()); + return parent::render($data); } - - - - } \ No newline at end of file diff --git a/classes/tree/Tree.php b/classes/tree/Tree.php index fe5f7817f..0c9e07222 100644 --- a/classes/tree/Tree.php +++ b/classes/tree/Tree.php @@ -42,6 +42,8 @@ class TreeCore protected $_node_folder_template; protected $_node_item_template; protected $_template; + private $_root_element_selectable = true; + /** @var string */ private $_template_directory; @@ -342,6 +344,17 @@ class TreeCore return $this; } + public function setRootElementSelectable($value) + { + $this->_root_element_selectable = (bool)$value; + return $this; + } + + public function rootElementSelectable() + { + return (isset($this->_root_element_selectable) && $this->_root_element_selectable); + } + public function getToolbar() { if (isset($this->_toolbar)) { @@ -419,14 +432,14 @@ class TreeCore //Assign Tree nodes $template->assign($this->getAttributes())->assign(array( 'id' => $this->getId(), - 'nodes' => $this->renderNodes($data), + 'nodes' => $this->renderNodes($data, true), 'id_tree' => $this->getIdTree() )); return (isset($html) ? $html : '').$template->fetch(); } - public function renderNodes($data = null) + public function renderNodes($data = null, $root = false) { if (!isset($data)) { $data = $this->getData(); @@ -446,14 +459,16 @@ class TreeCore $this->getContext()->smarty )->assign(array( 'children' => $this->renderNodes($item['children']), - 'node' => $item + 'node' => $item, + 'selectable' => !$root || $this->rootElementSelectable() ))->fetch(); } else { $html .= $this->getContext()->smarty->createTemplate( $this->getTemplateFile($this->getNodeItemTemplate()), $this->getContext()->smarty )->assign(array( - 'node' => $item + 'node' => $item, + 'selectable' => !$root || $this->rootElementSelectable() ))->fetch(); } } diff --git a/controllers/admin/AdminNormalProductsController.php b/controllers/admin/AdminNormalProductsController.php index 3d794c1a5..0e52ca53f 100644 --- a/controllers/admin/AdminNormalProductsController.php +++ b/controllers/admin/AdminNormalProductsController.php @@ -2877,7 +2877,7 @@ class AdminNormalProductsControllerCore extends AdminController $objRoomTypeServiceProduct = new RoomTypeServiceProduct(); $associatedRoomTypes = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product->id)['room_type']; if (Product::SERVICE_PRODUCT_WITH_ROOMTYPE == $product->service_product_type) { - $selectedRoomTypes = Tools::getValue('roomTypeBox'); + $selectedRoomTypes = Tools::getValue('room_type_box'); // Generate list of new associations $newRoomTypes = array(); @@ -3502,8 +3502,8 @@ class AdminNormalProductsControllerCore extends AdminController $tree = new HelperTree('hotels-tree'); $tree->setData(HotelHelper::generateTreeData([ - // 'rootNode' => HotelHelper::NODE_HOTEL, - // 'leafNode' => HotelHelper::NODE_ROOM_TYPE, + 'rootNode' => HotelHelper::NODE_HOTEL, + 'leafNode' => HotelHelper::NODE_ROOM_TYPE, 'selectedElements' => $selectedElements ])) ->setUseCheckBox(true) diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index b6e6f1030..4fe8b4f87 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -2533,10 +2533,10 @@ class HotelHelper * room --> leaf * * You can edit the start and end point to generate tree for different levels - * @param $start - * @param $end - * @param $start_element_id int|array - * @param $selected_elements int|array + * @param $rootNode = 'country' + * @param $leafNode = 'room' + * @param $rootNodeId int|array + * @param $selectedElements int|array */ const NODE_COUNTRY = 1; @@ -2548,12 +2548,6 @@ class HotelHelper public static function generateTreeData($params) { - // $rootNode = 'country' - // $leafNode = 'room' - // $startElementId = false - // $selectedElements = array() - - extract($params); if (!isset($rootNode)) { @@ -2562,141 +2556,265 @@ class HotelHelper if (!isset($leafNode)) { $leafNode = self::NODE_ROOM; } - if (!isset($leafNode)) { + if (!isset($selectedElements)) { $selectedElements = array(); } - $rootNodeId = false; + if (!isset($rootNodeId)) { + $rootNodeId = false; + } $treeData = array(); - if ($rootNode <= self::NODE_COUNTRY && $leafNode >= self::NODE_COUNTRY) { - self::generateCountryTree($treeData, $rootNode, $rootNodeId, $selectedElements); - } - if ($rootNode <= self::NODE_STATE && $leafNode >= self::NODE_STATE) { - self::generateStateTree($treeData, $rootNode, $rootNodeId, $selectedElements); + if ($rootNode == self::NODE_COUNTRY) { + $treeData = self::generateCountryTree($selectedElements, $leafNode, $rootNodeId); + } else if ($rootNode == self::NODE_STATE) { + $treeData = self::generateStateTree($selectedElements, $leafNode, $rootNodeId); + } else if ($rootNode == self::NODE_CITY) { + $treeData = self::generateCityTree($selectedElements, $leafNode, $rootNodeId); + } else if ($rootNode == self::NODE_HOTEL) { + $treeData = self::generateHotelTree($selectedElements, $leafNode, $rootNodeId); + } else if ($rootNode == self::NODE_ROOM_TYPE) { + $treeData = self::generateRoomTypeTree($selectedElements, $leafNode, $rootNodeId); + } else if ($rootNode == self::NODE_ROOM) { + $treeData = self::generateRoomTree($selectedElements, $leafNode, $rootNodeId); } - if ($rootNode <= self::NODE_CITY && $leafNode >= self::NODE_CITY) { - self::generateCityTree($treeData, $rootNode, $rootNodeId, $selectedElements); - } - if ($rootNode <= self::NODE_HOTEL && $leafNode >= self::NODE_HOTEL) { - self::generateHotelTree($treeData, $rootNode, $rootNodeId, $selectedElements); - } - if ($rootNode <= self::NODE_ROOM_TYPE && $leafNode >= self::NODE_ROOM_TYPE) { - self::generateRoomTypeTree($treeData, $rootNode, $rootNodeId, $selectedElements); - - } - if ($rootNode <= self::NODE_ROOM && $leafNode >= self::NODE_ROOM) { - self::generateRoomTree($treeData, $rootNode, $rootNodeId, $selectedElements); - } - // $objHotelInfo = new HotelBranchInformation(); - // if ($hotels = $objHotelInfo->hotelBranchesInfo()) { - // foreach ($hotels as $hotel) { - // $objRoomType = new HotelRoomType(); - // if ($roomTypes = $objRoomType->getRoomTypeByHotelId($hotel['id'], Context::getContext()->language->id)) { - // foreach ($roomTypes as &$roomType) { - // $objHotelRoomInformation = new HotelRoomInformation(); - // if ($rooms = $objHotelRoomInformation->getHotelRoomInfoByProductId($roomType['id_product'])) { - // foreach ($rooms as &$room) { - // $room = array( - // 'name' => $room['room_num'], - // 'input_name' => 'room', - // 'value' => $room['id'] - // ); - - // if (isset($selectedElements['room']) && in_array($room['id'], $selectedElements['room'])) { - // $room['selected'] = true; - // } - // } - // } - // $roomType = array( - // 'name' => $roomType['room_type'], - // 'input_name' => 'roomTypeBox', - // 'value' => $roomType['id_product'], - // 'children' => $rooms - // ); - // if (isset($selectedElements['room_type']) && in_array($roomType['id_product'], $selectedElements['room_type'])) { - // $roomType['selected'] = true; - // } - // } - // } - - // $hotel = array( - // 'name' => $hotel['hotel_name'], - // 'input_name' => 'hotelBox', - // 'value' => $hotel['id'], - // 'children' => $roomTypes - // ); - // if (isset($selectedElements['hotel']) && in_array($hotel['id'], $selectedElements['hotel'])) { - // $hotel['selected'] = true; - // } - // $treeData[] = array( - // 'name' => $hotel['hotel_name'], - // 'input_name' => 'hotelBox', - // 'value' => $hotel['id'], - // 'children' => $roomTypes - // ); - // } - // } - ddd($treeData); return $treeData; } - public static function generateHotelTree(&$treeData, $rootNode, $rootNodeId) + public static function generateCountryTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) { - // $objHotelInfo = new HotelBranchInformation(); - // if ($hotels = $objHotelInfo->hotelBranchesInfo()) { - // } + $return = array(); + $countries = self::getcategoryByParent($previousElements, 3, 'country', $rootNodeId); + $stateIds = array_column($countries, 'value'); + if ($leafNode > self::NODE_COUNTRY) { + $states = self::generateStateTree($selectedElements, $leafNode, false, $stateIds); + } + + foreach ($countries as $country) { + if (isset($selectedElements['state']) && in_array($country['value'], $selectedElements['state'])) { + $country['selected'] = true; + } + + if (isset($states[$country['value']])) { + $country['children'] = $states[$country['value']]; + } + + if ($previousElements) { + $return[$country['id_parent']][] = $country; + } else { + $return[] = $country; + } + } + + return $return; } - public static function generateRoomTypeTree(&$treeData, $rootNode, $rootNodeId) + public static function generateStateTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) { + $return = array(); + $states = self::getcategoryByParent($previousElements, 4, 'state', $rootNodeId); + $stateIds = array_column($states, 'value'); + if ($leafNode > self::NODE_STATE) { + $cities = self::generateCityTree($selectedElements, $leafNode, false, $stateIds); + } + + foreach ($states as $state) { + if (isset($selectedElements['state']) && in_array($state['value'], $selectedElements['state'])) { + $state['selected'] = true; + } + + if (isset($cities[$state['value']])) { + $state['children'] = $cities[$state['value']]; + } + + if ($previousElements) { + $return[$state['id_parent']][] = $state; + } else { + $return[] = $state; + } + } + + return $return; } - public static function generateRoomTree(&$treeData, $rootNode, $rootNodeId) + public static function generateCityTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) { + $return = array(); + $cities = self::getcategoryByParent($previousElements, 5, 'city', $rootNodeId); + $cityIds = array_column($cities, 'value'); + if ($leafNode > self::NODE_CITY) { + $hotels = self::generateHotelTree($selectedElements, $leafNode, false, $cityIds); + } + + foreach ($cities as $city) { + if (isset($selectedElements['city']) && in_array($city['value'], $selectedElements['city'])) { + $city['selected'] = true; + } + + if (isset($hotels[$city['value']])) { + $city['children'] = $hotels[$city['value']]; + } + + if ($previousElements) { + $return[$city['id_parent']][] = $city; + } else { + $return[] = $city; + } + } + + return $return; } - public static function generateCountryTree(&$treeData, $rootNode, $rootNodeId) + public static function generateHotelTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) + { + $return = array(); + $hotels = self::getHotelsByIdCity($previousElements, $rootNodeId); + $hotelIds = array_column($hotels, 'value'); + + if ($leafNode > self::NODE_HOTEL) { + $roomTypes = self::generateRoomTypeTree($selectedElements, $leafNode, false, $hotelIds); + } + + foreach ($hotels as $hotel) { + if (isset($selectedElements['hotel']) && in_array($hotel['value'], $selectedElements['hotel'])) { + $hotel['selected'] = true; + } + + if (isset($roomTypes[$hotel['value']])) { + $hotel['children'] = $roomTypes[$hotel['value']]; + } + + if ($previousElements) { + $return[$hotel['id_parent']][] = $hotel; + } else { + $return[] = $hotel; + } + } + + return $return; + } + + public static function generateRoomTypeTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) + { + $return = array(); + $roomTypes = self::getRoomTypesByHotelsId($previousElements, $rootNodeId); + $roomTypeIds = array_column($roomTypes, 'value'); + + if ($leafNode > self::NODE_ROOM_TYPE) { + $rooms = self::generateRoomTree($selectedElements, $leafNode, false, $roomTypeIds); + } + + foreach ($roomTypes as $roomType) { + if (isset($selectedElements['room_type']) && in_array($roomType['value'], $selectedElements['room_type'])) { + $roomType['selected'] = true; + } + + if (isset($rooms[$roomType['value']])) { + $roomType['children'] = $rooms[$roomType['value']]; + } + + if ($previousElements) { + $return[$roomType['id_hotel']][] = $roomType; + } else { + $return[] = $roomType; + } + } + + return $return; + } + + public static function generateRoomTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) + { + $return = array(); + $rooms = self::getRoomsByRoomTypeId($previousElements, $rootNodeId); + + foreach ($rooms as $room) { + if (isset($selectedElements['room']) && in_array($room['value'], $selectedElements['room'])) { + $room['selected'] = true; + } + + if ($previousElements) { + $return[$room['id_product']][] = $room; + } else { + $return[] = $room; + } + } + + return $return; + } + + public static function getcategoryByParent($idParents, $levelDepth, $input_name, $rootNodeId) { $locationCategory = new Category(Configuration::get('PS_LOCATIONS_CATEGORY')); + $sql = 'SELECT c.`id_category` as `value` , cl.`name`, "'.pSQL($input_name).'_box" as `input_name`, c.`id_parent` + FROM `'._DB_PREFIX_.'category` AS c + INNER JOIN `'._DB_PREFIX_.'category_lang` AS cl + ON (c.`id_category` = cl.`id_category` AND cl.`id_lang`='.(int)Context::getContext()->language->id.') + WHERE c.`nleft` > '.(int)$locationCategory->nleft.' AND c.`nright` < '.(int)$locationCategory->nright.' + AND c.`level_depth` = '.(int)$levelDepth; - if ($countries = Db::getInstance()->executeS( - 'SELECT cl.`id_category` as `value` , cl.`name` as `name` - FROM `'._DB_PREFIX_.'category_lang` AS cl - INNER JOIN `'._DB_PREFIX_.'category` AS c ON (cl.`id_category` = c.`id_category`) - WHERE c.`id_parent` = '.(int)Configuration::get('PS_LOCATIONS_CATEGORY').' and cl.`id_lang`='.(int)Context::getContext()->language->id.' - GROUP BY cl.`name`' - )) { - foreach ($countries as $country) { - $country['input_name'] = 'countryBox'; - if (isset($selectedElements['country']) && in_array($country['id'], $selectedElements['country'])) { - $country['selected'] = true; - } - $treeData[$country['value']] = $country; - } + if ($idParents) { + $sql .= ' AND c.`id_parent` IN ('.implode(', ', $idParents).')'; } - } - public static function generateStateTree(&$treeData, $rootNode, $rootNodeId) - { - if ($states = Db::getInstance()->executeS( - 'SELECT cl.`id_category` as `value` , cl.`name` as `name` - FROM `'._DB_PREFIX_.'category_lang` AS cl - INNER JOIN `'._DB_PREFIX_.'category` AS c ON (cl.`id_category` = c.`id_category`) - WHERE c.`id_parent` = '.(int)Configuration::get('PS_LOCATIONS_CATEGORY').' and cl.`id_lang`='.(int)Context::getContext()->language->id.' - GROUP BY cl.`name`' - )) { - foreach ($states as $country) { - $country['input_name'] = 'countryBox'; - if (isset($selectedElements['country']) && in_array($country['id'], $selectedElements['country'])) { - $country['selected'] = true; - } - $treeData[$country['value']] = $country; - } + if ($rootNodeId) { + $sql .= ' AND c.`id_category` = '.(int)$rootNodeId; } + + return Db::getInstance()->executeS($sql); } - public static function generateCityTree(&$treeData, $rootNode, $rootNodeId) + + public static function getHotelsByIdCity($cities, $rootNodeId) { + $sql = 'SELECT hbi.`id` as `value` , hbil.`hotel_name` as `name`, "hotel_box" as `input_name`, c.`id_parent` + FROM `'._DB_PREFIX_.'htl_branch_info` AS hbi + INNER JOIN `'._DB_PREFIX_.'htl_branch_info_lang` AS hbil + ON (hbi.`id` = hbil.`id` AND hbil.`id_lang`='.(int)Context::getContext()->language->id.') + INNER JOIN `'._DB_PREFIX_.'category` AS c ON (hbi.`id_category` = c.`id_category`) + WHERE 1'; + + if ($cities) { + $sql .= ' AND c.`id_parent` IN ('.implode(', ', $cities).')'; + } + if ($rootNodeId) { + $sql .= ' AND hbi.`id` = '.(int)$rootNodeId; + } + return Db::getInstance()->executeS($sql); + } + + public static function getRoomTypesByHotelsId($hotels, $rootNodeId) + { + $sql = 'SELECT p.`id_product` AS `value`, pl.`name`, "room_type_box" as `input_name`, rt.`id_hotel` + FROM `'._DB_PREFIX_.'htl_room_type` AS rt'; + + $sql .= ' INNER JOIN `'._DB_PREFIX_.'product` AS p ON (rt.`id_product` = p.`id_product`) + INNER JOIN `'._DB_PREFIX_.'product_lang` AS pl + ON (p.`id_product` = pl.`id_product` AND pl.`id_lang`='.(int)Context::getContext()->language->id.') + WHERE 1'; + + if ($hotels) { + $sql .= ' AND rt.`id_hotel` IN ('.implode(', ', $hotels).')'; + } + if ($rootNodeId) { + $sql .= ' AND p.`id_product` = '.(int)$rootNodeId; + } + + return Db::getInstance()->executeS($sql); + } + + public static function getRoomsByRoomTypeId($roomTypes, $rootNodeId) + { + $sql = 'SELECT `id` as `value`, `room_num` as `name`, "room_box" as `input_name`, `id_product` + FROM `'._DB_PREFIX_.'htl_room_information` + WHERE 1'; + if ($roomTypes) { + $sql .= ' AND `id_product` IN ('.implode(', ', $roomTypes).')'; + } + if ($rootNodeId) { + $sql .= ' AND `id` = '.(int)$rootNodeId; + } + + return Db::getInstance()->executeS($sql); } } From 8b2fa2546ea88896a10fd8af8f2244bed3740722 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Thu, 8 Aug 2024 13:08:29 +0530 Subject: [PATCH 3/4] Updated category tree render node function --- .../default/template/helpers/tree/tree_node_folder_checkbox.tpl | 2 +- .../default/template/helpers/tree/tree_node_folder_radio.tpl | 2 +- classes/helper/HelperTreeCategories.php | 2 +- classes/helper/HelperTreeShops.php | 2 +- config/defines.inc.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/admin/themes/default/template/helpers/tree/tree_node_folder_checkbox.tpl b/admin/themes/default/template/helpers/tree/tree_node_folder_checkbox.tpl index f4a584afa..6358d19ea 100644 --- a/admin/themes/default/template/helpers/tree/tree_node_folder_checkbox.tpl +++ b/admin/themes/default/template/helpers/tree/tree_node_folder_checkbox.tpl @@ -24,7 +24,7 @@ *}
  • - {if $selectable} + {if !isset($selectable) || $selectable} {/if} diff --git a/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl b/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl index c0f7945d1..0d14987f0 100644 --- a/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl +++ b/admin/themes/default/template/helpers/tree/tree_node_folder_radio.tpl @@ -24,7 +24,7 @@ *}
  • - {if $selectable} + {if !isset($selectable) || $selectable} {/if} diff --git a/classes/helper/HelperTreeCategories.php b/classes/helper/HelperTreeCategories.php index 4c328122c..e18583273 100644 --- a/classes/helper/HelperTreeCategories.php +++ b/classes/helper/HelperTreeCategories.php @@ -422,7 +422,7 @@ class HelperTreeCategoriesCore extends TreeCore } /* Override */ - public function renderNodes($data = null) + public function renderNodes($data = null, $root = false) { if (!isset($data)) { $data = $this->getData(); diff --git a/classes/helper/HelperTreeShops.php b/classes/helper/HelperTreeShops.php index 1f66edab0..c472d277d 100644 --- a/classes/helper/HelperTreeShops.php +++ b/classes/helper/HelperTreeShops.php @@ -126,7 +126,7 @@ class HelperTreeShopsCore extends TreeCore return parent::render($data); } - public function renderNodes($data = null) + public function renderNodes($data = null, $root = false) { if (!isset($data)) { $data = $this->getData(); diff --git a/config/defines.inc.php b/config/defines.inc.php index 3e319225f..4a86b1930 100644 --- a/config/defines.inc.php +++ b/config/defines.inc.php @@ -26,7 +26,7 @@ /* Debug only */ if (!defined('_PS_MODE_DEV_')) { - define('_PS_MODE_DEV_', true); + define('_PS_MODE_DEV_', false); } /* Compatibility warning */ define('_PS_DISPLAY_COMPATIBILITY_WARNING_', false); From b827ee75d01ccf77b81a520d9555921a89e2a573 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 21 Aug 2024 19:23:53 +0530 Subject: [PATCH 4/4] updated tree design and nodes generation helper function --- admin/themes/default/sass/partials/_tree.sass | 4 + classes/helper/HelperTree.php | 2 +- .../classes/HotelHelper.php | 82 +++++++++++++------ 3 files changed, 64 insertions(+), 24 deletions(-) diff --git a/admin/themes/default/sass/partials/_tree.sass b/admin/themes/default/sass/partials/_tree.sass index 9d382680e..39b2be7e6 100644 --- a/admin/themes/default/sass/partials/_tree.sass +++ b/admin/themes/default/sass/partials/_tree.sass @@ -47,6 +47,10 @@ font-style: italic color: #959595 margin-left: 30px + margin-top: -4px + margin-bottom: 4px + .badge + margin-left: 5px .tree-actions display: inline-block diff --git a/classes/helper/HelperTree.php b/classes/helper/HelperTree.php index 7c5d25e7f..0a3824205 100644 --- a/classes/helper/HelperTree.php +++ b/classes/helper/HelperTree.php @@ -114,7 +114,7 @@ class HelperTreeCore extends TreeCore if ($this->useSearch()) { $this->addAction(new TreeToolbarSearch( - 'dasdasd', + $this->getId().' search', $this->getId().'-search') ); $this->setAttribute('use_search', $this->useSearch()); diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 4fe8b4f87..d44240626 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -2565,30 +2565,33 @@ class HotelHelper $treeData = array(); if ($rootNode == self::NODE_COUNTRY) { - $treeData = self::generateCountryTree($selectedElements, $leafNode, $rootNodeId); + $treeData = self::generateCountryNodes($rootNodeId, $leafNode, $selectedElements); } else if ($rootNode == self::NODE_STATE) { - $treeData = self::generateStateTree($selectedElements, $leafNode, $rootNodeId); + $treeData = self::generateStateNodes($rootNodeId, $leafNode, $selectedElements); } else if ($rootNode == self::NODE_CITY) { - $treeData = self::generateCityTree($selectedElements, $leafNode, $rootNodeId); + $treeData = self::generateCityNodes($rootNodeId, $leafNode, $selectedElements); } else if ($rootNode == self::NODE_HOTEL) { - $treeData = self::generateHotelTree($selectedElements, $leafNode, $rootNodeId); + $treeData = self::generateHotelNodes($rootNodeId, $leafNode, $selectedElements); } else if ($rootNode == self::NODE_ROOM_TYPE) { - $treeData = self::generateRoomTypeTree($selectedElements, $leafNode, $rootNodeId); + $treeData = self::generateRoomTypeNodes($rootNodeId, $leafNode, $selectedElements); } else if ($rootNode == self::NODE_ROOM) { - $treeData = self::generateRoomTree($selectedElements, $leafNode, $rootNodeId); + $treeData = self::generateRoomNodes($rootNodeId, $leafNode, $selectedElements); } return $treeData; } - public static function generateCountryTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) + /** + * Generate the node data for country + */ + protected static function generateCountryNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false) { $return = array(); $countries = self::getcategoryByParent($previousElements, 3, 'country', $rootNodeId); - $stateIds = array_column($countries, 'value'); + $countriesIds = array_column($countries, 'value'); if ($leafNode > self::NODE_COUNTRY) { - $states = self::generateStateTree($selectedElements, $leafNode, false, $stateIds); + $states = self::generateStateNodes(false, $leafNode, $selectedElements, $countriesIds); } foreach ($countries as $country) { @@ -2609,14 +2612,18 @@ class HotelHelper return $return; } - public static function generateStateTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) + + /** + * Generate the node data for state + */ + protected static function generateStateNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false) { $return = array(); $states = self::getcategoryByParent($previousElements, 4, 'state', $rootNodeId); $stateIds = array_column($states, 'value'); if ($leafNode > self::NODE_STATE) { - $cities = self::generateCityTree($selectedElements, $leafNode, false, $stateIds); + $cities = self::generateCityNodes(false, $leafNode, $selectedElements, $stateIds); } foreach ($states as $state) { @@ -2637,14 +2644,18 @@ class HotelHelper return $return; } - public static function generateCityTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) + + /** + * Generate the node data for city + */ + protected static function generateCityNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false) { $return = array(); $cities = self::getcategoryByParent($previousElements, 5, 'city', $rootNodeId); $cityIds = array_column($cities, 'value'); if ($leafNode > self::NODE_CITY) { - $hotels = self::generateHotelTree($selectedElements, $leafNode, false, $cityIds); + $hotels = self::generateHotelNodes(false, $leafNode, $selectedElements, $cityIds); } foreach ($cities as $city) { @@ -2666,14 +2677,17 @@ class HotelHelper return $return; } - public static function generateHotelTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) + /** + * Generate the node data for hotels + */ + protected static function generateHotelNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false) { $return = array(); $hotels = self::getHotelsByIdCity($previousElements, $rootNodeId); $hotelIds = array_column($hotels, 'value'); if ($leafNode > self::NODE_HOTEL) { - $roomTypes = self::generateRoomTypeTree($selectedElements, $leafNode, false, $hotelIds); + $roomTypes = self::generateRoomTypeNodes(false, $leafNode, $selectedElements, $hotelIds); } foreach ($hotels as $hotel) { @@ -2695,14 +2709,17 @@ class HotelHelper return $return; } - public static function generateRoomTypeTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) + /** + * Generate the node data for room types + */ + protected static function generateRoomTypeNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false) { $return = array(); $roomTypes = self::getRoomTypesByHotelsId($previousElements, $rootNodeId); $roomTypeIds = array_column($roomTypes, 'value'); if ($leafNode > self::NODE_ROOM_TYPE) { - $rooms = self::generateRoomTree($selectedElements, $leafNode, false, $roomTypeIds); + $rooms = self::generateRoomNodes(false, $leafNode, $selectedElements, $roomTypeIds); } foreach ($roomTypes as $roomType) { @@ -2713,7 +2730,11 @@ class HotelHelper if (isset($rooms[$roomType['value']])) { $roomType['children'] = $rooms[$roomType['value']]; } - + $roomType['hint'] = 'This is Room type hint'; + $roomType['badge'] = array( + 'class' => 'badge-danger', + 'title' => 'Disabled' + ); if ($previousElements) { $return[$roomType['id_hotel']][] = $roomType; } else { @@ -2724,7 +2745,10 @@ class HotelHelper return $return; } - public static function generateRoomTree($selectedElements, $leafNode, $rootNodeId, $previousElements = false) + /** + * Generate the node data for rooms + */ + protected static function generateRoomNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false) { $return = array(); $rooms = self::getRoomsByRoomTypeId($previousElements, $rootNodeId); @@ -2744,7 +2768,10 @@ class HotelHelper return $return; } - public static function getcategoryByParent($idParents, $levelDepth, $input_name, $rootNodeId) + /** + * Get all the children category of the provided id categories + */ + protected static function getcategoryByParent($idParents, $levelDepth, $input_name, $rootNodeId) { $locationCategory = new Category(Configuration::get('PS_LOCATIONS_CATEGORY')); $sql = 'SELECT c.`id_category` as `value` , cl.`name`, "'.pSQL($input_name).'_box" as `input_name`, c.`id_parent` @@ -2764,7 +2791,10 @@ class HotelHelper return Db::getInstance()->executeS($sql); } - public static function getHotelsByIdCity($cities, $rootNodeId) + /** + * Get all the hotels of the passed cities (city id_category) + */ + protected static function getHotelsByIdCity($cities, $rootNodeId) { $sql = 'SELECT hbi.`id` as `value` , hbil.`hotel_name` as `name`, "hotel_box" as `input_name`, c.`id_parent` @@ -2783,7 +2813,10 @@ class HotelHelper return Db::getInstance()->executeS($sql); } - public static function getRoomTypesByHotelsId($hotels, $rootNodeId) + /** + * Get all the room types of the passed hotels + */ + protected static function getRoomTypesByHotelsId($hotels, $rootNodeId) { $sql = 'SELECT p.`id_product` AS `value`, pl.`name`, "room_type_box" as `input_name`, rt.`id_hotel` FROM `'._DB_PREFIX_.'htl_room_type` AS rt'; @@ -2803,7 +2836,10 @@ class HotelHelper return Db::getInstance()->executeS($sql); } - public static function getRoomsByRoomTypeId($roomTypes, $rootNodeId) + /** + * Get all the rooms of the passed room types (city id_category) + */ + protected static function getRoomsByRoomTypeId($roomTypes, $rootNodeId) { $sql = 'SELECT `id` as `value`, `room_num` as `name`, "room_box" as `input_name`, `id_product` FROM `'._DB_PREFIX_.'htl_room_information`