<?php
namespace App\Service;
use App\Repository\CampusRepository;
/**
* Class CampusService
* @package App\Service
*/
class CampusService extends BaseService
{
/**
* CampusService constructor.
* @param CampusRepository $repository
*/
public function __construct(
CampusRepository $repository,
BaseService $baseService
) {
$this->reflectFromParent($baseService);
$this->repository = $repository;
}
public function getById($id)
{
return $this->repository->getOneBy(
[
'filter_id' => $id
]
);
}
public function getCenterMapLocationList($campus = null, $template = 'campus/centerMapInfoMultiple.html.twig') {
$centers = [];
$filters = [];
$filters['filter_status'] = 1;
if(!is_null($campus)) {
$filters['filter_id'] = $campus->getId();
}
forEach($this->repository->getAll($filters, 'ENTITY') as $campus) {
forEach($campus->getCampusCenters() as $center) {
if(!$center->getGoogleMapUrl()) continue;
$re = '/!8m2!3d(?<lat>[\-0-9.]+)!4d(?<long>[\-0-9.]+)/m';
preg_match_all($re, $center->getGoogleMapUrl(), $matches, PREG_SET_ORDER);
if(count($matches) <= 0) {
$re = '/!2m2!1d(?<long>[\-0-9.]+)!2d(?<lat>[\-0-9.]+)/m';
preg_match_all($re, $center->getGoogleMapUrl(), $matches, PREG_SET_ORDER);
if(count($matches) <= 0) {
continue;
}
}
$lastCoordinate = $matches[count($matches) - 1];
$infoContent = $this->container->get('twig')->render($template, [
'name' => $campus->getName(),
'address' => $center->getAddress(),
'address2' => $center->getAddress2(),
'postalCode' => $center->getPostalCode(),
'city' => $center->getCity(),
'country' => $center->getCountry(),
'logo' => $this->uploadsStorage->publicUrl($campus->getLogo()->getPath()),
'url' => $this->urlGenerator->generate('campus_detail', ['slug' => $campus->getSlug()]),
'transportMethods' => $center->getTransportMethods(),
'googleMapUrl' => $center->getGoogleMapUrl(),
'contactEmail' => $center->getContactEmail(),
'disabilityReferentName' => $center->getDisabilityReferentName(),
'disabilityReferentEmail' => $center->getDisabilityReferentEmail()
]);
$centers[] = [
'id' => $center->getId(),
'infoContent' => $infoContent,
'name' => $campus->getName(),
'url' => $this->urlGenerator->generate('campus_detail', ['slug' => $campus->getSlug()]),
'longtitude' => $lastCoordinate['long']*1,
'latitude' => $lastCoordinate['lat']*1,
];
}
}
return $centers;
}
}