Files
Reservair/includes/Services/Forms/Pricing/RsvFormPriceCalculator.php
T
2026-06-16 19:33:55 +02:00

22 lines
662 B
PHP

<?php
/** Computes a form's total price as the sum of its elements' prices. */
class RsvFormPriceCalculator {
public function calculate(RsvFormDefinition $definition, RsvFormData $data): float {
global $rsv_form_price_registry;
$total = 0.0;
foreach ($definition->getElements() as $element) {
$calculator = $rsv_form_price_registry->get($element->getType());
if ($calculator === null) {
continue; // Unpriced element type contributes nothing.
}
$total += (float) $calculator($element, $data->getValue($element->getName()));
}
return $total;
}
}