MapController.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace MapBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. class MapController extends Controller
  7. {
  8. /**
  9. * @param Request $request
  10. * @return JsonResponse
  11. */
  12. public function getMapListAction(Request $request)
  13. {
  14. $query = $request->query->get('q', '');
  15. $choiceLoader = $this->get('map.map.choiceloader');
  16. $choiceList = $choiceLoader->getChoicesList($query);
  17. $list_values = [];
  18. foreach ($choiceList as $label => $id) {
  19. $list_values[] = [
  20. 'id' => $id,
  21. 'text' => $label
  22. ];
  23. }
  24. $response = new JsonResponse();
  25. $response->setData(['results' => $list_values]);
  26. return $response;
  27. }
  28. /**
  29. * @param Request $request
  30. * @return JsonResponse
  31. */
  32. public function getMapAction(Request $request)
  33. {
  34. $id = $request->get('id', null);
  35. $map = '';
  36. if (!is_null($id)) {
  37. $webservice = $this->get('webservice');
  38. $map = $webservice->getArray('remote_get_map_url', array(
  39. 'id' => $id,
  40. ));
  41. if (isset($map[0])) {
  42. $map = $map[0];
  43. }
  44. }
  45. $response = new JsonResponse();
  46. $response->setData($map);
  47. return $response;
  48. }
  49. }