1 |
18541
|
thanos.pap
|
<?php
|
2 |
|
|
|
3 |
|
|
defined('_JEXEC') or die('Access denied');
|
4 |
|
|
|
5 |
|
|
jimport('joomla.methods');
|
6 |
|
|
|
7 |
|
|
// This helper formats statistics.
|
8 |
|
|
abstract class StatisticHelper {
|
9 |
|
|
const MAX_ROWS = 5;
|
10 |
|
|
const MAX_ROW = 24;
|
11 |
|
|
|
12 |
|
|
// Format statistics.
|
13 |
|
|
// $statistics the statistics to format
|
14 |
|
|
// $filters the filters already selected by the user
|
15 |
|
|
// $baseUrl the base URL to use for links
|
16 |
|
|
// $fragment the URL fragment to use for links
|
17 |
|
|
// return a string containing the full HTML for the statistics or an empty string if any errors occur
|
18 |
|
|
public static function formatStatistics($statistics, $filters, $baseUrl, $fragment) {
|
19 |
|
|
$statistics = ($statistics == NULL) ? NULL : array_filter(array_map(function ($statistic) use ($filters, $baseUrl, $fragment) {return StatisticHelper :: _formatStatistic($statistic, $filters, $baseUrl, $fragment);}, $statistics));
|
20 |
|
|
return ($statistics == NULL) ? '' : ('<h2>' . JText :: _('REFINE_BY') . '</h2><div class="selectorAvailable">' . implode('', $statistics) . '</div>');
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
public static function _formatStatistic($statistic, $filters, $baseUrl, $fragment) {
|
24 |
|
|
$data = (($statistic -> data == NULL) || array_key_exists($statistic -> id, $filters)) ? NULL : array_filter(array_map(function ($row) use ($statistic, $filters, $baseUrl, $fragment) {return StatisticHelper :: _formatRow($row, $statistic -> id, $filters, $baseUrl, $fragment);}, $statistic -> data));
|
25 |
|
|
return ($data == NULL) ? '' : ('<div class="element"><h3>' . $statistic -> title . '</h3><div class="flowWrapper">' . implode('<br />', array_slice($data, 0, StatisticHelper :: MAX_ROWS)) . ((count($data) > StatisticHelper :: MAX_ROWS) ? ('<br /><span class="viewmore">' . JText :: _('VIEW_MORE') . '</span><div style="display: none;"><div class="viewallpop" id="' . $statistic -> id . 'More"><div class="header"><h5>' . $statistic -> title . '</h5></div><p>' . implode('<br />', $data) . '</p></div></div>') : '') . '</div></div>');
|
26 |
|
|
}
|
27 |
|
|
|
28 |
27602
|
yannis.str
|
public static function _formatRow($row, $statisticId, $filters, $baseUrl, $fragment) {
|
29 |
18541
|
thanos.pap
|
$filters = ($filters == NULL) ? NULL : array_filter(array_map(function ($filter) use ($statisticId) {return ($filter -> name == $statisticId) ? '' : (urlencode($filter -> name) . '=' . urlencode(($filter -> value === TRUE) ? 'true' : (($filter -> value === FALSE) ? 'false' : $filter -> value)));}, $filters));
|
30 |
|
|
// TODO JRoute :: _ keeps decoding urlencoded values, so this is just a hack to cope with this
|
31 |
30864
|
yannis.str
|
return '<a href="' . JRoute :: _( $baseUrl . (($filters == NULL) ? '' : ('&' . implode('&', $filters))) . '&' . urlencode($statisticId) . '=' . urlencode($row -> id) . $fragment) . '" class="selectorAdd" title="' . $row -> name . '">' . ((strlen($row -> name) > StatisticHelper :: MAX_ROW) ? (substr($row -> name, 0, StatisticHelper :: MAX_ROW - strlen('...')) . '...') : $row -> name ) . '</a> <span>(' . $row -> count . ')</span>';
|
32 |
18541
|
thanos.pap
|
}
|
33 |
|
|
}
|