src/Services/CountBusinessContactReferrals.php line 63

Open in your IDE?
  1. <?php
  2. namespace App\Services;
  3. use App\Repository\BusinessContactsRepository;
  4. use App\Repository\ReferralsRepository;
  5. class CountBusinessContactReferrals
  6. {
  7.     public function countReferrals(int $businessContact\DateTimeInterface $startDate null\DateTimeInterface $endDate nullstring $format)
  8.     {
  9.         $today = new \DateTime('now');
  10.         $all_referals $this->referralRepository->findBy([
  11.             'businessSite' => $this->businessContactsRepository->find($businessContact),
  12.             'action' => $format
  13.         ]);
  14.         $referals = [];
  15.         if ($startDate == null && $endDate == null) {
  16.             foreach ($all_referals as $referal) {
  17.                 if ($today->format('Y-m-d') <= $referal->getDateTime()->format('Y-m-d')) {
  18.                     $referals[] = $referal;
  19.                 }
  20.             }
  21.         }
  22.         if ($startDate != null && $endDate == null) {
  23.             foreach ($all_referals as $referal) {
  24.                 if ($startDate->format('y-m-d') <= $referal->getDateTime()->format('y-m-d')) {
  25.                     $referals[] = $referal;
  26.                 }
  27.             }
  28.         }
  29.         if ($startDate == null && $endDate != null) {
  30.             foreach ($all_referals as $referal) {
  31.                 if ($endDate->format('y-m-d') >= $referal->getDateTime()->format('y-m-d')) {
  32.                     $referals[] = $referal;
  33.                 }
  34.             }
  35.         }
  36.         if ($startDate != null && $endDate != null) {
  37.             foreach ($all_referals as $referal) {
  38.                 if ($startDate->format('y-m-d') <= $referal->getDateTime()->format('y-m-d') && $endDate->format('y-m-d') > $referal->getDateTime()->format('y-m-d')) {
  39.                     $referals[] = $referal;
  40.                 }
  41.             }
  42.         }
  43.         if ($referals) {
  44.             return count($referals);
  45.         } else {
  46.             return count($referals);
  47.         }
  48.     }
  49.     public function __construct(ReferralsRepository $referralsRepositoryBusinessContactsRepository $businessContactsRepository)
  50.     {
  51.         $this->businessContactsRepository $businessContactsRepository;
  52.         $this->referralRepository $referralsRepository;
  53.     }
  54. }