Files
wk-sync-bundle/src/Booking/FieldRules.php
T
Jürgen MummertandClaude Fable 5.1 4d4f21b7c8 Require Contao 6 and drop the Contao 5 compatibility code
- Require contao/core-bundle and calendar-bundle ^6.0
- Render the setup check and the notification help as input_field
  callbacks instead of a custom backend widget; the fields no longer
  create a virtual jsonData column
- Load the backend style sheet through contao.backend.custom_css and
  remove the menu listener (tooltip workaround for Contao 5 included)
- Tell editors when the Notification Center is not installed instead of
  linking to a module that does not exist
- Generate category aliases with the slug settings of the calendar page
  so that umlauts are transliterated for German sites
- Always return a RecordLabel for the category list, export stored
  values as they are, remove the decodeEntities options and the legacy
  "events" URL parameter, use array notation for the price columns

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-27 20:21:12 +02:00

68 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Mummert\ContaoWkSyncBundle\Booking;
/**
* Ergebnis der Formularregeln für eine Veranstaltung.
*/
final readonly class FieldRules
{
/**
* @param list<string> $hiddenFields
* @param list<string> $activeSlots
* @param array<string, array{field: string, values: list<string>}> $dependencies
*/
public function __construct(
public array $hiddenFields,
public array $activeSlots,
public array $dependencies,
) {
}
public function isHidden(string $field): bool
{
return \in_array($field, $this->hiddenFields, true);
}
/**
* Ist ein Feld bei den übermittelten Werten sichtbar? Berücksichtigt Regeln und Abhängigkeiten,
* auch über mehrere Stufen (z. B. Rechnungsfelder -> Rechnungsanschrift-Checkbox -> Lehrertätigkeit).
*
* @param array<string, mixed> $values
*/
public function isVisible(string $field, array $values, int $depth = 0): bool
{
if ($this->isHidden($field) || $depth > 10) {
return false;
}
if (!isset($this->dependencies[$field])) {
return true;
}
$dependency = $this->dependencies[$field];
if (!$this->isVisible($dependency['field'], $values, $depth + 1)) {
return false;
}
$value = $values[$dependency['field']] ?? '';
if (\is_array($value)) {
$value = (string) array_first($value);
}
return \in_array((string) $value, $dependency['values'], true);
}
/**
* @param array<string, mixed> $values
*/
public function isDependencyMet(string $field, array $values): bool
{
return !isset($this->dependencies[$field]) || $this->isVisible($field, $values);
}
}