Commit 95607f5d authored by Andrea Ruggiero's avatar Andrea Ruggiero
Browse files

Improve

parent 0f763760
Pipeline #1552 failed with stage
in 0 seconds
......@@ -37,16 +37,9 @@ class EventController extends Controller
"end" => $event->end,
"type" => $event->type,
"theme" => $event->theme,
"bookings" => count($bookingRepository->getBookingsByEvent($event->event_id))
"bookings" => count($bookingRepository->getBookingsByEvent($event->event_id)),
"places" => $eventRepository->getPlaces($event, $placeRepository)
];
if ($event->place_id == null) {
$temp["place"] = "all";
} else {
$place = $placeRepository->getById($event->place_id);
$temp["place"] = $place->name;
$temp["capacity"] = $place->capacity;
}
if ($user !== null) {
$temp["hasBooked"] = $bookingRepository->getBookingByEventAndUser($user->user_id, $event->event_id) !== null;
......@@ -76,17 +69,10 @@ class EventController extends Controller
"end" => $event->end,
"type" => $event->type,
"theme" => $event->theme,
"bookings" => count($bookingRepository->getBookingsByEvent($event->event_id))
"bookings" => count($bookingRepository->getBookingsByEvent($event->event_id)),
"places" => $eventRepository->getPlaces($event, $placeRepository)
];
if ($event->place_id == null) {
$temp["place"] = "all";
} else {
$place = $placeRepository->getById($event->place_id);
$temp["place"] = $place->name;
$temp["capacity"] = $place->capacity;
}
$response[] = $temp;
}
......@@ -140,20 +126,10 @@ class EventController extends Controller
"end" => $event->end,
"type" => $event->type,
"theme" => $event->theme,
"bookings" => count($bookingRepository->getBookingsByEvent($event->event_id))
"bookings" => count($bookingRepository->getBookingsByEvent($event->event_id)),
"places" => $eventRepository->getPlaces($event, $placeRepository)
];
if ($event->place_id == null) {
$response["place"] = "all";
} else {
$place = $placeRepository->getById($event->place_id);
$response["place"] = $place->name;
$response["capacity"] = $place->capacity;
$response["latitude"] = $place->latitude;
$response["longitude"] = $place->longitude;
$response["address"] = $place->address;
}
if ($user !== null) {
$response["hasBooked"] = $bookingRepository->getBookingByEventAndUser($user->user_id, $event->event_id) !== null;
}
......
......@@ -12,4 +12,32 @@ class EventRepository extends BaseRepository
return $this->db()->where('event_id', $id)->first();
}
public function getPlaces($event, PlaceRepository $placeRepository) {
$events = $this->db()->where('name', $event->name)->where('date', $event->date)->where('start', $event->start)->where('end', $event->end)->get();
$places = [];
foreach ($events as $event) {
if ($event->place === null) {
return array_map(function($place) {
return [
"place" => $place->name,
"capacity" => $place->capacity,
"latitude" => $place->latitude,
"longitude" => $place->longitude,
"address" => $place->address
];
}, $placeRepository->all());
} else {
$place = $placeRepository->getById($event->event_id);
$places[] = [
"place" => $place->name,
"capacity" => $place->capacity,
"latitude" => $place->latitude,
"longitude" => $place->longitude,
"address" => $place->address
];
}
}
return $places;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment