asArray();
uasort(
$pieChartData,
function ($a, $b) {
return $a->worseThan($b) ? -1 : ($b->worseThan($a) ? 1 : 0);
}
);
$results = array();
$keys = array('', 'label', 'value', 'min', 'max', 'warn', 'crit');
$columns = array();
$labels = array_combine(
$keys,
array(
'',
$this->view->translate('Label'),
$this->view->translate('Value'),
$this->view->translate('Min'),
$this->view->translate('Max'),
$this->view->translate('Warning'),
$this->view->translate('Critical')
)
);
foreach ($pieChartData as $perfdata) {
if ($perfdata->isVisualizable()) {
$columns[''] = '';
}
foreach ($perfdata->toArray() as $column => $value) {
if (empty($value) ||
$column === 'min' && floatval($value) === 0.0 ||
$column === 'max' && $perfdata->isPercentage() && floatval($value) === 100) {
continue;
}
$columns[$column] = $labels[$column];
}
}
// restore original column array sorting
$headers = array();
foreach ($keys as $column) {
if (isset($columns[$column])) {
$headers[$column] = $labels[$column];
}
}
$table = array('
' . implode(' | ', $headers) . ' | ');
foreach ($pieChartData as $perfdata) {
if ($compact && $perfdata->isVisualizable()) {
$results[] = $perfdata->asInlinePie($color)->render();
} else {
$data = array();
if ($perfdata->isVisualizable()) {
$data []= $perfdata->asInlinePie($color)->render() . ' ';
} elseif (isset($columns[''])) {
$data []= '';
}
if (! $compact) {
foreach ($perfdata->toArray() as $column => $value) {
if (! isset($columns[$column])) {
continue;
}
$text = $this->view->escape(empty($value) ? '-' : $value);
$data []= sprintf(
'%s',
$text,
String::ellipsisCenter($text, 24)
);
}
}
$table []= '' . implode(' | ', $data) . ' |
';
}
}
if ($limit > 0) {
$count = $compact ? count($results) : count($table);
if ($count > $limit) {
if ($compact) {
$results = array_slice($results, 0, $limit);
$title = sprintf($this->view->translate('%d more ...'), $count - $limit);
$results[] = '...';
} else {
$table = array_slice($table, 0, $limit);
}
}
}
if ($compact) {
return join('', $results);
} else {
if (empty($table)) {
return '';
}
return sprintf(
'',
isset($columns['']) ? 'perfdata-piecharts' : '',
implode("\n", $table)
);
}
}
}