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

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