Merge pull request #1174 from shreesh-webkul/tree-update

Updated: Helper tree | Created a new helper tree class for generating tree
This commit is contained in:
Rohit Jain
2024-08-22 20:08:30 +05:30
committed by GitHub
27 changed files with 717 additions and 988 deletions

View File

@@ -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,14 @@
&:hover
color: #ccc
background-color: none
.node-hint
font-style: italic
color: #959595
margin-left: 30px
margin-top: -4px
margin-bottom: 4px
.badge
margin-left: 5px
.tree-actions
display: inline-block

View File

@@ -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 <support@webkul.com>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*}
{extends file="helpers/tree/tree.tpl"}
<script>
{block name="script" append}
$(document).ready(function () {
$('#{$id|escape:'html':'UTF-8'}').find('[name="hotel_box[]"]').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');
});
}
});
});
{/block}
</script>

View File

@@ -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 <contact@prestashop.com>
* @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
*}
<div class="panel">
{if isset($header)}{$header}{/if}
{if isset($nodes)}
<ul id="{$id|escape:'html':'UTF-8'}" class="cattree tree">
{$nodes}
</ul>
{/if}
</div>
<script type="text/javascript">
var currentToken="{$token|@addslashes}";
var treeClickFunc = function() {
var newURL = window.location.protocol + "//" + window.location.host + window.location.pathname;
var queryString = window.location.search.replace(/&id_category=[0-9]*/, "") + "&id_category=" + $(this).val();
location.href = newURL+queryString; // hash part is dropped: window.location.hash
};
function addDefaultCategory(elem)
{
$('select#id_category_default').append('<option value="' + elem.val()+'">' + (elem.val() !=1 ? elem.parent().find('label').html() : home) + '</option>');
if ($('select#id_category_default option').length > 0)
{
$('select#id_category_default').closest('.form-group').show();
$('#no_default_category').hide();
}
}
{if isset($use_checkbox) && $use_checkbox == true}
function checkAllAssociatedHotels($tree)
{
$tree.find(':input[type=checkbox]').each(function(){
$(this).prop('checked', true);
$(this).parent().addClass('tree-selected');
});
}
function uncheckAllAssociatedHotels($tree)
{
$tree.find(':input[type=checkbox]').each(function(){
$(this).prop('checked', false);
$(this).parent().removeClass('tree-selected');
});
}
function checkAllRoomTypeOfHotel(node)
{
$(node).find(':input[type=checkbox]').each(function(){
$(this).prop('checked', true);
$(this).parent().addClass('tree-selected');
});
}
function unCheckAllRoomTypeOfHotel(node)
{
$(node).find(':input[type=checkbox]').each(function(){
$(this).prop('checked', false);
$(this).parent().removeClass('tree-selected');
});
}
{/if}
$('#{$id|escape:'html':'UTF-8'}').find('.select_hotel').on('click', function(){
if ($(this).is(":checked")) {
checkAllRoomTypeOfHotel($(this).closest('li.tree-folder').find('ul.tree'));
} else {
unCheckAllRoomTypeOfHotel($(this).closest('li.tree-folder').find('ul.tree'));
}
});
$('#{$id|escape:'html':'UTF-8'}').find(':input[type=checkbox].select_room_type').on('change', function(){
var totalNodes = $(this).closest('ul.tree').find('li.tree-item');
var checkedNodes = $(this).closest('ul.tree').find('li.tree-item :input[type=checkbox].select_room_type:checked');
if (totalNodes.length == checkedNodes.length) {
$(this).closest('li.tree-folder').find(':input[type=checkbox].select_hotel').prop('checked', true).parent().addClass('tree-selected');
} else {
$(this).closest('li.tree-folder').find(':input[type=checkbox].select_hotel').prop('checked', false).parent().removeClass('tree-selected');
}
});
{if isset($use_search) && $use_search == true}
$('#{$id|escape:'html':'UTF-8'}-categories-search').bind('typeahead:selected', function(obj, datum){
var match = $('#{$id|escape:'html':'UTF-8'}').find(':input[value="'+datum.id_category+'"]').first();
if (match.length)
{
match.each(function(){
$(this).prop("checked", true);
$(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');
});
addDefaultCategory($(this));
}
);
}
else
{
var selected = [];
that = this;
$('#{$id|escape:'html':'UTF-8'}').find('.tree-selected input').each(
function()
{
selected.push($(this).val());
}
);
{literal}
$.get(
'ajax-tab.php',
{controller:'AdminNormalProducts',token:currentToken,action:'getCategoryTree', fullTree:1, selected:selected},
function(content) {
{/literal}
$('#{$id|escape:'html':'UTF-8'}').html(content);
$('#{$id|escape:'html':'UTF-8'}').tree('init');
$('#{$id|escape:'html':'UTF-8'}').find(':input[value="'+datum.id_category+'"]').each(function(){
$(this).prop("checked", true);
$(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');
});
full_loaded = true;
}
);
}
);
}
});
{/if}
function startTree() {
if (typeof $.fn.tree === 'undefined') {
setTimeout(startTree, 100);
return;
}
$('#{$id|escape:'html':'UTF-8'}').tree('expandAll');
$('#expand-all-{$id|escape:'html':'UTF-8'}').hide();
$('#{$id|escape:'html':'UTF-8'}').find(':input[type=radio]').click(treeClickFunc);
{if isset($selected_hotels)}
$('#no_default_category').hide();
{assign var=imploded_selected_hotels value='","'|implode:$selected_hotels}
var selected_hotels = new Array("{$imploded_selected_hotels}");
$('#{$id|escape:'html':'UTF-8'}').find(':input.select_hotel').each(function(){
if ($.inArray($(this).val(), selected_hotels) != -1)
{
$(this).prop("checked", true);
$(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');
});
}
});
{/if}
{if isset($selected_roomtypes)}
$('#no_default_category').hide();
{assign var=imploded_selected_hotels value='","'|implode:$selected_roomtypes}
var selected_roomtypes = new Array("{$imploded_selected_hotels}");
$('#{$id|escape:'html':'UTF-8'}').find(':input.select_room_type').each(function(){
if ($.inArray($(this).val(), selected_roomtypes) != -1)
{
$(this).prop("checked", true);
$(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');
});
}
});
{/if}
}
startTree();
</script>

