getJSInitFile(); return $this->render('home.html.twig', $params); } 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); $lat = $coordinates->getLatitude(); $long = $coordinates->getLongitude(); $jo = $rider->getActiveJobOrder(); if ($jo == null) { $has_jo = false; $clat = 0; $clong = 0; $jo_data = []; } else { $has_jo = true; $cust_loc = $jo->getCoordinates(); $clat = $cust_loc->getLatitude(); $clong = $cust_loc->getLongitude(); $jo_id = $jo->getID(); $jo_data = [ 'id' => $jo_id, 'status' => $jo->getStatusText(), 'stype' => $jo->getServiceTypeName(), 'url' => $this->generateUrl('jo_all_form', ['id' => $jo_id]), 'plate' => $jo->getCustomerVehicle()->getPlateNumber(), 'cname' => $jo->getCustomer()->getNameDisplay(), ]; } // use rider map label as key $rider_map_label = $rider->getMapLabel(); $locations[$rider_id] = [ 'label' => $rider->getMapLabel(), 'loc' => [$lat, $long], 'has_jo' => $has_jo, 'cust_loc' => [$clat, $clong], 'jo' => $jo_data, ]; } return $this->json([ 'riders' => $locations, ]); } }