Source
xxxxxxxxxx
public static function getPeriodTag(int $period, int $period_from, int $period_to, string $timezone): CTag {
<?php declare(strict_types = 0);
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
final class CSlaHelper {
public const SLA_STATUS_ANY = -1;
public const SLA_STATUS_ENABLED = ZBX_SLA_STATUS_ENABLED;
public const SLA_STATUS_DISABLED = ZBX_SLA_STATUS_DISABLED;
public const SCHEDULE_MODE_24X7 = 0;
public const SCHEDULE_MODE_CUSTOM = 1;
/**
* @return array
*/
public static function getPeriodNames(): array {
static $period_names;
if ($period_names === null) {
$period_names = [
ZBX_SLA_PERIOD_DAILY => _('Daily'),
ZBX_SLA_PERIOD_WEEKLY => _('Weekly'),
ZBX_SLA_PERIOD_MONTHLY => _('Monthly'),
ZBX_SLA_PERIOD_QUARTERLY => _('Quarterly'),
ZBX_SLA_PERIOD_ANNUALLY => _('Annually')
];
}
return $period_names;
}
/**
* @param bool $compact
*
* @return array
*/
public static function getReportNames(bool $compact = false): array {
static $report_names;
if ($report_names === null) {
$report_names = [
'default' => [
ZBX_SLA_PERIOD_DAILY => _('Day'),
ZBX_SLA_PERIOD_WEEKLY => _('Week'),
ZBX_SLA_PERIOD_MONTHLY => _('Month'),
ZBX_SLA_PERIOD_QUARTERLY => _('Quarter'),
ZBX_SLA_PERIOD_ANNUALLY => _('Year')
],
'compact' => [
ZBX_SLA_PERIOD_DAILY => _x('Day', 'compact table header'),
ZBX_SLA_PERIOD_WEEKLY => _x('Week', 'compact table header'),
ZBX_SLA_PERIOD_MONTHLY => _x('Month', 'compact table header'),
ZBX_SLA_PERIOD_QUARTERLY => _x('Quarter', 'compact table header'),
ZBX_SLA_PERIOD_ANNUALLY => _x('Year', 'compact table header')
]
];
}
return $report_names[$compact ? 'compact' : 'default'];
}
/**
* @param array $schedule
*
* @throws Exception
* @return array
*/
public static function getSchedulePeriods(array $schedule): array {
$schedule_periods = array_fill(0, 7, '');
for ($weekday = 0; $weekday < 7; $weekday++) {
foreach ($schedule as $schedule_row) {
$period_from = max(SEC_PER_DAY * $weekday, $schedule_row['period_from']);
$period_to = min(SEC_PER_DAY * ($weekday + 1), $schedule_row['period_to']);
if ($period_to <= $period_from) {
continue;
}