1
|
<?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 = 25;
|
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
|
$hasExtraFunder=(array_key_exists($statistic -> id, $filters) && strpos($statistic -> id, 'funder') !== FALSE);
|
25
|
$data = (($statistic -> data == NULL) || (array_key_exists($statistic -> id, $filters)&& strpos($statistic -> id, 'funder') === FALSE)) ? NULL : array_filter(array_map(function ($row) use ($statistic, $filters, $baseUrl, $fragment,$hasExtraFunder) {return ($hasExtraFunder)?StatisticHelper :: _formatRowForFunder($row, $statistic -> id, $filters, $baseUrl, $fragment):StatisticHelper :: _formatRow($row, $statistic -> id, $filters, $baseUrl, $fragment);}, $statistic -> data));
|
26
|
return ($data == NULL) ? '' : ('<div class="element"><h3>' .(($hasExtraFunder)?JText :: _('ALSO_FUNDED_BY'): $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>');
|
27
|
}
|
28
|
|
29
|
public static function _formatRow($row, $statisticId, $filters, $baseUrl, $fragment) {
|
30
|
$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));
|
31
|
// TODO JRoute :: _ keeps decoding urlencoded values, so this is just a hack to cope with this
|
32
|
mb_internal_encoding('UTF-8');
|
33
|
//encode '&' to '%26' otherwise it takes it as a parameter
|
34
|
$row -> id= str_replace('&','%26',$row -> id);
|
35
|
return '<a href="' . JRoute :: _( $baseUrl . (($filters == NULL) ? '' : ('&' . implode('&', $filters))) . '&' . urlencode($statisticId) . '=' . urlencode($row -> id) . $fragment) . '" class="selectorAdd" title="' . $row -> name . '">' . ((strlen($row -> name.'(' . $row -> count . ')') > StatisticHelper :: MAX_ROW) ? (mb_substr($row -> name, 0, StatisticHelper :: MAX_ROW - strlen('...(' . $row -> count . ')')) . '...') : $row -> name ) . '</a> <span>(' . $row -> count . ')</span>';
|
36
|
}
|
37
|
public static function _formatRowForFunder($row, $statisticId, $filters, $baseUrl, $fragment) {
|
38
|
$funderId=($filters['funder']!==null)?'funder':'funderFilter';
|
39
|
$funders=($filters[$funderId]==null)?'':$filters[$funderId] -> name.'='.$filters[$funderId] -> value;
|
40
|
$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));
|
41
|
// TODO JRoute :: _ keeps decoding urlencoded values, so this is just a hack to cope with this
|
42
|
mb_internal_encoding('UTF-8');
|
43
|
//encode '&' to '%26' otherwise it takes it as a parameter
|
44
|
$row -> id= str_replace('&','%26',$row -> id);
|
45
|
|
46
|
return (strpos($funders, $row -> id) !== FALSE)?'':'<a href="' . JRoute :: _( $baseUrl . (($filters == NULL) ? '' : ('&' . implode('&', $filters))) . '&'.(empty($funders)? urlencode($statisticId) . '=':$funders.'---') . urlencode($row -> id) . $fragment) . '" class="selectorAdd" title="' . $row -> name . '">' . ((strlen($row -> name.'(' . $row -> count . ')') > StatisticHelper :: MAX_ROW) ? (mb_substr($row -> name, 0, StatisticHelper :: MAX_ROW - strlen('...(' . $row -> count . ')')) . '...') : $row -> name ) . '</a> <span>(' . $row -> count . ')</span>';
|
47
|
}
|
48
|
}
|
49
|
|