Hi ecartz
I think i have hte same problem now here, as i have parameter, filters, as a array (filter[]=test) and the sort function in de index.php (sort for name or price) cannot handle this
i think it's this function:
Code: Select all
public function retain_query_except(array $excludes = []) {
$excludes = array_merge($excludes, ['x', 'y', 'error', session_name()]);
$this->parameters += array_diff_key(array_filter($_GET, function ($k) {
return rawurlencode($k) === $k;
}, ARRAY_FILTER_USE_KEY), array_flip($excludes));
return $this;
}
you already told me how to fix the rawurlencode to accept the arrays, do you have a idea how to do it for the sort function, that it accepts them?
(for rawurl we did this in the href.php
Code: Select all
public function build_subquery(array $parameters, string $prefix) {
return implode('&', array_map(function ($k, $v) use ($prefix) {
$k = "{$prefix}[{$k}]";
return is_array($v) ? $this->build_subquery($v, $k) : "$k=" . rawurlencode($v);
}, array_keys($parameters), $parameters));
}
because at the moment I lose every filter as soon as i make a new sort....
one simple idea would maybe be, change the function
public static function create_sort_heading($sortby, $colnum, $heading, $class = 'dropdown-item')
to this, and it will work:
Code: Select all
public static function create_sort_heading($sortby, $colnum, $heading, $class = 'dropdown-item') {
if (!$sortby) {
return $heading;
}
$link = $GLOBALS['Linker']->build()->retain_query_except(['info', 'page']);
$link->set_parameter('sort', $colnum . ($sortby == $colnum . 'a' ? 'd' : 'a'));
$selected = substr($sortby, 0, -1) == $colnum;
$ascending = substr($sortby, -1) === 'a';
$title = sprintf(($selected && $ascending) ? TEXT_DESCENDINGLY : TEXT_ASCENDINGLY, $heading);
$text = sprintf(($selected ? ($ascending ? LISTING_SORT_DOWN : LISTING_SORT_UP) : LISTING_SORT_UNSELECTED), $heading);
return '<a href="' . $_SERVER['PHP_SELF']."?".str_replace("sort=".$sortby, "sort=".$colnum."a", $_SERVER['QUERY_STRING']). '" title="' . Text::output($title) . '" class="' . $class . '">' . $text . '</a>';
}
but maybe there is a more elegant way, it's probably a ugly hack this function