src/Service/CampusService.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Repository\CampusRepository;
  4. /**
  5.  * Class CampusService
  6.  * @package App\Service
  7.  */
  8. class CampusService extends BaseService
  9. {
  10.     /**
  11.      * CampusService constructor.
  12.      * @param CampusRepository $repository
  13.      */
  14.     public function __construct(
  15.         CampusRepository $repository,
  16.         BaseService $baseService
  17.     ) {
  18.         $this->reflectFromParent($baseService);
  19.         $this->repository $repository;
  20.     }
  21.     public function getById($id)
  22.     {
  23.         return $this->repository->getOneBy(
  24.             [
  25.                 'filter_id' => $id
  26.             ]
  27.         );
  28.     }
  29.     public function getCenterMapLocationList($campus null$template 'campus/centerMapInfoMultiple.html.twig') {
  30.         $centers = [];
  31.         $filters = [];
  32.         $filters['filter_status'] = 1;
  33.         if(!is_null($campus)) {
  34.             $filters['filter_id'] = $campus->getId();
  35.         }
  36.         forEach($this->repository->getAll($filters'ENTITY') as $campus) {
  37.             forEach($campus->getCampusCenters() as $center) {
  38.                 if(!$center->getGoogleMapUrl()) continue;
  39.                 $re '/!8m2!3d(?<lat>[\-0-9.]+)!4d(?<long>[\-0-9.]+)/m';
  40.                 preg_match_all($re$center->getGoogleMapUrl(), $matchesPREG_SET_ORDER);
  41.                 if(count($matches) <= 0) {
  42.                     $re '/!2m2!1d(?<long>[\-0-9.]+)!2d(?<lat>[\-0-9.]+)/m';
  43.                     preg_match_all($re$center->getGoogleMapUrl(), $matchesPREG_SET_ORDER);
  44.                     if(count($matches) <= 0) {
  45.                         continue;
  46.                     }
  47.                 }
  48.                 $lastCoordinate $matches[count($matches) - 1];
  49.                 $infoContent $this->container->get('twig')->render($template, [
  50.                     'name' => $campus->getName(),
  51.                     'address' => $center->getAddress(),
  52.                     'address2' => $center->getAddress2(),
  53.                     'postalCode' => $center->getPostalCode(),
  54.                     'city' => $center->getCity(),
  55.                     'country' => $center->getCountry(),
  56.                     'logo' => $this->uploadsStorage->publicUrl($campus->getLogo()->getPath()),
  57.                     'url' => $this->urlGenerator->generate('campus_detail', ['slug' => $campus->getSlug()]),
  58.                     'transportMethods' => $center->getTransportMethods(),
  59.                     'googleMapUrl' => $center->getGoogleMapUrl(),
  60.                     'contactEmail' => $center->getContactEmail(),
  61.                     'disabilityReferentName' => $center->getDisabilityReferentName(),
  62.                     'disabilityReferentEmail' => $center->getDisabilityReferentEmail()
  63.                 ]);
  64.                 $centers[] = [
  65.                     'id' => $center->getId(),
  66.                     'infoContent' => $infoContent,
  67.                     'name' => $campus->getName(),
  68.                     'url' => $this->urlGenerator->generate('campus_detail', ['slug' => $campus->getSlug()]),
  69.                     'longtitude' => $lastCoordinate['long']*1,
  70.                     'latitude' => $lastCoordinate['lat']*1,
  71.                 ];
  72.             }
  73.         }
  74.         return $centers;
  75.     }
  76. }