1 |
18541
|
thanos.pap
|
<?php
|
2 |
|
|
|
3 |
|
|
defined('_JEXEC') or die('Access denied');
|
4 |
|
|
|
5 |
|
|
jimport('joomla.methods');
|
6 |
|
|
|
7 |
|
|
// This helper formats filters.
|
8 |
|
|
abstract class FilterHelper {
|
9 |
|
|
const MAX_ROW = 32;
|
10 |
|
|
|
11 |
|
|
// Format filters.
|
12 |
|
|
// $filters the filters to format
|
13 |
|
|
// $statistics the available statistics
|
14 |
|
|
// $baseUrl the base URL to use for links
|
15 |
|
|
// $fragment the URL fragment to use for links
|
16 |
|
|
// return a string containing the full HTML for the filters or an empty string if any errors occur
|
17 |
|
|
public static function formatFilters($filters, $statistics, $baseUrl, $fragment) {
|
18 |
|
|
$filters = ($filters == NULL) ? NULL : array_filter(array_map(function ($filter) use ($filters, $statistics, $baseUrl, $fragment) {return FilterHelper :: _formatFilter($filter, $statistics, $filters, $baseUrl, $fragment);}, $filters));
|
19 |
30864
|
yannis.str
|
return ($filters == NULL) ? '' : ('<h2>' . JText :: _('CURRENT_SELECTIONS') . '</h2><div class="selectorCollections">' . implode('', $filters) . ((count($filters) > 1) ? ('<div class="flowWrapper"><a href="' . JRoute :: _($baseUrl . $fragment) . '" class="clearFilters" title="' . JText :: _('CLEAR_ALL_FILTERS') . '">' . JText :: _('CLEAR_ALL') . '</a></div>') : '') . '</div>');
|
20 |
18541
|
thanos.pap
|
}
|
21 |
|
|
|
22 |
|
|
public static function _formatFilter($filter, $statistics, $filters, $baseUrl, $fragment) {
|
23 |
|
|
$filterName = $filter -> name;
|
24 |
|
|
$filterValue = ($filter -> value === TRUE) ? 'true' : (($filter -> value === FALSE) ? 'false' : $filter -> value);
|
25 |
|
|
$filters = ($filters == NULL) ? NULL : array_filter(array_map(function ($otherFilter) use ($filterName) {return ($otherFilter -> name == $filterName) ? '' : (urlencode($otherFilter -> name) . '=' . urlencode(($otherFilter -> value === TRUE) ? 'true' : (($otherFilter -> value === FALSE) ? 'false' : $otherFilter -> value)));}, $filters));
|
26 |
|
|
// TODO JRoute :: _ keeps decoding urlencoded values, so this is just a hack to cope with this
|
27 |
30864
|
yannis.str
|
return (($statistics == NULL) || (!array_key_exists($filter -> name, $statistics)) || ($statistics[$filter -> name] -> data == NULL) || (!array_key_exists($filterValue, $statistics[$filter -> name] -> data))) ? '' : '<div class="element"><div class="flowWrapper"><a href="' . JRoute :: _($baseUrl . (($filters == NULL) ? '' : ('&' . implode('&', $filters))) . $fragment) . '"class="selectorRemove" title="' . $statistics[$filter -> name] -> data[$filterValue] -> name . '"><span class="fieldName">' . $statistics[$filter -> name] -> title . ':</span> ' . ((strlen($statistics[$filter -> name] -> data[$filterValue] -> name) > FilterHelper :: MAX_ROW) ? (substr($statistics[$filter -> name] -> data[$filterValue] -> name, 0, FilterHelper :: MAX_ROW - strlen('...')) . '...') : $statistics[$filter -> name] -> data[$filterValue] -> name) . '</a></div></div>';
|
28 |
18541
|
thanos.pap
|
}
|
29 |
|
|
}
|