View File

@@ -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 <contact@prestashop.com>
* @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
*}
<div class="tree-actions pull-right">
{if isset($actions)}
{foreach from=$actions item=action}
{$action->render()}
{/foreach}
{/if}
</div>

View File

@@ -234,13 +234,13 @@
</div>
<div class="form-group" id="associated_hotel_rooms_tree" {if $product->service_product_type == Product::SERVICE_PRODUCT_WITHOUT_ROOMTYPE}style="display:none;"{/if}>
<div class="col-lg-1"><span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="category_box" type="category_box"}</span></div>
<label class="control-label col-lg-2" for="category_block">
<label class="control-label col-lg-2" for="hotel_block">
<span class="label-tooltip" data-toggle="tooltip" title="{l s='Select room type and hotels for which this service will be available.'}">
{l s='Associated Hotels and Room Types'}
</span>
</label>
<div class="col-lg-9">
<div id="category_block">
<div id="hotel_block">
{$hotel_tree}
</div>
</div>

View File

@@ -22,11 +22,84 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<div class="panel">
{if isset($header)}{$header}{/if}
{if isset($nodes)}
<ul id="{$id|escape:'html':'UTF-8'}" class="tree">
{$nodes}
</ul>
{/if}
</div>
{block name="tree_panel"}
<div class="panel">
{block name="tree_header"}
{if isset($header)}{$header}{/if}
{/block}
{block name="tree"}
{if isset($nodes)}
<ul id="{$id|escape:'html':'UTF-8'}" class="tree top" style="max-height: {$max_height}px;">
{$nodes}
</ul>
{/if}
{/block}
</div>
{/block}
<script type="text/javascript">
{block name="script"}
{if isset($use_checkbox) && $use_checkbox == true}
function checkAll($tree)
{
$tree.find(":input[type=checkbox]").each(
function()
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
}
);
}
function uncheckAll($tree)
{
$tree.find(":input[type=checkbox]").each(
function()
{
$(this).prop("checked", false);
$(this).parent().removeClass("tree-selected");
}
);
}
{/if}
{if isset($use_search) && $use_search == true}
$("#{$id|escape:'html':'UTF-8'}-search").bind("typeahead:selected", function(obj, datum) {
$("#{$id|escape:'html':'UTF-8'}").find(":input").each(
function()
{
if ($(this).val() == datum.value)
{
{if (!(isset($use_checkbox) && $use_checkbox == true))}
$("#{$id|escape:'html':'UTF-8'} label").removeClass("tree-selected");
{/if}
$(this).prop("checked", true);
$(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');
});
}
}
);
});
{/if}
$(document).ready(function () {
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();
else
$('#collapse-all-{$id|escape:'html':'UTF-8'}').hide();
$("#{$id|escape:'html':'UTF-8'}").find(":input:checked").each(function(){
$(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');
});
});
});
{/block}
</script>

