Use new fields list keys

This commit is contained in:
Abhishek Kumar
2024-02-15 20:18:19 +05:30
parent 42f05f6e83
commit 44c0ea95fc
5 changed files with 104 additions and 71 deletions

View File

@@ -22,11 +22,28 @@
{block name='td_content'}
{if isset($tr.$key) && isset($params.position)}
{if $order_by == 'position' && $order_way != 'DESC'}
<div class="dragGroup">
<div class="positions">
{$tr.$key.position + 1}
{assign var=filters_has_value_no_location_hotel value=false}
{foreach $fields_display AS $key => $params}
{if $key != 'id_category_default' && (isset($params['value']) && $params['value'] !== false && $params['value'] !== '')}
{if is_array($params['value']) && trim(implode('', $params['value'])) == ''}
{continue}
{/if}
{assign var=filters_has_value_no_location_hotel value=true}
{break}
{/if}
{/foreach}
{if !$filters_has_value_no_location_hotel}
<div class="dragGroup">
<div class="positions">
{$tr.$key.position + 1}
</div>
</div>
</div>
{else}
{$tr.$key.position + 1}
{/if}
{else}
{$tr.$key.position + 1}
{/if}

View File

@@ -111,32 +111,24 @@
<i class="icon-times"></i>
</span>
{/if}
{else if $params.type == 'select'}
<span data-filter_key="{if isset($params.filter_key)}{$params.filter_key}{else}{$key}{/if}" data-filter_type="{$params.type}">
{$params['title']|escape:'html':'UTF-8'}: <span class="filter_value">{$params['list'][$params['value']]|replace: '&nbsp;' : ''}</span>
<i class="icon-times"></i>
</span>
{else if $params.type == 'select_multiple_and'}
<span data-filter_key="{if isset($params.filter_key)}{$params.filter_key}{else}{$key}{/if}" data-filter_type="{$params.type}">
{$params['title']|escape:'html':'UTF-8'}:
<span class="filter_value">
{foreach from=$params.value item=option name=foreachInfo}
{$params.list[$option]}{if !$smarty.foreach.foreachInfo.last}, {/if}
{/foreach}
{elseif $params.type == 'select'}
{if isset($params.multiple) && $params.multiple}
<span data-filter_key="{if isset($params.filter_key)}{$params.filter_key}{else}{$key}{/if}" data-filter_type="{$params.type}" data-multiple="{$params.multiple|intval}" data-operator="{$params.operator}">
{$params['title']|escape:'html':'UTF-8'}:
<span class="filter_value">
{foreach from=$params.value item=option name=foreachInfo}
{$params.list[$option]}{if !$smarty.foreach.foreachInfo.last}{if $params.operator == 'or'} | {else}, {/if}{/if}
{/foreach}
</span>
<i class="icon-times"></i>
</span>
<i class="icon-times"></i>
</span>
{else if $params.type == 'select_multiple_or'}
<span data-filter_key="{if isset($params.filter_key)}{$params.filter_key}{else}{$key}{/if}" data-filter_type="{$params.type}">
{$params['title']|escape:'html':'UTF-8'}:
<span class="filter_value">
{foreach from=$params.value item=option name=foreachInfo}
{$params.list[$option]}{if !$smarty.foreach.foreachInfo.last} | {/if}
{/foreach}
{else}
<span data-filter_key="{if isset($params.filter_key)}{$params.filter_key}{else}{$key}{/if}" data-filter_type="{$params.type}">
{$params['title']|escape:'html':'UTF-8'}: <span class="filter_value">{$params['list'][$params['value']]|replace: '&nbsp;' : ''}</span>
<i class="icon-times"></i>
</span>
<i class="icon-times"></i>
</span>
{else if $params.type == 'bool' && $key == 'advance_payment'}
{/if}
{elseif $params.type == 'bool' && $key == 'advance_payment'}
<span data-filter_key="{if isset($params.filter_key)}{$params.filter_key}{else}{$key}{/if}" data-filter_type="{$params.type}">
{$params['title']|escape:'html':'UTF-8'}: <span class="filter_value">{if $params['value'] == 1}{l s='Yes'}{elseif $params['value'] == 0}{l s='No'}{/if}</span>
<i class="icon-times"></i>
@@ -245,32 +237,26 @@
</script>
</div>
{elseif $params.type == 'select'}
{if isset($params.filter_key)}
<select id="filter_input_{$key}" class="filter{if isset($params.align) && $params.align == 'center'}center{/if} {if isset($params.class)}{$params.class}{/if}" {if !isset($params.remove_onchange) || !$params.remove_onchange}onchange="$('#submitFilterButton{$list_id}').focus();$('#submitFilterButton{$list_id}').click();"{/if} name="{$list_id}Filter_{$params.filter_key}" {if isset($params.width)} style="width:{$params.width}px"{/if}>
<option value="" {if $params.value == ''} selected="selected" {/if}>-</option>
{if isset($params.multiple) && $params.multiple}
<select id="filter_input_{$key}" class="filter{if isset($params.align) && $params.align == 'center'}center{/if} select_multiple_{$params.operator} chosen chosen-options-horizontal" multiple name="{$list_id}Filter_{$params.filter_key}[]" {if isset($params.width)} style="width:{$params.width}px"{/if}>
{if isset($params.list) && is_array($params.list)}
{foreach $params.list AS $option_value => $option_display}
<option value="{$option_value}" {if (string)$option_display === (string)$params.value || (string)$option_value === (string)$params.value} selected="selected"{/if}>{$option_display}</option>
<option value="{$option_value}" {if isset($params.value) && $params.value}{if in_array($option_value, $params.value)} selected="selected"{/if}{/if}>{$option_display}</option>
{/foreach}
{/if}
</select>
{else}
{if isset($params.filter_key)}
<select id="filter_input_{$key}" class="filter{if isset($params.align) && $params.align == 'center'}center{/if} {if isset($params.class)}{$params.class}{/if}" {if !isset($params.remove_onchange) || !$params.remove_onchange}onchange="$('#submitFilterButton{$list_id}').focus();$('#submitFilterButton{$list_id}').click();"{/if} name="{$list_id}Filter_{$params.filter_key}" {if isset($params.width)} style="width:{$params.width}px"{/if}>
<option value="" {if $params.value == ''} selected="selected" {/if}>-</option>
{if isset($params.list) && is_array($params.list)}
{foreach $params.list AS $option_value => $option_display}
<option value="{$option_value}" {if (string)$option_display === (string)$params.value || (string)$option_value === (string)$params.value} selected="selected"{/if}>{$option_display}</option>
{/foreach}
{/if}
</select>
{/if}
{/if}
{elseif $params.type == 'select_multiple_and'}
<select id="filter_input_{$key}" class="filter{if isset($params.align) && $params.align == 'center'}center{/if} select_multiple_and chosen chosen-options-horizontal" multiple name="{$list_id}Filter_{$params.filter_key}[]" {if isset($params.width)} style="width:{$params.width}px"{/if}>
{if isset($params.list) && is_array($params.list)}
{foreach $params.list AS $option_value => $option_display}
<option value="{$option_value}" {if isset($params.value) && $params.value}{if in_array($option_value, $params.value)} selected="selected"{/if}{/if}>{$option_display}</option>
{/foreach}
{/if}
</select>
{elseif $params.type == 'select_multiple_or'}
<select id="filter_input_{$key}" class="filter{if isset($params.align) && $params.align == 'center'}center{/if} select_multiple_or chosen chosen-options-horizontal" multiple name="{$list_id}Filter_{$params.filter_key}[]" {if isset($params.width)} style="width:{$params.width}px"{/if}>
{if isset($params.list) && is_array($params.list)}
{foreach $params.list AS $option_value => $option_display}
<option value="{$option_value}" {if isset($params.value) && $params.value}{if in_array($option_value, $params.value)} selected="selected"{/if}{/if}>{$option_display}</option>
{/foreach}
{/if}
</select>
{else}
<input type="text" class="filter" name="{$list_id}Filter_{if isset($params.filter_key)}{$params.filter_key}{else}{$key}{/if}" value="{$params.value|escape:'html':'UTF-8'}" {if isset($params.width) && $params.width != 'auto'} style="width:{$params.width}px"{/if} />
{/if}
@@ -312,7 +298,7 @@
$('#list_filters_panel').find('[name*="'+$(this).parent().data('filter_key')+'"]').val('');
} else if (type == 'range') {
$('#list_filters_panel').find('[name*="productFilter_'+$(this).parent().data('filter_key')+'"]').val('');
} else if (type == 'select' || type == 'select_multiple_and' || type == 'select_multiple_or') {
} else if (type == 'select') {
$('#list_filters_panel').find('select[name*="productFilter_'+$(this).parent().data('filter_key')+'"] option:selected').prop('selected', false);
} else if (type == 'bool' && $(this).parent().data('filter_key') == 'advance_payment') {
$('#list_filters_panel').find('select[name*="productFilter_'+$(this).parent().data('filter_key')+'"] option:selected').prop('selected', false);
@@ -329,6 +315,17 @@
form.submit();
});
$('#form-product').submit(function () {
let form = $(this);
$(form).find('select[multiple]').each(function (i, selectElement) {
if ($(selectElement).val() == null) {
$(form).append('<input type="hidden" name="' + $(selectElement).attr('name').slice(0, -2) + '" value="">');
}
});
return true;
});
});
</script>
<style>

