22 lines
662 B
PHP
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;
|
|
}
|
|
}
|