Merge pull request #1470 from vishal-singh-webkul/gli-tree_optmization

Optimized: The tree creation process from the helper tree, added option to add prefix in hotel helper while generating the tree data.
This commit is contained in:
Rohit Jain
2025-06-12 19:16:10 +05:30
committed by GitHub
4 changed files with 47 additions and 44 deletions

View File

@@ -101,8 +101,8 @@ Tree.prototype =
this.$element.find("li").click(
function ()
{
$('.tree-selected').removeClass("tree-selected");
$('li input:checked').parent().addClass("tree-selected");
$('#'+idTree+' .tree-selected').removeClass("tree-selected");
$('#'+idTree+' li input:checked').parent().addClass("tree-selected");
}
);

View File

@@ -30,7 +30,7 @@
{/block}
{block name="tree"}
{if isset($nodes)}
<ul id="{$id|escape:'html':'UTF-8'}" class="tree top" style="max-height: {$max_height}px;">
<ul id="{$id|escape:'html':'UTF-8'}" class="tree top cattree" style="max-height: {$max_height}px;">
{$nodes}
</ul>
{/if}
@@ -121,20 +121,19 @@
});
{/if}
function startTree() {
function startTree(idElem) {
if (typeof $.fn.tree === 'undefined') {
setTimeout(startTree, 100);
return;
}
var tree = $("#{$id|escape:'html':'UTF-8'}").tree('collapseAll');
if ($("#{$id|escape:'html':'UTF-8'}").find(":input:checked").length > 1)
$('#expand-all-{$id|escape:'html':'UTF-8'}').hide();
let tree = $("#"+idElem).tree('collapseAll');
if ($("#"+idElem).find(":input:checked").length > 1)
$('#expand-all-'+idElem).hide();
else
$('#collapse-all-{$id|escape:'html':'UTF-8'}').hide();
$('#collapse-all-'+idElem).hide();
$("#{$id|escape:'html':'UTF-8'}").find(":input:checked").each(function(){
$("#"+idElem).find(":input:checked").each(function(){
$(this).parent().addClass("tree-selected");
$(this).parents('ul.tree').each(function(){
$(this).show();
@@ -144,7 +143,7 @@
}
$(document).ready(function () {
startTree();
startTree("{$id|escape:'html':'UTF-8'}");
});
{/block}
</script>

View File

@@ -2964,7 +2964,7 @@ class AdminNormalProductsControllerCore extends AdminController
$allAssociations = $objRoomTypeServiceProduct->getAssociatedHotelsAndRoomType($product->id);
if (Product::SELLING_PREFERENCE_WITH_ROOM_TYPE == $product->selling_preference_type) {
$associatedRoomTypes = $allAssociations['room_type'];
$selectedRoomTypes = Tools::getValue('room_type_box', array());
$selectedRoomTypes = Tools::getValue('RT_tree_room_type_box', array());
// Generate list of new associations
$newRoomTypes = array();
@@ -3046,7 +3046,7 @@ class AdminNormalProductsControllerCore extends AdminController
} elseif (Product::SELLING_PREFERENCE_HOTEL_STANDALONE_AND_WITH_ROOM_TYPE == $product->selling_preference_type) {
// Add room types linking
$associatedRoomTypes = $allAssociations['room_type'];
$selectedRoomTypes = Tools::getValue('room_type_box', array());
$selectedRoomTypes = Tools::getValue('RT_tree_room_type_box', array());
// Generate list of new associations
$newRoomTypes = array();
foreach ($selectedRoomTypes as $selectedRoomType) {
@@ -3861,7 +3861,8 @@ class AdminNormalProductsControllerCore extends AdminController
$tree->setData(HotelHelper::generateTreeData([
'rootNode' => HotelHelper::NODE_HOTEL,
'leafNode' => HotelHelper::NODE_ROOM_TYPE,
'selectedElements' => $selectedRoomTypes
'selectedElements' => $selectedRoomTypes,
'prefix' => 'RT_tree_'
]))
->setUseCheckBox(true)
->setAutoSelectChildren(true)

View File

@@ -2774,20 +2774,23 @@ class HotelHelper
if (!isset($rootNodeId)) {
$rootNodeId = false;
}
if (!isset($prefix)) {
$prefix = '';
}
$treeData = array();
if ($rootNode == self::NODE_COUNTRY) {
$treeData = self::generateCountryNodes($rootNodeId, $leafNode, $selectedElements);
$treeData = self::generateCountryNodes($rootNodeId, $leafNode, $selectedElements, false, $prefix);
} else if ($rootNode == self::NODE_STATE) {
$treeData = self::generateStateNodes($rootNodeId, $leafNode, $selectedElements);
$treeData = self::generateStateNodes($rootNodeId, $leafNode, $selectedElements, false, $prefix);
} else if ($rootNode == self::NODE_CITY) {
$treeData = self::generateCityNodes($rootNodeId, $leafNode, $selectedElements);
$treeData = self::generateCityNodes($rootNodeId, $leafNode, $selectedElements, false, $prefix);
} else if ($rootNode == self::NODE_HOTEL) {
$treeData = self::generateHotelNodes($rootNodeId, $leafNode, $selectedElements);
$treeData = self::generateHotelNodes($rootNodeId, $leafNode, $selectedElements, false, $prefix);
} else if ($rootNode == self::NODE_ROOM_TYPE) {
$treeData = self::generateRoomTypeNodes($rootNodeId, $leafNode, $selectedElements);
$treeData = self::generateRoomTypeNodes($rootNodeId, $leafNode, $selectedElements, false, $prefix);
} else if ($rootNode == self::NODE_ROOM) {
$treeData = self::generateRoomNodes($rootNodeId, $leafNode, $selectedElements);
$treeData = self::generateRoomNodes($rootNodeId, $leafNode, $selectedElements, false, $prefix);
}
return $treeData;
@@ -2796,18 +2799,18 @@ class HotelHelper
/**
* Generate the node data for country
*/
protected static function generateCountryNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false)
protected static function generateCountryNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false, $prefix = '')
{
$return = array();
$countries = self::getcategoryByParent($previousElements, 3, 'country', $rootNodeId);
$countries = self::getcategoryByParent($previousElements, 3, $prefix.'country', $rootNodeId);
$countriesIds = array_column($countries, 'value');
if ($leafNode > self::NODE_COUNTRY) {
$states = self::generateStateNodes(false, $leafNode, $selectedElements, $countriesIds);
$states = self::generateStateNodes(false, $leafNode, $selectedElements, $countriesIds, $prefix);
}
foreach ($countries as $country) {
if (isset($selectedElements['state']) && in_array($country['value'], $selectedElements['state'])) {
if (isset($selectedElements['country']) && in_array($country['value'], $selectedElements['country'])) {
$country['selected'] = true;
}
@@ -2828,14 +2831,14 @@ class HotelHelper
/**
* Generate the node data for state
*/
protected static function generateStateNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false)
protected static function generateStateNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false, $prefix = '')
{
$return = array();
$states = self::getcategoryByParent($previousElements, 4, 'state', $rootNodeId);
$states = self::getcategoryByParent($previousElements, 4, $prefix.'state', $rootNodeId);
$stateIds = array_column($states, 'value');
if ($leafNode > self::NODE_STATE) {
$cities = self::generateCityNodes(false, $leafNode, $selectedElements, $stateIds);
$cities = self::generateCityNodes(false, $leafNode, $selectedElements, $stateIds, $prefix);
}
foreach ($states as $state) {
@@ -2860,14 +2863,14 @@ class HotelHelper
/**
* Generate the node data for city
*/
protected static function generateCityNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false)
protected static function generateCityNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false, $prefix = '')
{
$return = array();
$cities = self::getcategoryByParent($previousElements, 5, 'city', $rootNodeId);
$cities = self::getcategoryByParent($previousElements, 5, $prefix.'city', $rootNodeId);
$cityIds = array_column($cities, 'value');
if ($leafNode > self::NODE_CITY) {
$hotels = self::generateHotelNodes(false, $leafNode, $selectedElements, $cityIds);
$hotels = self::generateHotelNodes(false, $leafNode, $selectedElements, $cityIds, $prefix);
}
foreach ($cities as $city) {
@@ -2892,10 +2895,10 @@ class HotelHelper
/**
* Generate the node data for hotels
*/
protected static function generateHotelNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false)
protected static function generateHotelNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false, $prefix = '')
{
$return = array();
$hotels = self::getHotelsByIdCity($previousElements, $rootNodeId);
$hotels = self::getHotelsByIdCity($previousElements, $rootNodeId, $prefix);
$hotelIds = array_column($hotels, 'value');
if (Validate::isLoadedObject(Context::getContext()->employee)){
@@ -2905,7 +2908,7 @@ class HotelHelper
}
if ($leafNode > self::NODE_HOTEL) {
$roomTypes = self::generateRoomTypeNodes(false, $leafNode, $selectedElements, $hotelIds);
$roomTypes = self::generateRoomTypeNodes(false, $leafNode, $selectedElements, $hotelIds, $prefix);
}
foreach ($hotels as $hotel) {
@@ -2934,10 +2937,10 @@ class HotelHelper
/**
* Generate the node data for room types
*/
protected static function generateRoomTypeNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false)
protected static function generateRoomTypeNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false, $prefix = '')
{
$return = array();
$roomTypes = self::getRoomTypesByHotelsId($previousElements, $rootNodeId);
$roomTypes = self::getRoomTypesByHotelsId($previousElements, $rootNodeId, $prefix);
$roomTypeIds = array_column($roomTypes, 'value');
if (Validate::isLoadedObject(Context::getContext()->employee)){
@@ -2953,7 +2956,7 @@ class HotelHelper
}
if ($leafNode > self::NODE_ROOM_TYPE) {
$rooms = self::generateRoomNodes(false, $leafNode, $selectedElements, $roomTypeIds);
$rooms = self::generateRoomNodes(false, $leafNode, $selectedElements, $roomTypeIds, $prefix);
}
foreach ($roomTypes as $roomType) {
@@ -2982,10 +2985,10 @@ class HotelHelper
/**
* Generate the node data for rooms
*/
protected static function generateRoomNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false)
protected static function generateRoomNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false, $prefix = '')
{
$return = array();
$rooms = self::getRoomsByRoomTypeId($previousElements, $rootNodeId);
$rooms = self::getRoomsByRoomTypeId($previousElements, $rootNodeId, $prefix);
if (Validate::isLoadedObject(Context::getContext()->employee)){
if (!Context::getContext()->employee->isSuperAdmin()) {
$rooms = HotelBranchInformation::filterDataByHotelAccess(
@@ -3043,10 +3046,10 @@ class HotelHelper
/**
* Get all the hotels of the passed cities (city id_category)
*/
protected static function getHotelsByIdCity($cities, $rootNodeId)
protected static function getHotelsByIdCity($cities, $rootNodeId, $prefix = '')
{
$sql = 'SELECT hbi.`id` as `value` , hbil.`hotel_name` as `name`, "hotel_box" as `input_name`, c.`id_parent`
$sql = 'SELECT hbi.`id` as `value` , hbil.`hotel_name` as `name`, "'.$prefix.'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.')
@@ -3065,9 +3068,9 @@ class HotelHelper
/**
* Get all the room types of the passed hotels
*/
protected static function getRoomTypesByHotelsId($hotels, $rootNodeId)
protected static function getRoomTypesByHotelsId($hotels, $rootNodeId, $prefix = '')
{
$sql = 'SELECT p.`id_product` AS `value`, pl.`name`, "room_type_box" as `input_name`, rt.`id_hotel`
$sql = 'SELECT p.`id_product` AS `value`, pl.`name`, "'.$prefix.'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`)
@@ -3088,9 +3091,9 @@ class HotelHelper
/**
* Get all the rooms of the passed room types (city id_category)
*/
protected static function getRoomsByRoomTypeId($roomTypes, $rootNodeId)
protected static function getRoomsByRoomTypeId($roomTypes, $rootNodeId, $prefix = '')
{
$sql = 'SELECT `id` as `value`, `room_num` as `name`, "room_box" as `input_name`, `id_product`
$sql = 'SELECT `id` as `value`, `room_num` as `name`, "'.$prefix.'room_box" as `input_name`, `id_product`
FROM `'._DB_PREFIX_.'htl_room_information`
WHERE 1';
if ($roomTypes) {