View File

@@ -875,7 +875,9 @@ class AdminControllerCore extends Controller
if ($field = $this->filterToField($key, $filter)) {
$type = (array_key_exists('filter_type', $field) ? $field['filter_type'] : (array_key_exists('type', $field) ? $field['type'] : false));
if ((in_array($type, array('date', 'datetime', 'range', 'select_multiple_and', 'select_multiple_or'))) && is_string($value)) {
if ((($type == 'date' || $type == 'datetime' || $type == 'range') || ($type == 'select' && (isset($field['multiple']) && $field['multiple'])))
&& is_string($value)
) {
$value = json_decode($value, true);
}
$key = isset($tmp_tab[1]) ? $tmp_tab[0].'.`'.$tmp_tab[1].'`' : '`'.$tmp_tab[0].'`';
@@ -893,13 +895,15 @@ class AdminControllerCore extends Controller
} else {
$sql_filter = & $this->_filter;
}
/* Only for date filtering (from, to) */
if (is_array($value)) {
if ($type == 'select_multiple_and') {
$sql_filter .= ' AND '.pSQL($key).' IN ('.pSQL(implode(',', $value)).')';
$this->_filterHaving .= ' AND COUNT(DISTINCT '.pSQL($key).') = '.(int) count($value);
} elseif ($type == 'select_multiple_or') {
$sql_filter .= ' AND '.pSQL($key).' IN ('.pSQL(implode(',', $value)).')';
if ($type == 'select' && (isset($field['multiple']) && $field['multiple']) && isset($field['operator'])) {
if ($field['operator'] == 'and') {
$sql_filter .= ' AND '.pSQL($key).' IN ('.pSQL(implode(',', $value)).')';
$this->_filterHaving .= ' AND COUNT(DISTINCT '.pSQL($key).') = '.(int) count($value);
} elseif ($field['operator'] == 'or') {
$sql_filter .= ' AND '.pSQL($key).' IN ('.pSQL(implode(',', $value)).')';
}
} elseif ($type == 'range') {
if (isset($value[0]) && !empty($value[0])) {
if (!Validate::isUnsignedInt($value[0])) {

View File

@@ -672,20 +672,22 @@ class HelperListCore extends Helper
break;
case 'select':
foreach ($params['list'] as $option_value => $option_display) {
if (isset(Context::getContext()->cookie->{$prefix.$this->list_id.'Filter_'.$params['filter_key']})
&& Context::getContext()->cookie->{$prefix.$this->list_id.'Filter_'.$params['filter_key']} == $option_value
&& Context::getContext()->cookie->{$prefix.$this->list_id.'Filter_'.$params['filter_key']} != '') {
$this->fields_list[$key]['select'][$option_value]['selected'] = 'selected';
if (isset($params['multiple']) && $params['multiple']) {
if (!isset($params['operator'])) {
$params['operator'] = 'or';
}
$value = json_decode($value, true);
} else {
foreach ($params['list'] as $option_value => $option_display) {
if (isset(Context::getContext()->cookie->{$prefix.$this->list_id.'Filter_'.$params['filter_key']})
&& Context::getContext()->cookie->{$prefix.$this->list_id.'Filter_'.$params['filter_key']} == $option_value
&& Context::getContext()->cookie->{$prefix.$this->list_id.'Filter_'.$params['filter_key']} != '') {
$this->fields_list[$key]['select'][$option_value]['selected'] = 'selected';
}
}
}
break;
case 'select_multiple_and':
case 'select_multiple_or':
$value = json_decode($value, true);
break;
case 'text':
if (!Validate::isCleanHtml($value)) {
$value = '';

View File

@@ -253,7 +253,9 @@ class AdminProductsControllerCore extends AdminController
$this->fields_list['hotel_name'] = array(
'title' => $this->l('Hotel'),
'type' => 'select_multiple_or',
'type' => 'select',
'multiple' => true,
'operator' => 'or',
'filter_key' => 'hrt!id_hotel',
'list' => $this->hotelsArray,
'optional' => true,
@@ -337,7 +339,9 @@ class AdminProductsControllerCore extends AdminController
$this->fields_list['id_tax_rules_group'] = array(
'title' => $this->l('Tax Rules'),
'align' => 'text-center',
'type' => 'select_multiple_or',
'type' => 'select',
'multiple' => true,
'operator' => 'or',
'filter_key' => 'a!id_tax_rules_group',
'list' => $taxRulesGroups,
'displayed' => false,
@@ -350,7 +354,9 @@ class AdminProductsControllerCore extends AdminController
$this->fields_list['id_feature'] = array(
'title' => $this->l('Features'),
'align' => 'text-center',
'type' => 'select_multiple_and',
'type' => 'select',
'multiple' => true,
'operator' => 'and',
'filter_key' => 'fp!id_feature',
'list' => $features,
'displayed' => false,
@@ -365,7 +371,9 @@ class AdminProductsControllerCore extends AdminController
$this->fields_list['id_service_product'] = array(
'title' => $this->l('Service Products'),
'align' => 'text-center',
'type' => 'select_multiple_and',
'type' => 'select',
'multiple' => true,
'operator' => 'and',
'filter_key' => 'hrtsp!id_product',
'list' => $serviceProducts,
'displayed' => false,
@@ -380,7 +388,9 @@ class AdminProductsControllerCore extends AdminController
$this->fields_list['id_global_demand'] = array(
'title' => $this->l('Additional Facilities'),
'align' => 'text-center',
'type' => 'select_multiple_and',
'type' => 'select',
'multiple' => true,
'operator' => 'and',
'filter_key' => 'hrtd!id_global_demand',
'list' => $additionalFacilities,
'displayed' => false,
@@ -2557,6 +2567,9 @@ class AdminProductsControllerCore extends AdminController
$this->addRowAction('preview');
$this->addRowAction('duplicate');
$this->addRowAction('delete');
$this->tpl_list_vars['title'] = $this->l('Room Types');
return parent::renderList();
}