2021-07-26 11:16:52 +02:00
|
|
|
<?php
|
|
|
|
$mainNoticeHeading = [
|
|
|
|
'critical' => __('Your Cerebrate instance requires immediate attention.'),
|
|
|
|
'warning' => __('Issues found, it is recommended that you resolve them.'),
|
|
|
|
'info' => __('There are some optional settings that are incorrect or not set.'),
|
|
|
|
];
|
|
|
|
$headingPerLevel = [
|
|
|
|
'critical' => __('Critical settings'),
|
|
|
|
'warning' => __('Warning settings'),
|
|
|
|
'info' => __('Info settings'),
|
|
|
|
];
|
|
|
|
$noticeDescriptionPerLevel = [
|
|
|
|
'critical' => __('Cerebrate will not operate correctly or will be unsecure until these issues are resolved.'),
|
|
|
|
'warning' => __('Some of the features of Cerebrate cannot be utilised until these issues are resolved.'),
|
|
|
|
'info' => __('There are some optional tweaks that could be done to improve the looks of your Cerebrate instance.'),
|
|
|
|
];
|
|
|
|
|
2021-07-30 11:45:44 +02:00
|
|
|
$settingNoticeListHeader = [];
|
|
|
|
$settingNoticeList = [];
|
|
|
|
|
2021-07-26 11:16:52 +02:00
|
|
|
$alertVariant = 'info';
|
|
|
|
$skipHeading = false;
|
|
|
|
$alertBody = '';
|
|
|
|
$tableItems = [];
|
|
|
|
foreach (array_keys($mainNoticeHeading) as $level) {
|
|
|
|
if(!empty($notices[$level])) {
|
|
|
|
$variant = $variantFromSeverity[$level];
|
|
|
|
if (!$skipHeading) {
|
|
|
|
$alertBody .= sprintf('<h5 class="alert-heading">%s</h5>', $mainNoticeHeading[$level]);
|
|
|
|
$alertVariant = $variant;
|
|
|
|
$skipHeading = true;
|
|
|
|
}
|
|
|
|
$tableItems[] = [
|
|
|
|
'severity' => $headingPerLevel[$level],
|
|
|
|
'issues' => count($notices[$level]),
|
|
|
|
'badge-variant' => $variant,
|
|
|
|
'description' => $noticeDescriptionPerLevel[$level],
|
|
|
|
];
|
2021-07-30 11:55:03 +02:00
|
|
|
$settingNoticeListHeader[] = [
|
|
|
|
'html' => $this->Bootstrap->badge([
|
|
|
|
'variant' => $variantFromSeverity[$level],
|
|
|
|
'text' => $level
|
|
|
|
])
|
|
|
|
];
|
2021-07-30 11:45:44 +02:00
|
|
|
$settingNoticeList[] = $this->Bootstrap->table([
|
|
|
|
'small' => true,
|
|
|
|
'striped' => false,
|
|
|
|
'hover' => false,
|
|
|
|
'borderless' => true,
|
|
|
|
'bordered' => false,
|
|
|
|
], [
|
|
|
|
'fields' => [
|
2022-11-24 12:50:11 +01:00
|
|
|
['path' => 'name', 'label' => __('Name'), 'formatter' => function($name, $row) {
|
2021-07-30 14:58:50 +02:00
|
|
|
$settingID = preg_replace('/(\.|\W)/', '_', h($row['true-name']));
|
2022-11-28 10:02:36 +01:00
|
|
|
return sprintf('<a style="max-width: 200px; white-space: nowrap;" href="#lb-%s" onclick="redirectToSetting(\'#lb-%s\')">%s</a>', $settingID, $settingID, h($name));
|
2021-07-30 11:45:44 +02:00
|
|
|
}],
|
2022-11-24 12:50:11 +01:00
|
|
|
['path' => 'setting-path', 'label' => __('Category'), 'formatter' => function($path, $row) {
|
2021-07-30 11:45:44 +02:00
|
|
|
return '<span class="text-nowrap">' . h(str_replace('.', ' ▸ ', $path)) . '</span>';
|
|
|
|
}],
|
2022-11-24 12:50:11 +01:00
|
|
|
['path' => 'value', 'label' => __('Value'), 'formatter' => function($value, $row) {
|
2021-07-30 11:55:03 +02:00
|
|
|
$formatedValue = '<span class="p-1 rounded mb-0" style="background: #eeeeee55; font-family: monospace;">';
|
2021-07-30 11:45:44 +02:00
|
|
|
if (is_null($value)) {
|
|
|
|
$formatedValue .= '<i class="text-nowrap">' . __('No value') . '</i>';
|
|
|
|
} else if ($value === '') {
|
|
|
|
$formatedValue .= '<i class="text-nowrap">' . __('Empty string') . '</i>';
|
|
|
|
} else if (is_bool($value)) {
|
|
|
|
$formatedValue .= '<i class="text-nowrap">' . ($value ? __('true') : __('false')) . '</i>';
|
|
|
|
} else {
|
|
|
|
$formatedValue .= h($value);
|
|
|
|
}
|
2021-07-30 11:55:03 +02:00
|
|
|
$formatedValue .= '</span>';
|
2021-07-30 11:45:44 +02:00
|
|
|
return $formatedValue;
|
|
|
|
}],
|
2022-11-24 12:50:11 +01:00
|
|
|
['path' => 'description', 'label' => __('Description')]
|
2021-07-30 11:45:44 +02:00
|
|
|
],
|
|
|
|
'items' => $notices[$level],
|
|
|
|
]);
|
2021-07-26 11:16:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$alertBody = $this->Bootstrap->table([
|
|
|
|
'small' => true,
|
|
|
|
'striped' => false,
|
|
|
|
'hover' => false,
|
|
|
|
'borderless' => true,
|
|
|
|
'bordered' => false,
|
|
|
|
'tableClass' => 'mb-0'
|
|
|
|
], [
|
|
|
|
'fields' => [
|
2022-11-24 12:50:11 +01:00
|
|
|
['path' => 'severity', 'label' => __('Severity')],
|
|
|
|
['path' => 'issues', 'label' => __('Issues'), 'formatter' => function($count, $row) {
|
2021-07-26 11:16:52 +02:00
|
|
|
return $this->Bootstrap->badge([
|
|
|
|
'variant' => $row['badge-variant'],
|
|
|
|
'text' => $count
|
|
|
|
]);
|
|
|
|
}],
|
2022-11-24 12:50:11 +01:00
|
|
|
['path' => 'description', 'label' => __('Description')]
|
2021-07-26 11:16:52 +02:00
|
|
|
],
|
|
|
|
'items' => $tableItems,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$settingNotice = $this->Bootstrap->alert([
|
|
|
|
'dismissible' => false,
|
|
|
|
'variant' => $alertVariant,
|
|
|
|
'html' => $alertBody
|
|
|
|
]);
|
|
|
|
$settingNotice = sprintf('<div class="mt-3">%s</div>', $settingNotice);
|
2021-07-30 11:45:44 +02:00
|
|
|
echo $settingNotice;
|
|
|
|
|
|
|
|
$tabsOptions = [
|
|
|
|
'card' => true,
|
|
|
|
'pills' => false,
|
|
|
|
'data' => [
|
|
|
|
'navs' => $settingNoticeListHeader,
|
|
|
|
'content' => $settingNoticeList
|
|
|
|
]
|
|
|
|
];
|
|
|
|
echo $this->Bootstrap->tabs($tabsOptions);
|