src/Aqarmap/Bundle/NeighborhoodBundle/Controller/Api/NeighborhoodController.php line 195

  1. $this->logger->debug('entered with request');
  2. /** @var \Doctrine\ORM\EntityManager $em */
  3. $em = $this->managerRegistry->getManager();
  4. $sections = json_decode($request->request->get('data'), 1);
  5. $this->sqlLoggerManager->disable($em);
  6. gc_collect_cycles();
  7. set_time_limit(0);
  8. $errors = [];
  9. $this->logger->debug('entered');
  10. if (is_array($sections) || is_object($sections)) {
  11. foreach ($sections as $sectionId => $section) {
  12. $this->logger->debug('entered loop');
  13. foreach ($section as $propertyTypeId => $propertyType) {
  14. foreach ($propertyType as $locationId => $data) {
  15. try {
  16. $this->messageBus->dispatch(new LocationStatisticsMessage(
  17. (int) $locationId,
  18. (int) $sectionId,
  19. (int) $propertyTypeId,
  20. $data,
  21. ));
  22. $this->logger->error('modular 0 ');
  23. } catch (\Exception $e) {
  24. $errors[] = $e->getMessage();
  25. }
  26. }
  27. }
  28. }
  29. if (!empty($errors)) {
  30. $this->logger->error('valuationerrors', $errors);
  31. return $this->respond(['errors' => $errors], Response::HTTP_INTERNAL_SERVER_ERROR);
  32. }
  33. }
  34. return $this->respond(true);
  35. }
  36. /**
  37. * Get Neighborhood First Level Locations Without Children.
  38. *
  39. * **Response Format**
  40. *
  41. * ```
  42. * {
  43. * "location":
  44. * {
  45. * "id": 1,
  46. * "title": "Cairo",
  47. * "description": "Cairo City",
  48. * "center_lat": 30.04841,
  49. * "center_lng": 31.23619,
  50. * "zoom_level": 10,
  51. * "searchable": true,
  52. * "home_filter": true,
  53. * "statistics_filter": true,
  54. * "neighborhood_filter": true,
  55. * }
  56. * {...
  57. * }
  58. * ]
  59. * },
  60. * {...
  61. * }
  62. * }
  63. * ```
  64. *
  65. * @return array
  66. */
  67. #[Rest\Get('/api/v2/neighborhood', options: ['i18n' => false], name: 'aqarmap_api_neighborhood_location')]
  68. #[Rest\View(serializerGroups: ['Default', 'Neighborhood'])]
  69. public function getNeighborhoodLocation()
  70. {
  71. /** @var \Doctrine\ORM\EntityManager $em */
  72. $em = $this->managerRegistry->getManager();
  73. $locations = $em->getRepository(Location::class)->getNeighbourhoodLocations(['level' => 0]);
  74. return [
  75. 'locations' => $locations,
  76. ];
  77. }
  78. /**
  79. * Get Neighborhood Location With Children.
  80. *
  81. * @return array
  82. */
  83. #[Rest\Get('/api/v2/neighborhood/{location}', options: ['i18n' => false], name: 'aqarmap_api_neighborhood_location_details')]
  84. #[Rest\View(serializerGroups: ['Default', 'Neighborhood'])]
  85. public function getNeighborhoodDetails(Location $location)
  86. {
  87. return [
  88. 'location' => $location,
  89. 'children' => $location->getNeighborhoodChildren(),
  90. ];
  91. }
  92. /**
  93. * Get Neighborhood History For Crm App.
  94. *
  95. * @return array
  96. */
  97. #[Rest\Get('/api/v2/neighborhood/{location}/history', options: ['i18n' => false], name: 'aqarmap_api_neighborhood_history_data')]
  98. #[Rest\View(serializerGroups: ['Default', 'NeighborhoodStatistics'])]
  99. public function getNeighborhoodHistory(Location $location)
  100. {
  101. $historyData = $this->neighborhoodManager->generateStatisticsHistoryData($location);
  102. foreach ($historyData['historyData'] as &$value) {
  103. $value['data']['average_price'] = array_values($value['data']['average_price']);
  104. $value['data']['demand_heat'] = array_values($value['data']['demand_heat']);
  105. $value['data']['growth'] = array_values($value['data']['growth']);
  106. }
  107. return [
  108. 'location' => $location,
  109. 'data' => $historyData['historyData'],
  110. ];
  111. }
  112. }