Skip to content

Instantly share code, notes, and snippets.

@OlegShchavelev
Last active November 18, 2020 12:37
Show Gist options
  • Save OlegShchavelev/e106121906d4e614e873dfe142e21e8a to your computer and use it in GitHub Desktop.
Save OlegShchavelev/e106121906d4e614e873dfe142e21e8a to your computer and use it in GitHub Desktop.
Вызов фильтра Newport - кейс ключ в переменной $filter с постфиксом default чанк $scriptProperties['tplFilter.outer.'
{'!msPCS' | snippet : [
'snippet' => 'mFilter2',
'up' => 1,
'mode' => 2,
'limit' => 32,
'parents' => $dsmc_parent ?: 'id' | resource,
'element' => 'msProducts',
'class' => 'msProduct',
'prepareSnippet' => 'prepareProducts',
'includeThumbs' => 'medium',
'tplOuter' => 'dsmc.tpl.mFilter2.outer',
'tpl' => 'dsmc.tpl.msProducts.row',
'tplPlaceholders' => [
'class' => 'col-12 col-mm-6 col-hd-2 col-xl-3 col-sm-4 col-6'
],
'optionFilters' => $dsmc_option ?: [],
'tplFilter.outer.default' => 'dsmc.tpl.mFilter2.filter.outer',
'tplFilter.row.default' => 'dsmc.tpl.mFilter2.filter.checkbox',
'tplPageWrapper' => '@INLINE <div class="pagination mse2_pagination"><ul class="pagination">{$prev}{$pages}{$next}</ul></div>',
'tplPagePrev' => '@INLINE
<li class="page-item">
<a class="page-arrow" href="{$href}">
<span aria-hidden="true">
<svg class="svg-icon page-icon">
<use xlink:href="#angle-left-1"> </use>
</svg>
</span>
</a>
</li>',
'tplPageNext' => '@INLINE
<li class="page-item">
<a class="page-arrow" href="{$href}">
<span aria-hidden="true">
<svg class="svg-icon page-icon">
<use xlink:href="#angle-right-1"> </use>
</svg>
</span>
</a>
</li>',
'tplPage' => '@INLINE <li class="page-item"><a class="page-link" href="{$href}">{$pageNo}</a></li>',
'tplPagePrevEmpty' => '@INLINE
<li class="page-item">
<a class="page-arrow" href="{$href}">
<span aria-hidden="true">
<svg class="svg-icon page-icon">
<use xlink:href="#angle-left-1"> </use>
</svg>
</span>
</a>
</li>
',
'tplPageNextEmpty' => '@INLINE
<li class="page-item">
<a class="page-arrow" href="{$href}">
<span aria-hidden="true">
<svg class="svg-icon page-icon">
<use xlink:href="#angle-right-1"> </use>
</svg>
</span>
</a>
</li>
'
]}
$aliases = $mSearch2->aliases;
foreach ($filters as $filter => $data) {
if (empty($data) || !is_array($data)) {
continue;
}
$rows = $has_active = '';
list($table, $method) = explode($mSearch2->config['filter_delimeter'], $filter);
$filter_key = !empty($aliases[$filter])
? $aliases[$filter]
: $filter;
$tplOuter = !empty($scriptProperties['tplFilter.outer.' . $filter_key])
? $scriptProperties['tplFilter.outer.' . $filter_key]
: $scriptProperties['tplFilter.outer.default'];
$tplRow = !empty($scriptProperties['tplFilter.row.' . $filter_key])
? $scriptProperties['tplFilter.row.' . $filter_key]
: $scriptProperties['tplFilter.row.default'];
$tplEmpty = !empty($scriptProperties['tplFilter.empty.' . $filter_key])
? $scriptProperties['tplFilter.empty.' . $filter_key]
: '';
$idx = 0;
foreach ($data as $v) {
if (empty($v)) {continue;}
$checked = isset($request[$filter_key]) && in_array((string)$v['value'], $request[$filter_key], true) && isset($v['type']) && $v['type'] != 'number';
if ($scriptProperties['suggestions']) {
if ($checked) {
$num = '';
$has_active = 'has_active';
}
elseif (isset($suggestions[$filter_key][$v['value']])) {
$num = $suggestions[$filter_key][$v['value']];
}
else {
$num = !empty($v['resources'])
? count($v['resources'])
: '';
}
}
else {
$num = '';
}
$current_value = 0;
if (in_array($v['type'], array('number', 'decimal')) && isset($suggestions[$filter_key])) {
$tmp = $suggestions[$filter_key];
array_walk($tmp, function($v, $k) use (&$tmp) {
if (empty($v)) {
unset($tmp[$k]);
}
});
$tmp = array_keys($tmp);
if ($v['type'] == 'number') {
$current_value = ($idx == 0)
? floor(min($tmp))
: ceil(max($tmp));
} else {
$current_value = ($idx == 0)
? min($tmp)
: max($tmp);
}
}
$rows .= $mSearch2->pdoTools->getChunk($tplRow, array(
'filter' => $method,
'table' => $table,
'title' => $v['title'],
'value' => $v['value'],
'current_value' => $current_value,
'type' => $v['type'],
'checked' => $checked
? 'checked'
: '',
'selected' => $checked
? 'selected'
: '',
'disabled' => !$checked && empty($num) && $scriptProperties['suggestions']
? 'disabled'
: '',
'delimeter' => $mSearch2->config['filter_delimeter'],
'idx' => $idx++,
'num' => $num,
'filter_key' => $filter_key,
), $fastMode);
}
$tpl = empty($rows) ? $tplEmpty : $tplOuter;
if (!isset($output['filters'][$filter])) {
$output['filters'][$filter] = '';
}
$output['filters'][$filter] = $mSearch2->pdoTools->getChunk($tpl, array(
'filter' => $method,
'table' => $table,
'rows' => $rows,
'has_active' => $has_active,
'delimeter' => $mSearch2->config['filter_delimeter'],
'filter_key' => $filter_key,
), $fastMode);
}
// Duplicates
if (isset($filters[$table][$name])) {
$old_filter = $built[$table . $this->config['filter_delimeter'] . $name];
$new_name = $name . '-' . $old_filter;
$built[$table . $this->config['filter_delimeter'] . $new_name] = $old_filter;
$filters[$table][$new_name] = $filters[$table][$name];
$duplicates[$table][$new_name] = $name;
$new_name = $name . '-' . $filter;
$duplicates[$table][$new_name] = $name;
$name = $new_name;
}
$filters[$table][$name] = array();
$built[$table . $this->config['filter_delimeter'] . $name] = $filter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment