← Back
Editing: AbstractTypeControlReport.php
<?php namespace App\Report\Control\Type; use App\Entity\AgencyPrestataire; use App\Entity\Controle; abstract class AbstractTypeControlReport implements TypeControlReportInterface { protected string $logo; public function __construct(protected readonly string $publicDir) { } public function getContextFromControl(Controle $control): array { return [ 'controle' => $control, 'agent' => $control->getAgent(), 'numeroContratAgency' => $this->getAgencyProvider($control)?->getNumeroContrat() ?? '', 'agency' => $control->getAdresse()->getAgency(), 'logo' => $this->getLogo($control), 'prestataire' => $this->getAgencyProvider($control)?->getPrestataire(), 'adresse' => $control->getAdresse(), 'today' => new \DateTime('today'), ]; } public function getAgencyProvider(Controle $control): ?AgencyPrestataire { if ($control->getAdresse()->getPrestataires()->count() > 0) { $listeAgencyPrestataires = $control->getAdresse()->getPrestataires()->first()?->getAgencyPrestataires(); if (count($listeAgencyPrestataires) > 0) { return $listeAgencyPrestataires[0]; } } return null; } /** * @return AgencyPrestataire[] */ public function getAdditionalProviderContacts(Controle $control): array { if (0 === $control->getAdresse()->getPrestataires()->count()) { return []; } $listContacts = $control->getAdresse()->getPrestataires()->first()?->getAgencyPrestataires(); if (count($listContacts) <= 1) { return []; } $contacts = []; for ($i = 1; $i < count($listContacts); ++$i) { $contacts[] = $listContacts[$i]; } return $contacts; } protected function getLogo(Controle $control): string { if ($control->getAdresse()->getAgency()?->getLogo() && is_file( $this->publicDir.'/uploads/logos/'.$control->getAdresse()->getAgency()->getLogo() )) { return '@logos/'.$control->getAdresse()->getAgency()->getLogo(); } return '@images/bot.png'; } }
Save File
Cancel