View File

@@ -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');
});
}
}

View File

@@ -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 <contact@prestashop.com>
* @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
*}
<div class="panel">
{if isset($header)}{$header}{/if}
{if isset($nodes)}
<ul id="{$id|escape:'html':'UTF-8'}" class="cattree tree">
{$nodes}
</ul>
{/if}
</div>
<script type="text/javascript">
var currentToken="{$token|@addslashes}";
{if isset($use_checkbox) && $use_checkbox == true}
function checkAllAssociatedCategories($tree)
{
$tree.find(":input[type=checkbox]").each(
function()
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
}
);
}
function uncheckAllAssociatedCategories($tree)
{
$tree.find(":input[type=checkbox]").each(
function()
{
$(this).prop("checked", false);
$(this).parent().removeClass("tree-selected");
}
);
}
{/if}
{if isset($use_search) && $use_search == true}
$("#{$id|escape:'html':'UTF-8'}-categories-search").bind("typeahead:selected", function(obj, datum) {
$("#{$id|escape:'html':'UTF-8'}").find(":input").each(
function()
{
if ($(this).val() == datum.id_category)
{
{if (!(isset($use_checkbox) && $use_checkbox == true))}
$("#{$id|escape:'html':'UTF-8'} label").removeClass("tree-selected");
{/if}
$(this).prop("checked", true);
$(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');
});
}
}
);
});
{/if}
$(document).ready(function () {
$("#{$id|escape:'html':'UTF-8'}").tree("collapseAll");
{if isset($selected_categories)}
{assign var=imploded_selected_categories value='","'|implode:$selected_categories}
var selected_categories = new Array("{$imploded_selected_categories}");
$("#{$id|escape:'html':'UTF-8'}").find(":input").each(
function()
{
if ($.inArray($(this).val(), selected_categories) != -1)
{
$(this).prop("checked", true);
$(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');
});
}
}
);
{/if}
});
</script>

View File

@@ -27,6 +27,12 @@
<i class="icon-folder-close"></i>
<label class="tree-toggler">{$node['name']|escape:'html':'UTF-8'}</label>
</span>
{if isset($node['badge'])}
<span class="badge {if isset($node['badge']['class'])}{$node['badge']['class']}{/if}">{$node['badge']['title']}</span>
{/if}
{if isset($node['hint'])}
<div class="node-hint">{$node['hint']}</div>
{/if}
<ul class="tree">
{$children|escape:'UTF-8'}
</ul>

View File

