Files
Reservair/includes/Services/Forms/RsvFormDefinition.php
T

66 lines
1.8 KiB
PHP
Raw Normal View History

2026-06-11 19:03:29 +02:00
<?php
class RsvFormDefinition {
public $_elements = [];
public string $_id = "";
public string $email_key = "";
2026-06-17 11:15:09 +02:00
public array $membership = [];
2026-06-14 07:16:13 +02:00
public string $success_message = "";
2026-06-11 19:03:29 +02:00
/**
2026-06-17 11:15:09 +02:00
* @param array<string,mixed> $definition Full definition array including 'elements', 'email_key' and 'success_message'.
2026-06-11 19:03:29 +02:00
*/
public function __construct(string $id, array $definition) {
$this->_elements = [];
if (array_key_exists('elements', $definition)) {
foreach ($definition['elements'] as $element) {
array_push($this->_elements, RsvFormElementDefinition::fromArray($element));
}
}
2026-06-14 07:16:13 +02:00
$this->_id = $id;
$this->email_key = $definition['email_key'] ?? '';
2026-06-17 11:15:09 +02:00
$this->membership = $definition['membership'] ?? [];
2026-06-14 07:16:13 +02:00
$this->success_message = $definition['success_message'] ?? '';
2026-06-11 19:03:29 +02:00
}
public function getId(): string {
return $this->_id;
}
public function getEmailKey(): string {
return $this->email_key;
}
2026-06-17 11:15:09 +02:00
/** @return array<int,array{program_id:int,discount:float,field:string}> */
public function getMembershipBindings(): array {
return $this->membership['bindings'] ?? [];
}
public function getMembershipCombine(): string {
return $this->membership['combine'] ?? 'max';
}
2026-06-14 07:16:13 +02:00
/** Template shown to the visitor after a successful submission. */
public function getSuccessMessage(): string {
return $this->success_message;
}
2026-06-11 19:03:29 +02:00
public function hasElements() : bool {
return count($this->_elements) > 0;
}
/**
* @return array<int, RsvFormElementDefinition>
*/
public function getElements() : array {
return $this->_elements;
}
}