Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions system/ee/ExpressionEngine/Addons/stats/mod.stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Stats
public function __construct()
{
ee()->stats->load_stats();
$statdata = ee()->stats->statdata();

// Limit stats by channel or status
// You can limit the stats by any combination of channels
Expand Down Expand Up @@ -89,16 +90,11 @@ public function __construct()
}
}

foreach ($sdata as $key => $val) {
ee()->stats->set_statdata($key, $val);

ee()->stats->stats_cache[$cache_sql][$key] = $val;
}
ee()->stats->stats_cache[$cache_sql] = $sdata;
$statdata = array_merge($statdata, $sdata);
}
} else {
foreach (ee()->stats->stats_cache[$cache_sql] as $key => $val) {
ee()->stats->set_statdata($key, $val);
}
$statdata = array_merge($statdata, ee()->stats->stats_cache[$cache_sql]);
}
}

Expand All @@ -110,8 +106,9 @@ public function __construct()

foreach ($fields as $field) {
if (isset(ee()->TMPL->var_single[$field])) {
$cond[$field] = ee()->stats->statdata($field);
ee()->TMPL->tagdata = ee()->TMPL->swap_var_single($field, ee()->stats->statdata($field), ee()->TMPL->tagdata);
$value = isset($statdata[$field]) ? $statdata[$field] : false;
$cond[$field] = $value;
ee()->TMPL->tagdata = ee()->TMPL->swap_var_single($field, $value, ee()->TMPL->tagdata);
}
}

Expand All @@ -126,13 +123,14 @@ public function __construct()
foreach (ee()->TMPL->var_single as $key => $val) {
foreach ($dates as $date) {
if (strncmp($key, $date, strlen($date)) == 0) {
$date_value = isset($statdata[$date]) ? $statdata[$date] : false;
ee()->TMPL->tagdata = ee()->TMPL->swap_var_single(
$key,
(! ee()->stats->statdata($date)
or ee()->stats->statdata($date) == 0) ? '--' :
(! $date_value
or $date_value == 0) ? '--' :
ee()->localize->format_date(
$val,
ee()->stats->statdata($date)
$date_value
),
ee()->TMPL->tagdata
);
Expand All @@ -144,7 +142,7 @@ public function __construct()

$names = '';

if (ee()->stats->statdata('current_names')) {
if (! empty($statdata['current_names'])) {
$chunk = ee()->TMPL->fetch_data_between_var_pairs(
ee()->TMPL->tagdata,
'member_names'
Expand Down Expand Up @@ -177,7 +175,7 @@ public function __construct()
$member_path = str_replace("'", "", $member_path);
$member_path = trim_slashes($member_path);

foreach (ee()->stats->statdata('current_names') as $k => $v) {
foreach ($statdata['current_names'] as $k => $v) {
$temp = $chunk;

if (empty($temp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ public function set_statdata($key, $value)
$this->data[$key] = $value;
}

public function statdata($key)
public function statdata($key = null)
{
if (! $key) {
return $this->data;
}

return $this->data[$key] ?? false;
}
}
Expand Down