@@ -24,12 +24,18 @@
*}
<li class="tree-folder">
<span class="tree-folder-name{if isset($node['disabled']) && $node['disabled'] == true} tree-folder-name-disable{/if}">
{if isset($node['id_category']) && $node['id_category'] != $root_category}
<input type="checkbox" name="{$input_name}[]" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
{if !isset($selectable) || $selectable}
<input type="checkbox" name="{$node['input_name']}[]" value="{$node['value']}"{if isset($node['selected']) && $node['selected'] == true} checked="checked"{/if}{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
{/if}
<i class="icon-folder-close"></i>
<label class="tree-toggler">{if isset($node['name'])}{$node['name']|escape:'html':'UTF-8'}{/if}{if isset($node['selected_childs']) && (int)$node['selected_childs'] > 0} {l s='(%s selected)' sprintf=$node['selected_childs']}{/if}</label>
</span>
{if isset($node['badge'])}
<span class="badge {if isset($node['badge']['class'])}{$node['badge']['class']}{/if}">{$node['badge']['title']}</span>
{/if}
{if isset($node['hint'])}
<div class="node-hint">{$node['hint']}</div>
{/if}
<ul class="tree">
{$children|escape:'UTF-8'}
</ul>

View File

@@ -24,12 +24,18 @@
*}
<li class="tree-folder">
<span class="tree-folder-name{if isset($node['disabled']) && $node['disabled'] == true} tree-folder-name-disable{/if}">
{if $node['id_category'] != $root_category}
<input type="radio" name="{$input_name}" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
{if !isset($selectable) || $selectable}
<input type="radio" name="{$node['input_name']}" value="{$node['value']}"{if isset($node['selected']) && $node['selected'] == true} checked="checked"{/if}{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
{/if}
<i class="icon-folder-close"></i>
<label class="tree-toggler">{$node['name']|escape:'html':'UTF-8'}</label>
</span>
{if isset($node['badge'])}
<span class="badge {if isset($node['badge']['class'])}{$node['badge']['class']}{/if}">{$node['badge']['title']}</span>
{/if}
{if isset($node['hint'])}
<div class="node-hint">{$node['hint']}</div>
{/if}
<ul class="tree">
{$children}
</ul>

View File

@@ -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 <contact@prestashop.com>
* @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
*}
<li class="tree-folder">
<span class="tree-folder-name{if isset($node['disabled']) && $node['disabled'] == true} tree-folder-name-disable{/if}">
{if isset($node['id_hotel'])}
<input type="checkbox" class="select_hotel" name="{$input_name}[]" value="{$node['id_hotel']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
{* {if isset($node['id_category']) && $node['id_category'] != $root_category} *}
{/if}
<i class="icon-folder-close"></i>
<label class="tree-toggler">{if isset($node['name'])}{$node['name']|escape:'html':'UTF-8'}{/if}{if isset($node['selected_childs']) && (int)$node['selected_childs'] > 0} {l s='(%s selected)' sprintf=$node['selected_childs']}{/if}</label>
</span>
<ul class="tree">
{$children|escape:'UTF-8'}
</ul>
</li>

View File

@@ -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 <contact@prestashop.com>
* @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
*}
<li class="tree-item{if isset($node['disabled']) && $node['disabled'] == true} tree-item-disable{/if}">
<span class="tree-item-name{if isset($node['disabled']) && $node['disabled'] == true} tree-item-name-disable{/if}">
<input type="checkbox" class="select_room_type" name="{$input_name}[]" value="{$node['id_product']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<i class="tree-dot"></i>
<label class="tree-toggler">{$node['room_type']}</label>
</span>
</li>

View File

@@ -28,4 +28,10 @@
<i class="tree-dot"></i>
<label class="tree-toggler">{$node['name']}</label>
</span>
{if isset($node['badge'])}
<span class="badge {if isset($node['badge']['class'])}{$node['badge']['class']}{/if}">{$node['badge']['title']}</span>
{/if}
{if isset($node['hint'])}
<div class="node-hint">{$node['hint']}</div>
{/if}
</li>

View File

