src/Services/FutureOfficeAppointmentsByUser.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Services;
  3. use App\Entity\User;
  4. use App\Repository\OfficeAppointmentsRepository;
  5. class FutureOfficeAppointmentsByUser
  6. {
  7.     public function getAppointments(User $user null\DateTimeInterface $startDate null\DateTimeInterface $endDate null)
  8.     {
  9.         $today = new \DateTime('now');
  10.         $bookings $this->officeAppointmentsRepository->findBy([
  11.             'client' => $user
  12.         ]);
  13.         $future_bookings = [];
  14.         if ($startDate == null && $endDate == null) {
  15.             foreach ($bookings as $booking) {
  16.                 if ($today->format('y-m-d') <= $booking->getDate()->format('y-m-d')) {
  17.                     $future_bookings[] = $booking;
  18.                 }
  19.             }
  20.         }
  21.         if ($startDate != null && $endDate == null) {
  22.             foreach ($bookings as $booking) {
  23.                 if ($startDate->format('y-m-d') <= $booking->getDate()->format('y-m-d')) {
  24.                     $future_bookings[] = $booking;
  25.                 }
  26.             }
  27.         }
  28.         if ($startDate == null && $endDate != null) {
  29.             foreach ($bookings as $booking) {
  30.                 if ($endDate->format('y-m-d') >= $booking->getDate()->format('y-m-d')) {
  31.                     $future_bookings[] = $booking;
  32.                 }
  33.             }
  34.         }
  35.         if ($startDate != null && $endDate != null) {
  36.             foreach ($bookings as $booking) {
  37.                 if ($startDate->format('y-m-d') <= $booking->getDate()->format('y-m-d') && $endDate->format('y-m-d') > $booking->getDate()->format('y-m-d')) {
  38.                     $future_bookings[] = $booking;
  39.                 }
  40.             }
  41.         }
  42.         if ($future_bookings) {
  43.             return count($future_bookings);
  44.         } else {
  45.             return count($future_bookings);
  46.         }
  47.     }
  48.     public function __construct(OfficeAppointmentsRepository $officeAppointmentsRepository)
  49.     {
  50.         $this->officeAppointmentsRepository $officeAppointmentsRepository;
  51.     }
  52. }