Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API.get workaround for (probably) bug in VisitsSummary + refactor of hideShowMetrics #50

Closed
wants to merge 1 commit into from
Closed
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
45 changes: 16 additions & 29 deletions plugins/API/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -889,40 +889,27 @@ private function hideShowMetrics($columns, $emptyColumns = array())
return $columns;
}

// remove columns if hideColumns query parameters exist
$columnsToRemove = Piwik_Common::getRequestVar('hideColumns', '');
if ($columnsToRemove != '') {
$columnsToRemove = explode(',', $columnsToRemove);
foreach ($columnsToRemove as $name) {
// if a column to remove is in the column list, remove it
if (isset($columns[$name])) {
unset($columns[$name]);
}
}
}
$columnsToRemove = explode(',', Piwik_Common::getRequestVar('hideColumns', ''));
$columnsToKeep = explode(',', Piwik_Common::getRequestVar('showColumns', ''));

// remove columns if showColumns query parameters exist
$columnsToKeep = Piwik_Common::getRequestVar('showColumns', '');
if ($columnsToKeep != '') {
$columnsToKeep = explode(',', $columnsToKeep);
if (count($columnsToKeep) > 0)
{
$columnsToKeep[] = 'label';
}

foreach ($columns as $name => $ignore) {
// if the current column should not be kept, remove it
$idx = array_search($name, $columnsToKeep);
if ($idx === FALSE) // if $name is not in $columnsToKeep
{
unset($columns[$name]);
}
// Merge empty columns into columnsToRemove, no need to uniquify it
$columnsToRemove = array_merge($columnsToRemove, $emptyColumns);

foreach ($columns as $name => $ignore)
{
// FIXME VisitsSummary.get returns array with metric names as values
if (is_int($name))
{
$name = $ignore;
}
}

// remove empty columns
if (is_array($emptyColumns)) {
foreach ($emptyColumns as $column) {
if (isset($columns[$column])) {
unset($columns[$column]);
}
if (in_array($name, $columnsToRemove) || (count($columnsToKeep) > 0 && !in_array($name, $columnsToKeep))) {
unset($columns[$name]);
}
}

Expand Down