51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use Catalyst\MenuBundle\Annotation\Menu;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use App\Service\RiderTracker;
|
|
|
|
use App\Entity\Rider;
|
|
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
/**
|
|
* @Menu(selected="home")
|
|
*/
|
|
public function index(EntityManagerInterface $em, RiderTracker $rider_tracker)
|
|
{
|
|
return $this->render('home.html.twig');
|
|
}
|
|
|
|
public function getRiderLocations(EntityManagerInterface $em, RiderTracker $rider_tracker)
|
|
{
|
|
// get all riders
|
|
$riders = $em->getRepository(Rider::class)->findAll();
|
|
|
|
$locations = [];
|
|
foreach ($riders as $rider)
|
|
{
|
|
// get location for each rider
|
|
$rider_id = $rider->getID();
|
|
$coordinates = $rider_tracker->getRiderLocation($rider_id);
|
|
|
|
$long = $coordinates->getLongitude();
|
|
$lat = $coordinates->getLatitude();
|
|
|
|
// use rider map label as key
|
|
$rider_map_label = $rider->getMapLabel();
|
|
$locations[$rider_map_label] = array($lat, $long);
|
|
|
|
}
|
|
|
|
return $this->json([
|
|
'riders' => $locations,
|
|
]);
|
|
|
|
}
|
|
}
|