feat: extended insurance parsing, pass info urls to view
This commit is contained in:
@@ -37,6 +37,9 @@ class Insurance
|
||||
#[Groups(['api:single', 'api:list'])]
|
||||
public bool $package = false;
|
||||
|
||||
#[Groups(['api:single', 'api:list'])]
|
||||
public bool $complementary = false;
|
||||
|
||||
#[Groups(['api:single', 'api:list'])]
|
||||
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
||||
public ?\DateTimeImmutable $travelDateFrom = null;
|
||||
@@ -110,4 +113,66 @@ class Insurance
|
||||
|
||||
return $this->subType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all info URLs from this insurance or its contained insurances (for packages).
|
||||
*
|
||||
* @return array<string> Array of info URLs
|
||||
*/
|
||||
public function getAllUrlsInfo(): array
|
||||
{
|
||||
if (true === $this->package) {
|
||||
return $this->collectUrlsFromContainedInsurances('urlInfo');
|
||||
}
|
||||
|
||||
return null !== $this->urlInfo ? [$this->urlInfo] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all product info URLs from this insurance or its contained insurances (for packages).
|
||||
*
|
||||
* @return array<string> Array of product info URLs
|
||||
*/
|
||||
public function getAllUrlsProductInfo(): array
|
||||
{
|
||||
if (true === $this->package) {
|
||||
return $this->collectUrlsFromContainedInsurances('urlProductInfo');
|
||||
}
|
||||
|
||||
return null !== $this->urlProductInfo ? [$this->urlProductInfo] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all terms URLs from this insurance or its contained insurances (for packages).
|
||||
*
|
||||
* @return array<string> Array of terms URLs
|
||||
*/
|
||||
public function getAllUrlsTerms(): array
|
||||
{
|
||||
if (true === $this->package) {
|
||||
return $this->collectUrlsFromContainedInsurances('urlTerms');
|
||||
}
|
||||
|
||||
return null !== $this->urlTerms ? [$this->urlTerms] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects URLs from contained insurances for a specific URL property.
|
||||
*
|
||||
* @param string $urlProperty The URL property name to collect (urlInfo, urlProductInfo, urlTerms)
|
||||
*
|
||||
* @return array<string> Array of non-null URLs from contained insurances
|
||||
*/
|
||||
private function collectUrlsFromContainedInsurances(string $urlProperty): array
|
||||
{
|
||||
$urls = [];
|
||||
|
||||
foreach ($this->containedInsurances as $containedInsurance) {
|
||||
if (null !== $containedInsurance->{$urlProperty}) {
|
||||
$urls[] = $containedInsurance->{$urlProperty};
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($urls));
|
||||
}
|
||||
}
|
||||
@@ -39,13 +39,14 @@ class InsuranceParser extends AbstractParser
|
||||
// Parse all individual insurances for reference lookup
|
||||
$insurance = $this->parseInsuranceNode($node, false);
|
||||
if (null !== $insurance && null !== $insurance->id) {
|
||||
// Set complementary flag from XML attribute
|
||||
$insurance->complementary = $isComplementary;
|
||||
|
||||
$individualInsurances[$insurance->id] = $insurance;
|
||||
|
||||
// Include only if it's NOT a complementary insurance (zusatzversicherung)
|
||||
// Complementary insurances are only available as part of packages, never standalone
|
||||
if (!$isComplementary) {
|
||||
$insurances[$insurance->id] = $insurance;
|
||||
}
|
||||
// Include ALL insurances in the result array
|
||||
// Complementary insurances will be filtered out at the form field level
|
||||
$insurances[$insurance->id] = $insurance;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -56,6 +57,15 @@ class InsuranceParser extends AbstractParser
|
||||
if (null !== $insurance && null !== $insurance->id) {
|
||||
// Parse contained insurance IDs
|
||||
$insurance->containedInsuranceIds = $this->parseContainedInsuranceIds($node);
|
||||
|
||||
// Populate containedInsurances with actual Insurance objects
|
||||
$insurance->containedInsurances = [];
|
||||
foreach ($insurance->containedInsuranceIds as $containedId) {
|
||||
if (isset($individualInsurances[$containedId])) {
|
||||
$insurance->containedInsurances[] = $individualInsurances[$containedId];
|
||||
}
|
||||
}
|
||||
|
||||
$insurances[$insurance->id] = $insurance;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user