src/Service/VehicleService.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Adapter\AppointmentAdapter;
  4. use App\Adapter\VehicleAdapter;
  5. use App\Mapper\AppointmentMapper;
  6. use App\Model\Client;
  7. use App\Model\Vehicle;
  8. use Psr\Log\LoggerInterface;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. use Symfony\Component\Serializer\SerializerInterface;
  11. class VehicleService extends AppointmentService
  12. {
  13.     private LoggerInterface $logger;
  14.     private VehicleAdapter $vehicleAdapter;
  15.     public function __construct(AppointmentAdapter $adapterAppointmentMapper $mapperClientService $clientServiceSerializerInterface $serializerVehicleAdapter $vehicleAdapter)
  16.     {
  17.         parent::__construct($adapter$mapper$clientService$serializer);
  18.         $this->vehicleAdapter $vehicleAdapter;
  19.     }
  20.     public function all(): array
  21.     {
  22.         return $this->vehicleAdapter->getAllVehicles();
  23.     }
  24.     public function getOrderedVehicles(bool $isUserConnectedVehicle $selectedVehicle, array &$vehicles)
  25.     {
  26.         if ($isUserConnected) {
  27.             if ($upsertVehicle $this->clientService->upsertVehicle($selectedVehicle)) {
  28.                 $this->addToVehicles($vehicles$upsertVehicle);
  29.             }
  30.         } else {
  31.             $this->addToVehicles($vehicles$selectedVehicle);
  32.         }
  33.     }
  34.     public function getVehicles(bool $isUserConnected, ?Client $userSerializerInterface $serializerAppointmentService $appointmentServiceSessionInterface $session): array
  35.     {
  36.         if ($isUserConnected) {
  37.             $userVehicles $user->getVehicles();
  38.             $vehicles = [];
  39.             foreach ($userVehicles as $car) {
  40.                 /** @var Vehicle $userVehicle */
  41.                 $userVehicle $serializer->deserialize(json_encode($carJSON_THROW_ON_ERROR), Vehicle::class, 'json');
  42.                 $appointmentService->addToVehicles($vehicles$userVehicle);
  43.             }
  44.         } else {
  45.             $vehicles $session->get('vehicles', []);
  46.         }
  47.         return $vehicles;
  48.     }
  49. }