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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user