Tests / test (push) Failing after 49s
Merge the V4 development history with current manager, SDL and setpoint fixes. Retain guarded trial behavior and consolidate controls in Prognose / Forecast. Exclude the unverified accounting-evidence change; no runtime deployment or new dispatch permission. Validated: 357 PHPUnit tests / 1758 assertions, 150 PHP syntax checks, 310 backend tests, 16 portal tests and isolated UI/receiver checks. develop and beta publication explicitly approved by Daniel Haefliger.
108 lines
4.8 KiB
PHP
108 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Belevo\EnelixEMS;
|
|
|
|
use LogicException;
|
|
|
|
/** Form composition only. Existing configuration, control authority and backend stay unchanged. */
|
|
final class ManagerPrognoseFormular
|
|
{
|
|
public static function startErlaubt(array $zustand): bool
|
|
{
|
|
foreach (['prognoseAktiv', 'lizenziert', 'senderAktiv', 'empfangAktiv', 'managerAktiv',
|
|
'testErlaubt', 'aktivtestErlaubt', 'watchdogVerzichtErlaubt'] as $feld) {
|
|
if (($zustand[$feld] ?? false) !== true) {
|
|
return false;
|
|
}
|
|
}
|
|
return ($zustand['legacyAktiv'] ?? true) === false
|
|
&& ($zustand['aktivtestAktiv'] ?? true) === false
|
|
&& isset($zustand['ende'], $zustand['jetzt'])
|
|
&& is_int($zustand['ende']) && is_int($zustand['jetzt'])
|
|
&& ($zustand['ende'] === 0 || $zustand['ende'] > $zustand['jetzt']);
|
|
}
|
|
|
|
public static function statustext(array $zustand): string
|
|
{
|
|
$text = ($zustand['aktivtestAktiv'] ?? false)
|
|
? 'Netzfahrplan: befristeter Testbetrieb eingeschaltet.'
|
|
: 'Netzfahrplan: Steuerung ausgeschaltet.';
|
|
if ($zustand['legacyAktiv'] ?? false) {
|
|
$text = 'Bisheriger Netzfahrplan eingeschaltet; neuer Netzfahrplan gesperrt.';
|
|
}
|
|
if (!($zustand['lizenziert'] ?? false)) {
|
|
$text .= ' Netzfahrplanlizenz fehlt.';
|
|
}
|
|
$ende = $zustand['ende'] ?? 0;
|
|
if (is_int($ende) && $ende > 0) {
|
|
$text .= ' Bestehendes Testende: ' . gmdate('d.m.Y H:i:s', $ende) . ' UTC.';
|
|
if ($ende <= ($zustand['jetzt'] ?? 0)) {
|
|
$text .= ' Testfreigabe abgelaufen.';
|
|
}
|
|
}
|
|
return $text . ' Kein freigegebener Dauerbetrieb. Bestehende Laufzeit-, Messwert- und Geraeteschutzpruefungen bleiben wirksam.';
|
|
}
|
|
|
|
public static function integrieren(array $formular, array $zustand): array
|
|
{
|
|
$gefunden = false;
|
|
$v4Konfiguriert = ($zustand['senderAktiv'] ?? false)
|
|
|| ($zustand['empfangAktiv'] ?? false) || ($zustand['messdatenAktiv'] ?? false);
|
|
foreach ($formular['elements'] as &$element) {
|
|
if (($element['name'] ?? null) !== 'PrognoseForecast') {
|
|
continue;
|
|
}
|
|
if ($gefunden) {
|
|
throw new LogicException('Prognosebereich ist nicht eindeutig.');
|
|
}
|
|
$gefunden = true;
|
|
foreach ($element['items'] as &$feld) {
|
|
if (($feld['name'] ?? null) === 'NetzfahrplanAktiv' && $v4Konfiguriert) {
|
|
// An active legacy controller remains visible so it can still be disabled.
|
|
$feld['visible'] = (bool) ($zustand['legacyAktiv'] ?? false);
|
|
$feld['enabled'] = (bool) ($zustand['legacyAktiv'] ?? false);
|
|
$feld['caption'] = 'Bisheriger Netzfahrplan (konkurrierende Steuerung)';
|
|
}
|
|
}
|
|
unset($feld);
|
|
$element['items'][] = [
|
|
'type' => 'Button', 'name' => 'PrognoseLizenzVerwalten',
|
|
'caption' => 'Prognose und Netzfahrplan im Lizenzportal verwalten', 'link' => true,
|
|
'onClick' => "echo 'https://license.enelix.ch';",
|
|
];
|
|
$element['items'][] = [
|
|
'type' => 'CheckBox', 'name' => 'NetzfahrplanV4EmpfangAktiv',
|
|
'caption' => 'Aktuellen Netzfahrplan empfangen und anzeigen',
|
|
'enabled' => (bool) (($zustand['lizenziert'] ?? false) || ($zustand['empfangAktiv'] ?? false)),
|
|
];
|
|
$element['items'][] = [
|
|
'type' => 'Label', 'name' => 'PrognoseNetzfahrplanStatus',
|
|
'caption' => self::statustext($zustand),
|
|
];
|
|
$element['items'][] = [
|
|
'type' => 'Button', 'name' => 'PrognoseNetzfahrplanStart',
|
|
'caption' => 'Netzfahrplan einschalten (Testbetrieb)',
|
|
'enabled' => self::startErlaubt($zustand),
|
|
'onClick' => "IPS_RequestAction(\$id, 'FormNetzfahrplanSchalten', true);",
|
|
];
|
|
$element['items'][] = [
|
|
'type' => 'Button', 'name' => 'PrognoseNetzfahrplanStop',
|
|
'caption' => 'Netzfahrplan ausschalten', 'enabled' => true,
|
|
'onClick' => "IPS_RequestAction(\$id, 'FormNetzfahrplanSchalten', false);",
|
|
];
|
|
$element['items'][] = [
|
|
'type' => 'Button', 'name' => 'PrognoseNetzfahrplanPruefen',
|
|
'caption' => 'Plan jetzt pruefen',
|
|
'onClick' => "IPS_RequestAction(\$id, 'NetzfahrplanV4Empfangen', true);",
|
|
];
|
|
}
|
|
unset($element);
|
|
if (!$gefunden) {
|
|
throw new LogicException('Prognosebereich fehlt; Formular nicht erweitert.');
|
|
}
|
|
return $formular;
|
|
}
|
|
}
|