@@ -24,8 +24,14 @@
*}
<li class="tree-item{if isset($node['disabled']) && $node['disabled'] == true} tree-item-disable{/if}">
<span class="tree-item-name{if isset($node['disabled']) && $node['disabled'] == true} tree-item-name-disable{/if}">
<input type="checkbox" name="{$input_name}[]" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<input type="checkbox" name="{$node['input_name']}[]" value="{$node['value']}"{if isset($node['selected']) && $node['selected'] == true} checked="checked"{/if}{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<i class="tree-dot"></i>
<label class="tree-toggler">{$node['name']}</label>
</span>
</li>
{if isset($node['badge'])}
<span class="badge {if isset($node['badge']['class'])}{$node['badge']['class']}{/if}">{$node['badge']['title']}</span>
{/if}
{if isset($node['hint'])}
<div class="node-hint">{$node['hint']}</div>
{/if}
</li>

View File

@@ -24,8 +24,14 @@
*}
<li class="tree-item{if isset($node['disabled']) && $node['disabled'] == true} tree-item-disable{/if}">
<span class="tree-item-name">
<input type="radio" name="{$input_name}" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<input type="radio" name="{$node['input_name']}" value="{$node['value']}"{if isset($node['selected']) && $node['selected'] == true} checked="checked"{/if}{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
<i class="tree-dot"></i>
<label class="tree-toggler">{$node['name']}</label>
</span>
{if isset($node['badge'])}
<span class="badge {if isset($node['badge']['class'])}{$node['badge']['class']}{/if}">{$node['badge']['title']}</span>
{/if}
{if isset($node['hint'])}
<div class="node-hint">{$node['hint']}</div>
{/if}
</li>

View File

@@ -0,0 +1,146 @@
<?php
/**
* 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 <support@webkul.com>
* @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;
private $_max_height = 350;
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 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);
}
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(
$this->getId().' search',
$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);
}
$this->setAttribute('max_height', $this->maxHeight());
$this->setAttribute('root_selectable', $this->rootElementSelectable());
return parent::render($data);
}
}

View File

@@ -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;
@@ -430,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();
@@ -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();
}

View File

@@ -1,485 +0,0 @@
<?php
/*
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to 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 <contact@prestashop.com>
* @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;
}
}

View File

@@ -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)) {
@@ -153,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();

View File

@@ -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;
@@ -191,7 +193,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 +219,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 +234,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 +249,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 +273,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;
@@ -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();
}
}

View File

@@ -2875,9 +2875,9 @@ 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');
$selectedRoomTypes = Tools::getValue('room_type_box');
// Generate list of new associations
$newRoomTypes = array();
@@ -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

View File

@@ -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(

View File

@@ -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;

View File

@@ -2521,4 +2521,336 @@ 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 $rootNode = 'country'
* @param $leafNode = 'room'
* @param $rootNodeId int|array
* @param $selectedElements 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)
{
extract($params);
if (!isset($rootNode)) {
$rootNode = self::NODE_COUNTRY;
}
if (!isset($leafNode)) {
$leafNode = self::NODE_ROOM;
}
if (!isset($selectedElements)) {
$selectedElements = array();
}
if (!isset($rootNodeId)) {
$rootNodeId = false;
}
$treeData = array();
if ($rootNode == self::NODE_COUNTRY) {
$treeData = self::generateCountryNodes($rootNodeId, $leafNode, $selectedElements);
} else if ($rootNode == self::NODE_STATE) {
$treeData = self::generateStateNodes($rootNodeId, $leafNode, $selectedElements);
} else if ($rootNode == self::NODE_CITY) {
$treeData = self::generateCityNodes($rootNodeId, $leafNode, $selectedElements);
} else if ($rootNode == self::NODE_HOTEL) {
$treeData = self::generateHotelNodes($rootNodeId, $leafNode, $selectedElements);
} else if ($rootNode == self::NODE_ROOM_TYPE) {
$treeData = self::generateRoomTypeNodes($rootNodeId, $leafNode, $selectedElements);
} else if ($rootNode == self::NODE_ROOM) {
$treeData = self::generateRoomNodes($rootNodeId, $leafNode, $selectedElements);
}
return $treeData;
}
/**
* Generate the node data for country
*/
protected static function generateCountryNodes($rootNodeId, $leafNode, $selectedElements, $previousElements = false)
{
$return = array();
$countries = self::getcategoryByParent($previousElements, 3, 'country', $rootNodeId);
$countriesIds = array_column($countries, 'value');
if ($leafNode > self::NODE_COUNTRY) {
$states = self::generateStateNodes(false, $leafNode, $selectedElements, $countriesIds);
}
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;
}
/**
* 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::generateCityNodes(false, $leafNode, $selectedElements, $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;
}
/**
* 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::generateHotelNodes(false, $leafNode, $selectedElements, $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;
}
/**
* 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::generateRoomTypeNodes(false, $leafNode, $selectedElements, $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;
}
/**
* 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::generateRoomNodes(false, $leafNode, $selectedElements, $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']];
}
$roomType['hint'] = 'This is Room type hint';
$roomType['badge'] = array(
'class' => 'badge-danger',
'title' => 'Disabled'
);
if ($previousElements) {
$return[$roomType['id_hotel']][] = $roomType;
} else {
$return[] = $roomType;
}
}
return $return;
}
/**
* Generate the node data for rooms
*/
protected static function generateRoomNodes($rootNodeId, $leafNode, $selectedElements, $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;
}
/**
* 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`
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 ($idParents) {
$sql .= ' AND c.`id_parent` IN ('.implode(', ', $idParents).')';
}
if ($rootNodeId) {
$sql .= ' AND c.`id_category` = '.(int)$rootNodeId;
}
return Db::getInstance()->executeS($sql);
}
/**
* 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`
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);
}
/**
* 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';
$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);
}
/**
* 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`
WHERE 1';
if ($roomTypes) {
$sql .= ' AND `id_product` IN ('.implode(', ', $roomTypes).')';
}
if ($rootNodeId) {
$sql .= ' AND `id` = '.(int)$rootNodeId;
}
return Db::getInstance()->executeS($sql);
}
}

View File

@@ -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;