diff --git a/app/Events/BookableRooms/BookableRoomReservationAction.php b/app/Events/BookableRooms/BookableRoomReservationAction.php new file mode 100644 index 00000000..77315089 --- /dev/null +++ b/app/Events/BookableRooms/BookableRoomReservationAction.php @@ -0,0 +1,44 @@ +reservation_id = $reservation_id; + } + + /** + * @return int + */ + public function getReservationId(): int + { + return $this->reservation_id; + } +} \ No newline at end of file diff --git a/app/Events/BookableRooms/BookableRoomReservationRefundAccepted.php b/app/Events/BookableRooms/BookableRoomReservationRefundAccepted.php new file mode 100644 index 00000000..a2542338 --- /dev/null +++ b/app/Events/BookableRooms/BookableRoomReservationRefundAccepted.php @@ -0,0 +1,22 @@ + 'sometimes|url', 'secondary_registration_label' => 'sometimes|string', 'slug' => 'nullable|string', + 'meeting_room_booking_start_time' => 'nullable|date_format:U', + 'meeting_room_booking_end_time' => 'nullable|required_with:meeting_room_booking_end_time|date_format:U|after_or_equal:meeting_room_booking_end_time', + 'meeting_room_booking_slot_length' => 'nullable|integer', + 'meeting_room_booking_max_allowed' => 'nullable|integer|min:1', ]; } @@ -65,6 +69,10 @@ final class SummitValidationRulesFactory 'secondary_registration_link' => 'sometimes|url', 'secondary_registration_label' => 'sometimes|string', 'slug' => 'nullable|string', + 'meeting_room_booking_start_time' => 'nullable|date_format:U', + 'meeting_room_booking_end_time' => 'nullable|required_with:meeting_room_booking_end_time|date_format:U|after_or_equal:meeting_room_booking_end_time', + 'meeting_room_booking_slot_length' => 'nullable|integer', + 'meeting_room_booking_max_allowed' => 'nullable|integer|min:1', ]; } } \ No newline at end of file diff --git a/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitVenueBookableRoomValidationRulesFactory.php b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitVenueBookableRoomValidationRulesFactory.php new file mode 100644 index 00000000..07596051 --- /dev/null +++ b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitVenueBookableRoomValidationRulesFactory.php @@ -0,0 +1,36 @@ + 'required|integer:min:0', + 'time_slot_cost' => 'required|numeric', + 'currency' => 'required|string|currency_iso', + ], $rules); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitBookableRoomsAttributeTypeApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitBookableRoomsAttributeTypeApiController.php new file mode 100644 index 00000000..99565b27 --- /dev/null +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitBookableRoomsAttributeTypeApiController.php @@ -0,0 +1,592 @@ +attribute_type_repository = $attribute_type_repository; + $this->attribute_value_repository = $attribute_value_repository; + $this->summit_repository = $summit_repository; + $this->summit_service = $summit_service; + } + + /** + * @param $summit_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function getAllBookableRoomAttributeTypes($summit_id){ + $values = Input::all(); + $rules = [ + + 'page' => 'integer|min:1', + 'per_page' => sprintf('required_with:page|integer|min:%s|max:%s', PagingConstants::MinPageSize, PagingConstants::MaxPageSize), + ]; + + try { + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $validation = Validator::make($values, $rules); + + if ($validation->fails()) { + $ex = new ValidationException(); + throw $ex->setMessages($validation->messages()->toArray()); + } + + // default values + $page = 1; + $per_page = PagingConstants::DefaultPageSize; + + if (Input::has('page')) { + $page = intval(Input::get('page')); + $per_page = intval(Input::get('per_page')); + } + + $filter = null; + + if (Input::has('filter')) { + $filter = FilterParser::parse(Input::get('filter'), [ + 'type' => ['==', '=@'], + 'summit_id' => ['=='], + ]); + } + if(is_null($filter)) $filter = new Filter(); + + $filter->validate([ + 'type' => 'sometimes|string', + 'summit_id' => 'sometimes|integer', + ]); + + $order = null; + + if (Input::has('order')) + { + $order = OrderParser::parse(Input::get('order'), [ + 'id', + 'type', + ]); + } + + $filter->addFilterCondition(FilterElement::makeEqual("summit_id", $summit->getId())); + + $data = $this->attribute_type_repository->getAllByPage(new PagingInfo($page, $per_page), $filter, $order); + + return $this->ok + ( + $data->toArray + ( + Request::input('expand', ''), + [], + [], + [] + ) + ); + } + catch (ValidationException $ex1) + { + Log::warning($ex1); + return $this->error412(array( $ex1->getMessage())); + } + catch (EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message' => $ex2->getMessage())); + } + catch(\HTTP401UnauthorizedException $ex3) + { + Log::warning($ex3); + return $this->error401(); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function addBookableRoomAttributeType($summit_id){ + try { + if(!Request::isJson()) return $this->error400(); + $payload = Input::json()->all(); + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $rules = [ + 'type' => 'required|string', + ]; + + // Creates a Validator instance and validates the data. + $validation = Validator::make($payload, $rules); + + if ($validation->fails()) { + $messages = $validation->messages()->toArray(); + + return $this->error412 + ( + $messages + ); + } + + $attr = $this->summit_service->addBookableRoomAttribute($summit, $payload); + return $this->created(SerializerRegistry::getInstance()->getSerializer($attr)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $type_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function getBookableRoomAttributeType($summit_id, $type_id){ + try { + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $attr = $summit->getBookableAttributeTypeById($type_id); + if (is_null($attr)) return $this->error404(); + + return $this->ok(SerializerRegistry::getInstance()->getSerializer($attr)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + /** + * @param $summit_id + * @param $type_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function updateBookableRoomAttributeType($summit_id, $type_id){ + try { + if(!Request::isJson()) return $this->error400(); + $payload = Input::json()->all(); + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $rules = [ + 'type' => 'required|string', + ]; + + // Creates a Validator instance and validates the data. + $validation = Validator::make($payload, $rules); + + if ($validation->fails()) { + $messages = $validation->messages()->toArray(); + + return $this->error412 + ( + $messages + ); + } + + $attr = $this->summit_service->updateBookableRoomAttribute($summit, $type_id, $payload); + return $this->updated(SerializerRegistry::getInstance()->getSerializer($attr)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $type_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function deleteBookableRoomAttributeType($summit_id, $type_id){ + try { + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $this->summit_service->deleteBookableRoomAttribute($summit, $type_id); + return $this->deleted(); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + // values + + /** + * @param $summit_id + * @param $type_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function getAllBookableRoomAttributeValues($summit_id, $type_id){ + $values = Input::all(); + $rules = [ + + 'page' => 'integer|min:1', + 'per_page' => sprintf('required_with:page|integer|min:%s|max:%s', PagingConstants::MinPageSize, PagingConstants::MaxPageSize), + ]; + + try { + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $attr = $summit->getBookableAttributeTypeById($type_id); + if (is_null($attr)) return $this->error404(); + + $validation = Validator::make($values, $rules); + + if ($validation->fails()) { + $ex = new ValidationException(); + throw $ex->setMessages($validation->messages()->toArray()); + } + + // default values + $page = 1; + $per_page = PagingConstants::DefaultPageSize; + + if (Input::has('page')) { + $page = intval(Input::get('page')); + $per_page = intval(Input::get('per_page')); + } + + $filter = null; + + if (Input::has('filter')) { + $filter = FilterParser::parse(Input::get('filter'), [ + 'value' => ['==', '=@'], + 'summit_id' => ['=='], + 'type_id' => ['=='], + ]); + } + if(is_null($filter)) $filter = new Filter(); + + $filter->validate([ + 'value' => 'sometimes|string', + 'summit_id' => 'sometimes|integer', + 'type_id' => 'sometimes|integer', + ]); + + $order = null; + + if (Input::has('order')) + { + $order = OrderParser::parse(Input::get('order'), [ + 'id', + 'value', + ]); + } + + $filter->addFilterCondition(FilterElement::makeEqual("summit_id", $summit->getId())); + $filter->addFilterCondition(FilterElement::makeEqual("type_id", $attr->getId())); + + $data = $this->attribute_value_repository->getAllByPage(new PagingInfo($page, $per_page), $filter, $order); + + return $this->ok + ( + $data->toArray + ( + Request::input('expand', ''), + [], + [], + [] + ) + ); + } + catch (ValidationException $ex1) + { + Log::warning($ex1); + return $this->error412(array( $ex1->getMessage())); + } + catch (EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message' => $ex2->getMessage())); + } + catch(\HTTP401UnauthorizedException $ex3) + { + Log::warning($ex3); + return $this->error401(); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $type_id + * @param $value_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function getBookableRoomAttributeValue($summit_id, $type_id, $value_id){ + try { + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $attr = $summit->getBookableAttributeTypeById($type_id); + if (is_null($attr)) return $this->error404(); + + $value = $attr->getValueById($value_id); + if (is_null($value)) return $this->error404(); + + return $this->ok(SerializerRegistry::getInstance()->getSerializer($value)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $type_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function addBookableRoomAttributeValue($summit_id, $type_id){ + try { + if(!Request::isJson()) return $this->error400(); + $payload = Input::json()->all(); + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $rules = [ + 'value' => 'required|string', + ]; + + // Creates a Validator instance and validates the data. + $validation = Validator::make($payload, $rules); + + if ($validation->fails()) { + $messages = $validation->messages()->toArray(); + + return $this->error412 + ( + $messages + ); + } + + $value = $this->summit_service->addBookableRoomAttributeValue($summit, $type_id, $payload); + return $this->created(SerializerRegistry::getInstance()->getSerializer($value)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $type_id + * @param $value_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function updateBookableRoomAttributeValue($summit_id, $type_id, $value_id){ + try { + if(!Request::isJson()) return $this->error400(); + $payload = Input::json()->all(); + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $rules = [ + 'value' => 'required|string', + ]; + + // Creates a Validator instance and validates the data. + $validation = Validator::make($payload, $rules); + + if ($validation->fails()) { + $messages = $validation->messages()->toArray(); + + return $this->error412 + ( + $messages + ); + } + + $value = $this->summit_service->updateBookableRoomAttributeValue($summit, $type_id, $value_id, $payload); + return $this->updated(SerializerRegistry::getInstance()->getSerializer($value)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $type_id + * @param $value_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function deleteBookableRoomAttributeValue($summit_id, $type_id, $value_id){ + try { + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $this->summit_service->deleteBookableRoomAttributeValue($summit, $type_id, $value_id); + return $this->deleted(); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitLocationsApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitLocationsApiController.php index e376bfa7..b3de31fd 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitLocationsApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitLocationsApiController.php @@ -16,6 +16,7 @@ use App\Models\Foundation\Summit\Locations\Banners\SummitLocationBannerConstants use App\Models\Foundation\Summit\Locations\SummitLocationConstants; use App\Models\Foundation\Summit\Repositories\ISummitLocationBannerRepository; use App\Models\Foundation\Summit\Repositories\ISummitLocationRepository; +use App\Models\Foundation\Summit\Repositories\ISummitRoomReservationRepository; use App\Services\Apis\IPaymentGatewayAPI; use App\Services\Model\ILocationService; use Exception; @@ -99,6 +100,11 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController */ private $payment_gateway; + /** + * @var ISummitRoomReservationRepository + */ + private $reservation_repository; + /** * OAuth2SummitLocationsApiController constructor. * @param ISummitRepository $summit_repository @@ -108,6 +114,7 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController * @param ISummitLocationRepository $location_repository * @param ISummitLocationBannerRepository $location_banners_repository * @param IMemberRepository $member_repository + * @param ISummitRoomReservationRepository $reservation_repository * @param ISummitService $summit_service * @param ILocationService $location_service * @param IPaymentGatewayAPI $payment_gateway @@ -122,6 +129,7 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController ISummitLocationRepository $location_repository, ISummitLocationBannerRepository $location_banners_repository, IMemberRepository $member_repository, + ISummitRoomReservationRepository $reservation_repository, ISummitService $summit_service, ILocationService $location_service, IPaymentGatewayAPI $payment_gateway, @@ -138,6 +146,7 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController $this->location_service = $location_service; $this->summit_service = $summit_service; $this->payment_gateway = $payment_gateway; + $this->reservation_repository = $reservation_repository; } /** @@ -656,7 +665,6 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController return $this->error404(); } - $room = $venue->getRoom($room_id); if (is_null($room)) { diff --git a/app/Http/Controllers/Apis/Protected/Summit/Traits/SummitBookableVenueRoomApi.php b/app/Http/Controllers/Apis/Protected/Summit/Traits/SummitBookableVenueRoomApi.php index 56492b8d..52e9bf9c 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/Traits/SummitBookableVenueRoomApi.php +++ b/app/Http/Controllers/Apis/Protected/Summit/Traits/SummitBookableVenueRoomApi.php @@ -21,8 +21,11 @@ use models\exceptions\EntityNotFoundException; use models\exceptions\ValidationException; use models\summit\SummitBookableVenueRoom; use models\summit\SummitBookableVenueRoomAvailableSlot; +use models\summit\SummitRoomReservation; +use models\summit\SummitVenue; use ModelSerializers\SerializerRegistry; use utils\Filter; +use utils\FilterElement; use utils\FilterParser; use utils\OrderParser; use utils\PagingInfo; @@ -134,8 +137,163 @@ trait SummitBookableVenueRoomApi } } - public function getBookableVenueRoom($summit_id, $room_id){ + /** + * @param $summit_id + * @return mixed + */ + public function getAllReservationsBySummit($summit_id){ + $values = Input::all(); + $rules = [ + 'page' => 'integer|min:1', + 'per_page' => sprintf('required_with:page|integer|min:%s|max:%s', PagingConstants::MinPageSize, PagingConstants::MaxPageSize), + ]; + + try { + + $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $validation = Validator::make($values, $rules); + + if ($validation->fails()) { + $ex = new ValidationException(); + throw $ex->setMessages($validation->messages()->toArray()); + } + + // default values + $page = 1; + $per_page = PagingConstants::DefaultPageSize; + + if (Input::has('page')) { + $page = intval(Input::get('page')); + $per_page = intval(Input::get('per_page')); + } + + $filter = null; + + if (Input::has('filter')) { + $filter = FilterParser::parse(Input::get('filter'), [ + 'summit_id' => ['=='], + 'room_name' => ['==', '=@'], + 'room_id' => ['=='], + 'owner_id' => ['=='], + 'status' => ['=='], + 'start_datetime' => ['>', '<', '<=', '>=', '=='], + 'end_datetime' => ['>', '<', '<=', '>=', '=='], + ]); + } + if(is_null($filter)) $filter = new Filter(); + + $filter->validate([ + 'status' => sprintf('sometimes|in:%s',implode(',', SummitRoomReservation::$valid_status)), + 'room_name' => 'sometimes|string', + 'summit_id' => 'sometimes|integer', + 'room_id' => 'sometimes|integer', + 'owner_id' => 'sometimes|string', + 'start_datetime' => 'sometimes|required|date_format:U', + 'end_datetime' => 'sometimes|required_with:start_datetime|date_format:U|after:start_datetime', + + ], [ + 'status.in' => sprintf + ( + ":attribute has an invalid value ( valid values are %s )", + implode(", ", SummitRoomReservation::$valid_status) + ) + ]); + + $order = null; + + if (Input::has('order')) + { + $order = OrderParser::parse(Input::get('order'), [ + 'id', + 'start_datetime', + 'end_datetime', + ]); + } + + + $data = $this->reservation_repository->getAllBySummitByPage($summit, new PagingInfo($page, $per_page), $filter, $order); + + return $this->ok + ( + $data->toArray + ( + Request::input('expand', ''), + [], + [], + [] + ) + ); + } + catch (ValidationException $ex1) + { + Log::warning($ex1); + return $this->error412(array( $ex1->getMessage())); + } + catch (EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message' => $ex2->getMessage())); + } + catch(\HTTP401UnauthorizedException $ex3) + { + Log::warning($ex3); + return $this->error401(); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + /** + * @param $summit_id + * @param $venue_id + * @param $room_id + * @return mixed + */ + public function getBookableVenueRoom($summit_id, $venue_id, $room_id){ + try { + + $expand = Request::input('expand', ''); + $relations = Request::input('relations', ''); + $relations = !empty($relations) ? explode(',', $relations) : []; + + $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $venue = $summit->getLocation($venue_id); + + if (is_null($venue)) { + return $this->error404(); + } + + if (!$venue instanceof SummitVenue) { + return $this->error404(); + } + + $room = $venue->getRoom($room_id); + + if (is_null($room) || !$room instanceof SummitBookableVenueRoom) { + return $this->error404(); + } + + return $this->ok(SerializerRegistry::getInstance()->getSerializer($room)->serialize($expand,[], $relations)); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } } /** @@ -337,9 +495,9 @@ trait SummitBookableVenueRoomApi if(is_null($member)) return $this->error403(); - $this->location_service->cancelReservation($summit, $member, $reservation_id); + $reservation = $this->location_service->cancelReservation($summit, $member, $reservation_id); - return $this->deleted(); + return $this->updated(SerializerRegistry::getInstance()->getSerializer($reservation)->serialize()); } catch (ValidationException $ex1) { @@ -382,4 +540,323 @@ trait SummitBookableVenueRoomApi } return $this->error400(["error" => 'invalid event type']); } + + /** + * @param $summit_id + * @param $venue_id + * @param $room_id + * @return mixed + */ + public function updateVenueBookableRoom($summit_id, $venue_id, $room_id){ + try { + if(!Request::isJson()) return $this->error400(); + $payload = Input::json()->all(); + $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + $payload['class_name'] = SummitBookableVenueRoom::ClassName; + $rules = SummitLocationValidationRulesFactory::build($payload, true); + // Creates a Validator instance and validates the data. + $validation = Validator::make($payload, $rules); + + if ($validation->fails()) { + $messages = $validation->messages()->toArray(); + + return $this->error412 + ( + $messages + ); + } + + $room = $this->location_service->updateVenueBookableRoom($summit, $venue_id, $room_id, $payload); + + return $this->created(SerializerRegistry::getInstance()->getSerializer($room)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $venue_id + * @param $floor_id + * @param $room_id + * @return mixed + */ + public function updateVenueFloorBookableRoom($summit_id, $venue_id, $floor_id, $room_id){ + try { + if(!Request::isJson()) return $this->error400(); + $payload = Input::json()->all(); + $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + $payload['class_name'] = SummitBookableVenueRoom::ClassName; + $rules = SummitLocationValidationRulesFactory::build($payload, true); + // Creates a Validator instance and validates the data. + $validation = Validator::make($payload, $rules); + + if ($validation->fails()) { + $messages = $validation->messages()->toArray(); + + return $this->error412 + ( + $messages + ); + } + + if(!isset($payload['floor_id'])) + $payload['floor_id'] = intval($floor_id); + + $room = $this->location_service->updateVenueBookableRoom($summit, $venue_id, $room_id, $payload); + + return $this->created(SerializerRegistry::getInstance()->getSerializer($room)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + public function deleteVenueBookableRoom($summit_id, $venue_id, $room_id){ + try { + + $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $this->location_service->deleteVenueBookableRoom($summit, $venue_id, $room_id); + + return $this->deleted(); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $venue_id + * @return mixed + */ + public function addVenueBookableRoom($summit_id, $venue_id){ + try { + if(!Request::isJson()) return $this->error400(); + $payload = Input::json()->all(); + $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + $payload['class_name'] = SummitBookableVenueRoom::ClassName; + $rules = SummitLocationValidationRulesFactory::build($payload); + // Creates a Validator instance and validates the data. + $validation = Validator::make($payload, $rules); + + if ($validation->fails()) { + $messages = $validation->messages()->toArray(); + + return $this->error412 + ( + $messages + ); + } + + $room = $this->location_service->addVenueBookableRoom($summit, $venue_id, $payload); + + return $this->created(SerializerRegistry::getInstance()->getSerializer($room)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $venue_id + * @return mixed + */ + public function addVenueFloorBookableRoom($summit_id, $venue_id, $floor_id){ + try { + if(!Request::isJson()) return $this->error400(); + $payload = Input::json()->all(); + $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + $payload['class_name'] = SummitBookableVenueRoom::ClassName; + $rules = SummitLocationValidationRulesFactory::build($payload); + // Creates a Validator instance and validates the data. + $validation = Validator::make($payload, $rules); + + if ($validation->fails()) { + $messages = $validation->messages()->toArray(); + + return $this->error412 + ( + $messages + ); + } + + $payload['floor_id'] = intval($floor_id); + + $room = $this->location_service->addVenueBookableRoom($summit, $venue_id, $payload); + + return $this->created(SerializerRegistry::getInstance()->getSerializer($room)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $venue_id + * @param $room_id + * @param $attribute_id + * @return mixed + */ + public function addVenueBookableRoomAttribute($summit_id, $venue_id, $room_id, $attribute_id){ + try { + + $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $room = $this->location_service->addVenueBookableRoomAttribute($summit, $venue_id, $room_id, $attribute_id); + + return $this->created(SerializerRegistry::getInstance()->getSerializer($room)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + /** + * @param $summit_id + * @param $venue_id + * @param $room_id + * @param $attribute_id + * @return mixed + */ + public function deleteVenueBookableRoomAttribute($summit_id, $venue_id, $room_id, $attribute_id){ + try { + $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $room = $this->location_service->deleteVenueBookableRoomAttribute($summit, $venue_id, $room_id, $attribute_id); + + return $this->deleted(SerializerRegistry::getInstance()->getSerializer($room)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + + public function refundBookableVenueRoomReservation($summit_id, $room_id, $reservation_id){ + try { + if(!Request::isJson()) return $this->error400(); + $payload = Input::json()->all(); + $rules = [ + 'amount' => 'required|numeric', + ]; + + // Creates a Validator instance and validates the data. + $validation = Validator::make($payload, $rules); + + if ($validation->fails()) { + $messages = $validation->messages()->toArray(); + + return $this->error412 + ( + $messages + ); + } + + $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $room = $summit->getLocation($room_id); + if (is_null($room)) return $this->error404(); + if (!$room instanceof SummitBookableVenueRoom) return $this->error404(); + + $amount = intval($payload['amount']); + $reservation = $this->location_service->refundReservation($room, $reservation_id, $amount); + + return $this->updateVenueBookableRoom(SerializerRegistry::getInstance()->getSerializer($reservation)->serialize()); + } + catch (ValidationException $ex1) { + Log::warning($ex1); + return $this->error412(array($ex1->getMessage())); + } + catch(EntityNotFoundException $ex2) + { + Log::warning($ex2); + return $this->error404(array('message'=> $ex2->getMessage())); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } } \ No newline at end of file diff --git a/app/Http/Utils/Filters/DoctrineJoinFilterMapping.php b/app/Http/Utils/Filters/DoctrineJoinFilterMapping.php index 5d9dd396..6ee504bb 100644 --- a/app/Http/Utils/Filters/DoctrineJoinFilterMapping.php +++ b/app/Http/Utils/Filters/DoctrineJoinFilterMapping.php @@ -11,10 +11,8 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ - use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; - /** * Class DoctrineJoinFilterMapping * @package utils diff --git a/app/Http/routes.php b/app/Http/routes.php index 746f7378..486b809b 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -319,15 +319,17 @@ Route::group([ // bookable-rooms Route::group(['prefix' => 'bookable-rooms'], function () { - // GET /api/v1/summits/{id}/bookable-rooms + // GET /api/v1/summits/{id}/locations/bookable-rooms Route::get('', 'OAuth2SummitLocationsApiController@getBookableVenueRooms'); Route::group(['prefix' => 'all'], function () { Route::group(['prefix' => 'reservations'], function () { - // GET /api/v1/summits/{id}/bookable-rooms/all/reservations/me + // GET /api/v1/summits/{id}/locations/bookable-rooms/all/reservations + Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@getAllReservationsBySummit']); + // GET /api/v1/summits/{id}/locations/bookable-rooms/all/reservations/me Route::get('me', 'OAuth2SummitLocationsApiController@getMyBookableVenueRoomReservations'); Route::group(['prefix' => '{reservation_id}'], function () { - // DELETE /api/v1/summits/{id}/bookable-rooms/all/reservations/{reservation_id} + // DELETE /api/v1/summits/{id}/locations/bookable-rooms/all/reservations/{reservation_id} Route::delete('', 'OAuth2SummitLocationsApiController@cancelMyBookableVenueRoomReservation'); }); }); @@ -338,9 +340,17 @@ Route::group([ Route::get('', 'OAuth2SummitLocationsApiController@getBookableVenueRoom'); // GET /api/v1/summits/{id}/locations/bookable-rooms/{room_id}/availability/{day} Route::get('availability/{day}', 'OAuth2SummitLocationsApiController@getBookableVenueRoomAvailability'); + Route::group(['prefix' => 'reservations'], function () { // POST /api/v1/summits/{id}/locations/bookable-rooms/{room_id}/reservations Route::post('', 'OAuth2SummitLocationsApiController@createBookableVenueRoomReservation'); + + Route::group(['prefix' => '{reservation_id}'], function () { + // GET /api/v1/summits/{id}/bookable-rooms/{room_id}/reservations/{reservation_id} + Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@getBookableVenueRoomReservation']); + // DELETE /api/v1/summits/{id}/bookable-rooms/{room_id}/reservations/{reservation_id}/refund + Route::delete('refund', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@refundBookableVenueRoomReservation']); + }); }); }); @@ -368,14 +378,25 @@ Route::group([ // bookable-rooms Route::group(['prefix' => 'bookable-rooms'], function () { // POST /api/v1/summits/{id}/locations/venues/{venue_id}/bookable-rooms - Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@addBookableVenueRoom']); + Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@addVenueBookableRoom']); Route::group(['prefix' => '{room_id}'], function () { // GET /api/v1/summits/{id}/locations/venues/{venue_id}/bookable-rooms/{room_id} Route::get('', 'OAuth2SummitLocationsApiController@getBookableVenueRoom'); // PUT /api/v1/summits/{id}/locations/venues/{venue_id}/bookable-rooms/{room_id} - Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@updateBookableVenueRoom']); + Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@updateVenueBookableRoom']); // DELETE /api/v1/summits/{id}/locations/venues/{venue_id}/bookable-rooms/{room_id} - Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@deleteBookableVenueRoom']); + Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@deleteVenueBookableRoom']); + // attributes + + Route::group(['prefix' => 'attributes'], function () { + Route::group(['prefix' => '{attribute_id}'], function () { + // PUT /api/v1/summits/{id}/locations/venues/{venue_id}/bookable-rooms/{room_id}/attributes/{attribute_id} + Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@addVenueBookableRoomAttribute']); + // DELETE /api/v1/summits/{id}/locations/venues/{venue_id}/bookable-rooms/{room_id}/attributes/{attribute_id} + Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitLocationsApiController@deleteVenueBookableRoomAttribute']); + }); + + }); }); }); @@ -460,6 +481,26 @@ Route::group([ }); }); + // bookable rooms attributes + Route::group(['prefix' => 'bookable-room-attribute-types'], function () { + Route::get('', 'OAuth2SummitBookableRoomsAttributeTypeApiController@getAllBookableRoomAttributeTypes'); + Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitBookableRoomsAttributeTypeApiController@addBookableRoomAttributeType']); + Route::group(['prefix' => '{type_id}'], function () { + Route::get('', 'OAuth2SummitLocationsApiController@getBookableRoomAttributeType'); + Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitBookableRoomsAttributeTypeApiController@updateBookableRoomAttributeType']); + Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitBookableRoomsAttributeTypeApiController@deleteBookableRoomAttributeType']); + Route::group(['prefix' => 'values'], function () { + Route::get('', 'OAuth2SummitBookableRoomsAttributeTypeApiController@getAllBookableRoomAttributeValues'); + Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitBookableRoomsAttributeTypeApiController@addBookableRoomAttributeValue']); + Route::group(['prefix' => '{value_id}'], function () { + Route::get('', 'OAuth2SummitLocationsApiController@getBookableRoomAttributeValue'); + Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitBookableRoomsAttributeTypeApiController@updateBookableRoomAttributeValue']); + Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitBookableRoomsAttributeTypeApiController@udeleteBookableRoomAttributeValue']); + }); + }); + }); + }); + // event types Route::group(['prefix' => 'event-types'], function () { Route::get('', 'OAuth2SummitsEventTypesApiController@getAllBySummit'); diff --git a/app/ModelSerializers/Locations/SummitBookableVenueRoomAttributeTypeSerializer.php b/app/ModelSerializers/Locations/SummitBookableVenueRoomAttributeTypeSerializer.php index af7fb253..93c8fcbd 100644 --- a/app/ModelSerializers/Locations/SummitBookableVenueRoomAttributeTypeSerializer.php +++ b/app/ModelSerializers/Locations/SummitBookableVenueRoomAttributeTypeSerializer.php @@ -11,6 +11,8 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +use models\summit\SummitBookableVenueRoomAttributeType; +use ModelSerializers\SerializerRegistry; use ModelSerializers\SilverStripeSerializer; /** * Class SummitBookableVenueRoomAttributeTypeSerializer @@ -22,4 +24,36 @@ class SummitBookableVenueRoomAttributeTypeSerializer extends SilverStripeSeriali 'Type' => 'type:json_string', 'SummitId' => 'summit_id:json_int', ]; + + public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array() ) + { + $attr_type = $this->object; + if(!$attr_type instanceof SummitBookableVenueRoomAttributeType) + return []; + + $values = parent::serialize($expand, $fields, $relations, $params); + $attr_values = []; + foreach ($attr_type->getValues() as $attr_val){ + $attr_values[] = $attr_val->getId(); + } + $values['values'] = $attr_values; + if (!empty($expand)) { + $exp_expand = explode(',', $expand); + foreach ($exp_expand as $relation) { + switch (trim($relation)) { + case 'values': { + unset($values['values']); + $attr_values = []; + foreach ($attr_type->getValues() as $attr_val){ + $attr_values[] = SerializerRegistry::getInstance()->getSerializer($attr_val)->serialize(); + } + $values['values'] = $attr_values; + } + break; + + } + } + } + return $values; + } } \ No newline at end of file diff --git a/app/ModelSerializers/Summit/SummitSerializer.php b/app/ModelSerializers/Summit/SummitSerializer.php index cf87a2f2..20422dd7 100644 --- a/app/ModelSerializers/Summit/SummitSerializer.php +++ b/app/ModelSerializers/Summit/SummitSerializer.php @@ -52,6 +52,7 @@ class SummitSerializer extends SilverStripeSerializer 'SecondaryRegistrationLink' => 'secondary_registration_link:json_string', 'SecondaryRegistrationLabel' => 'secondary_registration_label:json_string', 'RawSlug' => 'slug:json_string', + // Bookable rooms attributes 'MeetingRoomBookingStartTime' => 'meeting_room_booking_start_time:datetime_epoch', 'MeetingRoomBookingEndTime' => 'meeting_room_booking_end_time:datetime_epoch', 'MeetingRoomBookingSlotLength' => 'meeting_room_booking_slot_length:json_int', diff --git a/app/Models/Foundation/Main/Member.php b/app/Models/Foundation/Main/Member.php index 7847ef5d..4237afd3 100644 --- a/app/Models/Foundation/Main/Member.php +++ b/app/Models/Foundation/Main/Member.php @@ -1150,6 +1150,17 @@ SQL; return $this->reservations; } + /** + * @param Summit $summit + * @return int + * @throws NoResultException + * @throws NonUniqueResultException + */ + public function getReservationsCountBySummit(Summit $summit):int{ + $query = $this->createQuery("SELECT count(rv.id) from models\summit\SummitRoomReservation rv JOIN rv.room r JOIN r.venue v JOIN v.summit s WHERE s.id = :summit_id"); + return $query->setParameter('summit_id', $summit->getId())->getSingleResult(); + } + /** * @param int $reservation_id * @return SummitRoomReservation diff --git a/app/Models/Foundation/Summit/Factories/SummitFactory.php b/app/Models/Foundation/Summit/Factories/SummitFactory.php index ffc05851..4a4140ce 100644 --- a/app/Models/Foundation/Summit/Factories/SummitFactory.php +++ b/app/Models/Foundation/Summit/Factories/SummitFactory.php @@ -149,6 +149,30 @@ final class SummitFactory $summit->setSecondaryRegistrationLabel(trim($data['secondary_registration_label'])); } + if(isset($data['meeting_room_booking_start_time']) ){ + // no need to convert to UTC, its only relative time + $meeting_room_booking_start_time = intval($data['meeting_room_booking_start_time']); + $meeting_room_booking_start_time = new \DateTime("@$meeting_room_booking_start_time"); + $summit->setMeetingRoomBookingStartTime($meeting_room_booking_start_time); + } + + if(isset($data['meeting_room_booking_end_time']) ){ + // no need to convert to UTC, its only relative time + $meeting_room_booking_end_time = intval($data['meeting_room_booking_end_time']); + $meeting_room_booking_end_time = new \DateTime("@$meeting_room_booking_end_time"); + $summit->setMeetingRoomBookingEndTime($meeting_room_booking_end_time); + } + + if(isset($data['meeting_room_booking_slot_length']) ){ + // minutes + $summit->setMeetingRoomBookingSlotLength(intval($data['meeting_room_booking_slot_length'])); + } + + if(isset($data['meeting_room_booking_max_allowed']) ){ + // maximun books per user + $summit->setMeetingRoomBookingMaxAllowed(intval($data['meeting_room_booking_max_allowed'])); + } + return $summit; } } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Factories/SummitLocationFactory.php b/app/Models/Foundation/Summit/Factories/SummitLocationFactory.php index c0066d91..b641df49 100644 --- a/app/Models/Foundation/Summit/Factories/SummitLocationFactory.php +++ b/app/Models/Foundation/Summit/Factories/SummitLocationFactory.php @@ -14,12 +14,12 @@ use models\exceptions\ValidationException; use models\summit\SummitAbstractLocation; use models\summit\SummitAirport; +use models\summit\SummitBookableVenueRoom; use models\summit\SummitExternalLocation; use models\summit\SummitGeoLocatedLocation; use models\summit\SummitHotel; use models\summit\SummitVenue; use models\summit\SummitVenueRoom; - /** * Class SummitLocationFactory * @package App\Models\Foundation\Summit\Factories @@ -50,6 +50,11 @@ final class SummitLocationFactory case SummitAirport::ClassName :{ $location = self::populateSummitAirport(new SummitAirport, $data); } + break; + case SummitBookableVenueRoom::ClassName :{ + $location = self::populateSummitVenueBookableRoom(new SummitBookableVenueRoom, $data); + } + break; case SummitVenueRoom::ClassName :{ $location = self::populateSummitVenueRoom(new SummitVenueRoom, $data); } @@ -207,6 +212,11 @@ final class SummitLocationFactory return $airport; } + /** + * @param SummitVenueRoom $room + * @param array $data + * @return SummitVenueRoom + */ public static function populateSummitVenueRoom(SummitVenueRoom $room, array $data){ self::populateSummitAbstractLocation($room, $data); @@ -220,6 +230,25 @@ final class SummitLocationFactory return $room; } + /** + * @param SummitBookableVenueRoom $room + * @param array $data + * @return SummitBookableVenueRoom + */ + public static function populateSummitVenueBookableRoom(SummitBookableVenueRoom $room, array $data){ + + self::populateSummitVenueRoom($room, $data); + + if(isset($data['time_slot_cost'])) + $room->setTimeSlotCost(floatval($data['time_slot_cost'])); + + if(isset($data['currency'])) + $room->setCurrency(trim($data['currency'])); + + return $room; + } + + /** * @param SummitAbstractLocation $location * @param array $data @@ -238,6 +267,9 @@ final class SummitLocationFactory if($location instanceof SummitExternalLocation){ return self::populateSummitExternalLocation($location, $data); } + if($location instanceof SummitBookableVenueRoom){ + return self::populateSummitVenueBookableRoom($location, $data); + } if($location instanceof SummitVenueRoom){ return self::populateSummitVenueRoom($location, $data); } diff --git a/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoom.php b/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoom.php index a33a3ac8..b7565bda 100644 --- a/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoom.php +++ b/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoom.php @@ -66,6 +66,7 @@ class SummitBookableVenueRoom extends SummitVenueRoom * @throws ValidationException */ public function addReservation(SummitRoomReservation $reservation){ + $criteria = Criteria::create(); $start_date = $reservation->getStartDatetime(); @@ -87,7 +88,7 @@ class SummitBookableVenueRoom extends SummitVenueRoom if($this->reservations->matching($criteria)->count() > 0) throw new ValidationException(sprintf("reservation overlaps an existent reservation")); - $summit = $this->summit; + $summit = $this->summit; $local_start_date = $summit->convertDateFromUTC2TimeZone($start_date); $local_end_date = $summit->convertDateFromUTC2TimeZone($end_date); @@ -96,6 +97,7 @@ class SummitBookableVenueRoom extends SummitVenueRoom if(!$summit->isTimeFrameInsideSummitDuration($local_start_date, $local_end_date)) throw new ValidationException("requested reservation period does not belong to summit period"); + $local_start_time = new \DateTime("now", $this->summit->getTimeZone()); $local_start_time->setTime( intval($start_time->format("H")), @@ -162,6 +164,17 @@ class SummitBookableVenueRoom extends SummitVenueRoom return $this->reservations; } + /** + * @param int $id + * @return SummitRoomReservation|null + */ + public function getReservationById(int $id):?SummitRoomReservation{ + $criteria = Criteria::create(); + $criteria->where(Criteria::expr()->eq('id', intval($id))); + $reservation = $this->reservations->matching($criteria)->first(); + return $reservation === false ? null : $reservation; + } + public function clearReservations(){ $this->reservations->clear(); } @@ -276,5 +289,20 @@ class SummitBookableVenueRoom extends SummitVenueRoom return $this->attributes; } + /** + * @param SummitBookableVenueRoomAttributeValue $attribute + */ + public function addAttribute(SummitBookableVenueRoomAttributeValue $attribute){ + if($this->attributes->contains($attribute)) return; + $this->attributes->add($attribute); + } + + /** + * @param SummitBookableVenueRoomAttributeValue $attribute + */ + public function removeAttribute(SummitBookableVenueRoomAttributeValue $attribute){ + if(!$this->attributes->contains($attribute)) return; + $this->attributes->removeElement($attribute); + } } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoomAttributeType.php b/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoomAttributeType.php index d4411752..03ea3749 100644 --- a/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoomAttributeType.php +++ b/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoomAttributeType.php @@ -18,7 +18,7 @@ use models\exceptions\ValidationException; use models\summit\SummitOwned; use models\utils\SilverstripeBaseModel; /** - * @ORM\Entity + * @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineSummitBookableVenueRoomAttributeTypeRepository") * @ORM\Table(name="SummitBookableVenueRoomAttributeType") * @ORM\AssociationOverrides({ * @ORM\AssociationOverride( @@ -67,19 +67,45 @@ class SummitBookableVenueRoomAttributeType extends SilverstripeBaseModel $this->type = $type; } - /** - * @return ArrayCollection - */ - public function getValues(): ArrayCollection + public function getValues() { return $this->values; } - /** - * @param ArrayCollection $values - */ - public function setValues(ArrayCollection $values): void - { - $this->values = $values; + public function addValue(SummitBookableVenueRoomAttributeValue $value){ + if($this->values->contains($value)) return; + $this->values->add($value); + $value->setType($this); } + + public function removeValue(SummitBookableVenueRoomAttributeValue $value){ + if(!$this->values->contains($value)) return; + $this->values->removeElement($value); + } + + /** + * @param int $id + * @return SummitBookableVenueRoomAttributeValue|null + */ + public function getValueById(int $id):?SummitBookableVenueRoomAttributeValue + { + $criteria = Criteria::create(); + $criteria->where(Criteria::expr()->eq('id', intval($id))); + $value = $this->values->matching($criteria)->first(); + return $value === false ? null : $value; + } + + + /** + * @param string $value + * @return SummitBookableVenueRoomAttributeValue|null + */ + public function getValueByValue(string $value):?SummitBookableVenueRoomAttributeValue + { + $criteria = Criteria::create(); + $criteria->where(Criteria::expr()->eq('value', trim($value))); + $value = $this->values->matching($criteria)->first(); + return $value === false ? null : $value; + } + } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoomAttributeValue.php b/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoomAttributeValue.php index 27d2b623..05b16aa7 100644 --- a/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoomAttributeValue.php +++ b/app/Models/Foundation/Summit/Locations/SummitBookableVenueRoomAttributeValue.php @@ -17,7 +17,7 @@ use Doctrine\ORM\Mapping AS ORM; use models\exceptions\ValidationException; use models\utils\SilverstripeBaseModel; /** - * @ORM\Entity + * @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineSummitBookableVenueRoomAttributeValueRepository") * @ORM\Table(name="SummitBookableVenueRoomAttributeValue") * Class SummitBookableVenueRoomAttributeValue * @package models\summit diff --git a/app/Models/Foundation/Summit/Locations/SummitLocationConstants.php b/app/Models/Foundation/Summit/Locations/SummitLocationConstants.php index 05233f9a..7522c204 100644 --- a/app/Models/Foundation/Summit/Locations/SummitLocationConstants.php +++ b/app/Models/Foundation/Summit/Locations/SummitLocationConstants.php @@ -12,11 +12,11 @@ * limitations under the License. **/ use models\summit\SummitAirport; +use models\summit\SummitBookableVenueRoom; use models\summit\SummitExternalLocation; use models\summit\SummitHotel; use models\summit\SummitVenue; use models\summit\SummitVenueRoom; - /** * Class SummitLocationConstants * @package App\Models\Foundation\Summit\Locations @@ -28,6 +28,7 @@ final class SummitLocationConstants SummitAirport::ClassName, SummitHotel::ClassName, SummitExternalLocation::ClassName, - SummitVenueRoom::ClassName + SummitVenueRoom::ClassName, + SummitBookableVenueRoom::ClassName ]; } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Locations/SummitRoomReservation.php b/app/Models/Foundation/Summit/Locations/SummitRoomReservation.php index 4aa21ef1..b4a77b07 100644 --- a/app/Models/Foundation/Summit/Locations/SummitRoomReservation.php +++ b/app/Models/Foundation/Summit/Locations/SummitRoomReservation.php @@ -325,5 +325,4 @@ class SummitRoomReservation extends SilverstripeBaseModel } } - } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Repositories/ISummitBookableVenueRoomAttributeTypeRepository.php b/app/Models/Foundation/Summit/Repositories/ISummitBookableVenueRoomAttributeTypeRepository.php new file mode 100644 index 00000000..1f3faa2b --- /dev/null +++ b/app/Models/Foundation/Summit/Repositories/ISummitBookableVenueRoomAttributeTypeRepository.php @@ -0,0 +1,22 @@ +meeting_booking_room_allowed_attributes; } + /** + * @param SummitBookableVenueRoomAttributeType $type + */ + public function addMeetingBookingRoomAllowedAttribute(SummitBookableVenueRoomAttributeType $type){ + if($this->meeting_booking_room_allowed_attributes->contains($type)) return; + $this->meeting_booking_room_allowed_attributes->add($type); + $type->setSummit($this); + } + + /** + * @param SummitBookableVenueRoomAttributeType $type + */ + public function removeMeetingBookingRoomAllowedAttribute(SummitBookableVenueRoomAttributeType $type){ + if(!$this->meeting_booking_room_allowed_attributes->contains($type)) return; + $this->meeting_booking_room_allowed_attributes->removeElement($type); + } + + /** + * @param int $id + * @return SummitBookableVenueRoomAttributeType|null + */ + public function getBookableAttributeTypeById(int $id):?SummitBookableVenueRoomAttributeType + { + $criteria = Criteria::create(); + $criteria->where(Criteria::expr()->eq('id', intval($id))); + $attr = $this->meeting_booking_room_allowed_attributes->matching($criteria)->first(); + return $attr === false ? null : $attr; + } + + /** + * @param string $type + * @return SummitBookableVenueRoomAttributeType|null + */ + public function getBookableAttributeTypeByTypeName(string $type):?SummitBookableVenueRoomAttributeType + { + $criteria = Criteria::create(); + $criteria->where(Criteria::expr()->eq('type', trim($type))); + $attr = $this->meeting_booking_room_allowed_attributes->matching($criteria)->first(); + return $attr === false ? null : $attr; + } + public function getMaxReservationsPerDay():int { $interval = $this->meeting_room_booking_end_time->diff( $this->meeting_room_booking_start_time); $minutes = $interval->days * 24 * 60; @@ -2542,4 +2583,15 @@ SQL; return intval ($minutes / $this->meeting_room_booking_slot_length); } + /** + * @param int $id + * @return SummitBookableVenueRoomAttributeValue|null + */ + public function getMeetingBookingRoomAllowedAttributeValueById(int $id):?SummitBookableVenueRoomAttributeValue{ + foreach($this->meeting_booking_room_allowed_attributes as $attribute_type){ + $value = $attribute_type->getValueById($id); + if(!is_null($value)) return $value; + } + return null; + } } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 35f79cbd..e52683ad 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -41,6 +41,9 @@ use App\Factories\EntityEvents\TrackGroupActionActionEntityEventFactory; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\App; +use LaravelDoctrine\ORM\Facades\EntityManager; +use models\summit\SummitRoomReservation; + /** * Class EventServiceProvider * @package App\Providers @@ -317,5 +320,27 @@ final class EventServiceProvider extends ServiceProvider { EntityEventPersister::persist(SummitActionEntityEventFactory::build($event, 'DELETE')); }); + + // bookable rooms events + + Event::listen(\App\Events\BookableRoomReservationRefundAccepted::class, function($event) + { + $repository = EntityManager::getRepository(SummitRoomReservation::class); + }); + + Event::listen(\App\Events\CreatedBookableRoomReservation::class, function($event) + { + $repository = EntityManager::getRepository(SummitRoomReservation::class); + }); + + Event::listen(\App\Events\PaymentBookableRoomReservationConfirmed::class, function($event) + { + $repository = EntityManager::getRepository(SummitRoomReservation::class); + }); + + Event::listen(\App\Events\RequestedBookableRoomReservationRefund::class, function($event) + { + $repository = EntityManager::getRepository(SummitRoomReservation::class); + }); } } diff --git a/app/Repositories/RepositoriesProvider.php b/app/Repositories/RepositoriesProvider.php index 2ac3c723..87b4ac45 100644 --- a/app/Repositories/RepositoriesProvider.php +++ b/app/Repositories/RepositoriesProvider.php @@ -27,6 +27,8 @@ use App\Models\Foundation\Summit\Repositories\ISelectionPlanRepository; use App\Models\Foundation\Summit\Repositories\ISpeakerActiveInvolvementRepository; use App\Models\Foundation\Summit\Repositories\ISpeakerEditPermissionRequestRepository; use App\Models\Foundation\Summit\Repositories\ISpeakerOrganizationalRoleRepository; +use App\Models\Foundation\Summit\Repositories\ISummitBookableVenueRoomAttributeTypeRepository; +use App\Models\Foundation\Summit\Repositories\ISummitBookableVenueRoomAttributeValueRepository; use App\Models\Foundation\Summit\Repositories\ISummitEventTypeRepository; use App\Models\Foundation\Summit\Repositories\ISummitLocationBannerRepository; use App\Models\Foundation\Summit\Repositories\ISummitLocationRepository; @@ -57,6 +59,8 @@ use models\summit\SpeakerOrganizationalRole; use models\summit\SpeakerRegistrationRequest; use models\summit\SpeakerSummitRegistrationPromoCode; use models\summit\SummitAbstractLocation; +use models\summit\SummitBookableVenueRoomAttributeType; +use models\summit\SummitBookableVenueRoomAttributeValue; use models\summit\SummitEventType; use models\summit\SummitRegistrationPromoCode; use models\summit\SummitRoomReservation; @@ -410,5 +414,19 @@ final class RepositoriesProvider extends ServiceProvider } ); + App::singleton( + ISummitBookableVenueRoomAttributeTypeRepository::class, + function(){ + return EntityManager::getRepository(SummitBookableVenueRoomAttributeType::class); + } + ); + + App::singleton( + ISummitBookableVenueRoomAttributeValueRepository::class, + function(){ + return EntityManager::getRepository(SummitBookableVenueRoomAttributeValue::class); + } + ); + } } \ No newline at end of file diff --git a/app/Repositories/SilverStripeDoctrineRepository.php b/app/Repositories/SilverStripeDoctrineRepository.php index 9047037f..7586e48a 100644 --- a/app/Repositories/SilverStripeDoctrineRepository.php +++ b/app/Repositories/SilverStripeDoctrineRepository.php @@ -24,7 +24,6 @@ use LaravelDoctrine\ORM\Facades\Registry; abstract class SilverStripeDoctrineRepository extends DoctrineRepository { - /** * Initializes a new EntityRepository. * diff --git a/app/Repositories/Summit/DoctrineSummitBookableVenueRoomAttributeTypeRepository.php b/app/Repositories/Summit/DoctrineSummitBookableVenueRoomAttributeTypeRepository.php new file mode 100644 index 00000000..93559163 --- /dev/null +++ b/app/Repositories/Summit/DoctrineSummitBookableVenueRoomAttributeTypeRepository.php @@ -0,0 +1,62 @@ + 'e.type:json_string', + 'summit_id' => new DoctrineJoinFilterMapping + ( + 'e.summit', + 's', + "s.id :operator ':value'" + ), + ]; + } + + /** + * @return array + */ + protected function getOrderMappings() + { + return [ + 'id' => 'e.id', + 'type' => 'e.type', + ]; + } + + /** + * @return string + */ + protected function getBaseEntity() + { + return SummitBookableVenueRoomAttributeType::class; + } +} \ No newline at end of file diff --git a/app/Repositories/Summit/DoctrineSummitBookableVenueRoomAttributeValueRepository.php b/app/Repositories/Summit/DoctrineSummitBookableVenueRoomAttributeValueRepository.php new file mode 100644 index 00000000..0c1229c9 --- /dev/null +++ b/app/Repositories/Summit/DoctrineSummitBookableVenueRoomAttributeValueRepository.php @@ -0,0 +1,67 @@ + 'e.value:json_string', + 'summit_id' => new DoctrineJoinFilterMapping + ( + 'e.summit', + 's', + "s.id :operator ':value'" + ), + 'type_id' => new DoctrineJoinFilterMapping + ( + 'e.type', + 't', + "t.id :operator ':value'" + ), + ]; + } + + /** + * @return array + */ + protected function getOrderMappings() + { + return [ + 'id' => 'e.id', + 'value' => 'e.value', + ]; + } + + /** + * @return string + */ + protected function getBaseEntity() + { + return SummitBookableVenueRoomAttributeValue::class; + } +} \ No newline at end of file diff --git a/app/Repositories/Summit/DoctrineSummitRoomReservationRepository.php b/app/Repositories/Summit/DoctrineSummitRoomReservationRepository.php index a4816cdd..0049d238 100644 --- a/app/Repositories/Summit/DoctrineSummitRoomReservationRepository.php +++ b/app/Repositories/Summit/DoctrineSummitRoomReservationRepository.php @@ -13,7 +13,16 @@ **/ use App\Models\Foundation\Summit\Repositories\ISummitRoomReservationRepository; use App\Repositories\SilverStripeDoctrineRepository; +use Doctrine\ORM\Tools\Pagination\Paginator; +use models\summit\Summit; use models\summit\SummitRoomReservation; +use utils\DoctrineFilterMapping; +use utils\DoctrineJoinFilterMapping; +use utils\Filter; +use utils\Order; +use utils\PagingInfo; +use utils\PagingResponse; + /** * Class DoctrineSummitRoomReservationRepository * @package App\Repositories\Summit @@ -32,11 +41,105 @@ class DoctrineSummitRoomReservationRepository } /** - * @param string $payment_gateway_cart_id - * @return SummitRoomReservation + * @return array */ - public function getByPaymentGatewayCartId(string $payment_gateway_cart_id): SummitRoomReservation + protected function getFilterMappings() + { + return [ + 'status' => 'e.status:json_string', + 'start_datetime' => 'e.start_datetime:datetime_epoch', + 'end_datetime' => 'e.end_datetime:datetime_epoch', + 'room_id' => new DoctrineJoinFilterMapping + ( + 'e.room', + 'r', + "r.id :operator :value" + ), + 'venue_id' => new DoctrineJoinFilterMapping + ( + 'r.venue', + 'v', + "v.id :operator :value" + ), + 'owner_id' => new DoctrineJoinFilterMapping + ( + 'e.owner', + 'o', + "o.id :operator :value" + ), + ]; + } + + /** + * @param Summit $summit + * @param PagingInfo $paging_info + * @param Filter|null $filter + * @param Order|null $order + * @return PagingResponse + */ + public function getAllBySummitByPage(Summit $summit, PagingInfo $paging_info, Filter $filter = null, Order $order = null):PagingResponse{ + + $query = $this->getEntityManager() + ->createQueryBuilder() + ->select("e") + ->from($this->getBaseEntity(), "e") + ->join("e.room","r1") + ->join("r1.venue", "v1") + ->join("v1.summit", "s1") + ->where("s1.id = ".$summit->getId()) + ; + + $query = $this->applyExtraFilters($query); + + if(!is_null($filter)){ + $filter->apply2Query($query, $this->getFilterMappings()); + } + + if(!is_null($order)){ + $order->apply2Query($query, $this->getOrderMappings()); + } + + $query = $query + ->setFirstResult($paging_info->getOffset()) + ->setMaxResults($paging_info->getPerPage()); + + $paginator = new Paginator($query, $fetchJoinCollection = true); + $total = $paginator->count(); + $data = array(); + + foreach($paginator as $entity) + array_push($data, $entity); + + return new PagingResponse + ( + $total, + $paging_info->getPerPage(), + $paging_info->getCurrentPage(), + $paging_info->getLastPage($total), + $data + ); + } + + /** + * @return array + */ + protected function getOrderMappings() + { + return [ + 'id' => 'e.id', + 'start_datetime' => 'e.start_datetime', + 'end_datetime' => 'e.end_datetime', + ]; + } + + /** + * @param string $payment_gateway_cart_id + * @return SummitRoomReservation|null + */ + public function getByPaymentGatewayCartId(string $payment_gateway_cart_id):?SummitRoomReservation { return $this->findOneBy(["payment_gateway_cart_id" => trim($payment_gateway_cart_id)]); } + + } \ No newline at end of file diff --git a/app/Services/Model/ILocationService.php b/app/Services/Model/ILocationService.php index be7e65e3..b02c5728 100644 --- a/app/Services/Model/ILocationService.php +++ b/app/Services/Model/ILocationService.php @@ -13,6 +13,7 @@ **/ use App\Models\Foundation\Summit\Locations\Banners\SummitLocationBanner; use models\main\Member; +use models\summit\SummitBookableVenueRoom; use models\summit\SummitLocationImage; use models\summit\SummitRoomReservation; use models\summit\SummitVenueRoom; @@ -232,13 +233,77 @@ interface ILocationService */ public function processBookableRoomPayment(array $payload):void; - /** * @param Summit $sumit * @param Member $owner * @param int $reservation_id + * @return SummitRoomReservation * @throws EntityNotFoundException * @throws ValidationException */ - public function cancelReservation(Summit $sumit, Member $owner, int $reservation_id):void; + public function cancelReservation(Summit $sumit, Member $owner, int $reservation_id):SummitRoomReservation; + + /** + * @param SummitBookableVenueRoom $room + * @param int $reservation_id + * @param int $amount + * @return SummitRoomReservation + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function refundReservation(SummitBookableVenueRoom $room, int $reservation_id, int $amount):SummitRoomReservation; + + + /** + * @param Summit $summit + * @param int $venue_id + * @param int $room_id + * @return void + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function deleteVenueBookableRoom(Summit $summit, $venue_id, $room_id); + + /** + * @param Summit $summit + * @param $venue_id + * @param array $data + * @return SummitVenueRoom + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function addVenueBookableRoom(Summit $summit, $venue_id, array $data); + + /** + * @param Summit $summit + * @param int $venue_id + * @param int $room_id + * @param array $data + * @return SummitVenueRoom + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function updateVenueBookableRoom(Summit $summit, $venue_id, $room_id, array $data); + + /** + * @param Summit $summit + * @param int $venue_id + * @param int $room_id + * @param int $attribute_id + * @return SummitBookableVenueRoom + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function addVenueBookableRoomAttribute(Summit $summit, int $venue_id, int $room_id, int $attribute_id):SummitBookableVenueRoom; + + /** + * @param Summit $summit + * @param int $venue_id + * @param int $room_id + * @param int $attribute_id + * @return SummitBookableVenueRoom + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function deleteVenueBookableRoomAttribute(Summit $summit, int $venue_id, int $room_id, int $attribute_id):SummitBookableVenueRoom; } \ No newline at end of file diff --git a/app/Services/Model/ISummitService.php b/app/Services/Model/ISummitService.php index 87c7df96..e768a355 100644 --- a/app/Services/Model/ISummitService.php +++ b/app/Services/Model/ISummitService.php @@ -19,6 +19,8 @@ use models\main\Member; use models\summit\ConfirmationExternalOrderRequest; use models\summit\Summit; use models\summit\SummitAttendee; +use models\summit\SummitBookableVenueRoomAttributeType; +use models\summit\SummitBookableVenueRoomAttributeValue; use models\summit\SummitEvent; use models\summit\SummitEventFeedback; use models\summit\SummitScheduleEmptySpot; @@ -273,4 +275,64 @@ interface ISummitService */ public function cloneEvent(Summit $summit, int $event_id):SummitEvent; + // bookable room attribute types + + /** + * @param Summit $summit + * @param array $payload + * @return SummitBookableVenueRoomAttributeType + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function addBookableRoomAttribute(Summit $summit, array $payload):SummitBookableVenueRoomAttributeType; + + /** + * @param Summit $summit + * @param int $type_id + * @param array $payload + * @return SummitBookableVenueRoomAttributeType + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function updateBookableRoomAttribute(Summit $summit, int $type_id, array $payload):SummitBookableVenueRoomAttributeType; + + /** + * @param Summit $summit + * @param int $type_id + * @return void + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function deleteBookableRoomAttribute(Summit $summit, int $type_id):void; + + /** + * @param Summit $summit + * @param int $type_id + * @param array $payload + * @return SummitBookableVenueRoomAttributeValue + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function addBookableRoomAttributeValue(Summit $summit, int $type_id, array $payload):SummitBookableVenueRoomAttributeValue; + + /** + * @param Summit $summit + * @param int $type_id + * @param int $value_id + * @param array $payload + * @return SummitBookableVenueRoomAttributeValue + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function updateBookableRoomAttributeValue(Summit $summit, int $type_id, int $value_id, array $payload):SummitBookableVenueRoomAttributeValue; + + /** + * @param Summit $summit + * @param int $type_id + * @param int $value_id + * @return void + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function deleteBookableRoomAttributeValue(Summit $summit, int $type_id, int $value_id):void; } \ No newline at end of file diff --git a/app/Services/Model/SummitLocationService.php b/app/Services/Model/SummitLocationService.php index 6e875254..6f97465c 100644 --- a/app/Services/Model/SummitLocationService.php +++ b/app/Services/Model/SummitLocationService.php @@ -1,5 +1,4 @@ location_repository = $location_repository; - $this->member_repository = $member_repository; + $this->location_repository = $location_repository; + $this->member_repository = $member_repository; $this->reservation_repository = $reservation_repository; - $this->geo_coding_api = $geo_coding_api; - $this->file_uploader = $file_uploader; - $this->folder_service = $folder_service; - $this->payment_gateway = $payment_gateway; + $this->geo_coding_api = $geo_coding_api; + $this->file_uploader = $file_uploader; + $this->folder_service = $folder_service; + $this->payment_gateway = $payment_gateway; } /** @@ -135,7 +139,7 @@ final class SummitLocationService */ public function addLocation(Summit $summit, array $data) { - $location = $this->tx_service->transaction(function () use ($summit, $data) { + $location = $this->tx_service->transaction(function () use ($summit, $data) { $old_location = $summit->getLocationByName(trim($data['name'])); @@ -172,14 +176,16 @@ final class SummitLocationService Log::warning($ex1->getMessage()); $validation_msg = trans('validation_errors.LocationService.addLocation.geoCodingGenericError'); switch ($ex1->getStatus()) { - case IGeoCodingAPI::ResponseStatusZeroResults: { - $validation_msg = trans('validation_errors.LocationService.addLocation.InvalidAddressOrCoordinates'); - } - break; - case IGeoCodingAPI::ResponseStatusOverQueryLimit: { - $validation_msg = trans('validation_errors.LocationService.addLocation.OverQuotaLimit'); - } - break; + case IGeoCodingAPI::ResponseStatusZeroResults: + { + $validation_msg = trans('validation_errors.LocationService.addLocation.InvalidAddressOrCoordinates'); + } + break; + case IGeoCodingAPI::ResponseStatusOverQueryLimit: + { + $validation_msg = trans('validation_errors.LocationService.addLocation.OverQuotaLimit'); + } + break; } throw new ValidationException($validation_msg); } catch (\Exception $ex) { @@ -250,8 +256,8 @@ final class SummitLocationService ); } - if(!Summit::isPrimaryLocation($location)){ - throw new EntityNotFoundException( + if (!Summit::isPrimaryLocation($location)) { + throw new EntityNotFoundException( trans ( 'validation_errors.LocationService.updateLocation.LocationNotFoundOnSummit', @@ -269,9 +275,9 @@ final class SummitLocationService ( 'validation_errors.LocationService.updateLocation.ClassNameMissMatch', [ - 'summit_id' => $summit->getId(), + 'summit_id' => $summit->getId(), 'location_id' => $location_id, - 'class_name' => $data['class_name'] + 'class_name' => $data['class_name'] ] ) ); @@ -287,13 +293,15 @@ final class SummitLocationService Log::warning($ex1->getMessage()); $validation_msg = trans('validation_errors.LocationService.addLocation.geoCodingGenericError'); switch ($ex1->getStatus()) { - case IGeoCodingAPI::ResponseStatusZeroResults: { - $validation_msg = trans('validation_errors.LocationService.addLocation.InvalidAddressOrCoordinates'); - } + case IGeoCodingAPI::ResponseStatusZeroResults: + { + $validation_msg = trans('validation_errors.LocationService.addLocation.InvalidAddressOrCoordinates'); + } break; - case IGeoCodingAPI::ResponseStatusOverQueryLimit: { - $validation_msg = trans('validation_errors.LocationService.addLocation.OverQuotaLimit'); - } + case IGeoCodingAPI::ResponseStatusOverQueryLimit: + { + $validation_msg = trans('validation_errors.LocationService.addLocation.OverQuotaLimit'); + } break; } throw new ValidationException($validation_msg); @@ -327,7 +335,8 @@ final class SummitLocationService * @param array $data * @return bool */ - private function hasGeoLocationData2Update(array $data){ + private function hasGeoLocationData2Update(array $data) + { return isset($data['address_1']) || isset($data['lat']); } @@ -356,7 +365,7 @@ final class SummitLocationService ) ); } - if(!Summit::isPrimaryLocation($location)){ + if (!Summit::isPrimaryLocation($location)) { throw new EntityNotFoundException( trans ( @@ -395,7 +404,7 @@ final class SummitLocationService $venue = $summit->getLocation($venue_id); - if(is_null($venue)){ + if (is_null($venue)) { throw new EntityNotFoundException ( trans @@ -403,13 +412,13 @@ final class SummitLocationService 'not_found_errors.LocationService.addVenueFloor.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); } - if(!$venue instanceof SummitVenue){ + if (!$venue instanceof SummitVenue) { throw new EntityNotFoundException ( trans @@ -417,7 +426,7 @@ final class SummitLocationService 'not_found_errors.LocationService.addVenueFloor.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); @@ -425,14 +434,14 @@ final class SummitLocationService $former_floor = $venue->getFloorByName(trim($data['name'])); - if(!is_null($former_floor)){ + if (!is_null($former_floor)) { throw new ValidationException( trans ( 'validation_errors.LocationService.addVenueFloor.FloorNameAlreadyExists', [ - 'venue_id' => $venue_id, - 'floor_name' => trim($data['name']) + 'venue_id' => $venue_id, + 'floor_name' => trim($data['name']) ] ) ); @@ -440,14 +449,14 @@ final class SummitLocationService $former_floor = $venue->getFloorByNumber(intval($data['number'])); - if(!is_null($former_floor)){ + if (!is_null($former_floor)) { throw new ValidationException ( trans ( 'validation_errors.LocationService.addVenueFloor.FloorNumberAlreadyExists', [ - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, 'floor_number' => intval($data['number']) ] ) @@ -489,7 +498,7 @@ final class SummitLocationService $venue = $summit->getLocation($venue_id); - if(is_null($venue)){ + if (is_null($venue)) { throw new EntityNotFoundException ( trans @@ -497,13 +506,13 @@ final class SummitLocationService 'not_found_errors.LocationService.updateVenueFloor.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); } - if(!$venue instanceof SummitVenue){ + if (!$venue instanceof SummitVenue) { throw new EntityNotFoundException ( trans @@ -511,13 +520,13 @@ final class SummitLocationService 'not_found_errors.LocationService.updateVenueFloor.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); } - if(isset($data['name'])) { + if (isset($data['name'])) { $former_floor = $venue->getFloorByName(trim($data['name'])); if (!is_null($former_floor) && $former_floor->getId() != $floor_id) { @@ -534,7 +543,7 @@ final class SummitLocationService } } - if(isset($data['number'])) { + if (isset($data['number'])) { $former_floor = $venue->getFloorByNumber(intval($data['number'])); if (!is_null($former_floor) && $former_floor->getId() != $floor_id) { @@ -554,7 +563,7 @@ final class SummitLocationService } $floor = $venue->getFloor($floor_id); - if(is_null($floor)){ + if (is_null($floor)) { throw new EntityNotFoundException ( trans @@ -598,7 +607,7 @@ final class SummitLocationService $venue = $summit->getLocation($venue_id); - if(is_null($venue)){ + if (is_null($venue)) { throw new EntityNotFoundException ( trans @@ -606,13 +615,13 @@ final class SummitLocationService 'not_found_errors.LocationService.deleteVenueFloor.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); } - if(!$venue instanceof SummitVenue){ + if (!$venue instanceof SummitVenue) { throw new EntityNotFoundException ( trans @@ -620,7 +629,7 @@ final class SummitLocationService 'not_found_errors.LocationService.deleteVenueFloor.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); @@ -628,7 +637,7 @@ final class SummitLocationService $floor = $venue->getFloor($floor_id); - if(is_null($floor)){ + if (is_null($floor)) { throw new EntityNotFoundException ( trans @@ -664,7 +673,7 @@ final class SummitLocationService */ public function addVenueRoom(Summit $summit, $venue_id, array $data) { - $room = $this->tx_service->transaction(function () use ($summit, $venue_id, $data) { + $room = $this->tx_service->transaction(function () use ($summit, $venue_id, $data) { if (isset($data['name'])) { $old_location = $summit->getLocationByName(trim($data['name'])); @@ -685,7 +694,7 @@ final class SummitLocationService $venue = $summit->getLocation($venue_id); - if(is_null($venue)){ + if (is_null($venue)) { throw new EntityNotFoundException ( trans @@ -693,13 +702,13 @@ final class SummitLocationService 'not_found_errors.LocationService.addVenueRoom.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); } - if(!$venue instanceof SummitVenue){ + if (!$venue instanceof SummitVenue) { throw new EntityNotFoundException ( trans @@ -707,14 +716,14 @@ final class SummitLocationService 'not_found_errors.LocationService.addVenueRoom.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); } $data['class_name'] = SummitVenueRoom::ClassName; - $room = SummitLocationFactory::build($data); + $room = SummitLocationFactory::build($data); if (is_null($room)) { throw new ValidationException @@ -726,11 +735,11 @@ final class SummitLocationService ); } - if(isset($data['floor_id'])){ + if (isset($data['floor_id'])) { $floor_id = intval($data['floor_id']); - $floor = $venue->getFloor($floor_id); + $floor = $venue->getFloor($floor_id); - if(is_null($floor)){ + if (is_null($floor)) { throw new EntityNotFoundException ( trans @@ -798,7 +807,7 @@ final class SummitLocationService $venue = $summit->getLocation($venue_id); - if(is_null($venue)){ + if (is_null($venue)) { throw new EntityNotFoundException ( trans @@ -806,13 +815,13 @@ final class SummitLocationService 'not_found_errors.LocationService.updateVenueRoom.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); } - if(!$venue instanceof SummitVenue){ + if (!$venue instanceof SummitVenue) { throw new EntityNotFoundException ( trans @@ -820,7 +829,7 @@ final class SummitLocationService 'not_found_errors.LocationService.updateVenueRoom.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); @@ -835,8 +844,8 @@ final class SummitLocationService 'not_found_errors.LocationService.updateVenueRoom.RoomNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, - 'room_id' => $room_id, + 'venue_id' => $venue_id, + 'room_id' => $room_id, ] ) ); @@ -850,8 +859,8 @@ final class SummitLocationService 'not_found_errors.LocationService.updateVenueRoom.RoomNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, - 'room_id' => $room_id, + 'venue_id' => $venue_id, + 'room_id' => $room_id, ] ) ); @@ -860,12 +869,12 @@ final class SummitLocationService $old_floor_id = $room->getFloorId(); $new_floor_id = $room->getFloorId(); SummitLocationFactory::populate($room, $data); - $floor = null; + $floor = null; - if(isset($data['floor_id'])){ + if (isset($data['floor_id'])) { $old_floor_id = intval($room->getFloorId()); $new_floor_id = intval($data['floor_id']); - if($old_floor_id != $new_floor_id) { + if ($old_floor_id != $new_floor_id) { $floor = $venue->getFloor($new_floor_id); if (is_null($floor)) { throw new EntityNotFoundException @@ -880,7 +889,7 @@ final class SummitLocationService ) ); } - if($old_floor_id > 0){ + if ($old_floor_id > 0) { // remove from old floor $room->getFloor()->removeRoom($room); @@ -892,11 +901,9 @@ final class SummitLocationService // request to update order if (isset($data['order']) && intval($data['order']) != $room->getOrder()) { - if(!is_null($floor)){ + if (!is_null($floor)) { $floor->recalculateRoomsOrder($room, intval($data['order'])); - } - else - { + } else { $venue->recalculateRoomsOrder($room, intval($data['order'])); } } @@ -932,7 +939,7 @@ final class SummitLocationService $venue = $summit->getLocation($venue_id); - if(is_null($venue)){ + if (is_null($venue)) { throw new EntityNotFoundException ( trans @@ -940,13 +947,13 @@ final class SummitLocationService 'not_found_errors.LocationService.deleteVenueRoom.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); } - if(!$venue instanceof SummitVenue){ + if (!$venue instanceof SummitVenue) { throw new EntityNotFoundException ( trans @@ -954,7 +961,7 @@ final class SummitLocationService 'not_found_errors.LocationService.deleteVenueRoom.VenueNotFound', [ 'summit_id' => $summit->getId(), - 'venue_id' => $venue_id, + 'venue_id' => $venue_id, ] ) ); @@ -962,7 +969,7 @@ final class SummitLocationService $room = $venue->getRoom($room_id); - if(is_null($room)){ + if (is_null($room)) { throw new EntityNotFoundException ( trans @@ -978,8 +985,7 @@ final class SummitLocationService $venue->removeRoom($room); - if($room->hasFloor()) - { + if ($room->hasFloor()) { $floor = $room->getFloor(); $floor->removeRoom($room); } @@ -1011,7 +1017,7 @@ final class SummitLocationService $location = $summit->getLocation($location_id); - if(is_null($location)){ + if (is_null($location)) { throw new EntityNotFoundException ( trans @@ -1019,7 +1025,7 @@ final class SummitLocationService 'not_found_errors.LocationService.addLocationBanner.LocationNotFound', [ 'summit_id' => $summit->getId(), - 'location_id' => $location_id, + 'location_id' => $location_id, ] ) ); @@ -1058,14 +1064,14 @@ final class SummitLocationService $location = $summit->getLocation($location_id); - if(is_null($location)){ + if (is_null($location)) { throw new EntityNotFoundException ( trans ( 'not_found_errors.LocationService.updateLocationBanner.LocationNotFound', [ - 'summit_id' => $summit->getId(), + 'summit_id' => $summit->getId(), 'location_id' => $location_id, ] ) @@ -1074,15 +1080,15 @@ final class SummitLocationService $banner = $location->getBannerById($banner_id); - if(is_null($banner)){ + if (is_null($banner)) { throw new EntityNotFoundException ( trans ( 'not_found_errors.LocationService.updateLocationBanner.BannerNotFound', [ - 'location_id' => $location_id, - 'banner_id' => $banner_id, + 'location_id' => $location_id, + 'banner_id' => $banner_id, ] ) ); @@ -1107,15 +1113,15 @@ final class SummitLocationService return $this->tx_service->transaction(function () use ($summit, $location_id, $banner_id) { $location = $summit->getLocation($location_id); - if(is_null($location)){ + if (is_null($location)) { throw new EntityNotFoundException ( trans ( 'not_found_errors.LocationService.deleteLocationBanner.LocationNotFound', [ - 'summit_id' => $summit->getId(), - 'location_id' => $location_id, + 'summit_id' => $summit->getId(), + 'location_id' => $location_id, ] ) ); @@ -1123,15 +1129,15 @@ final class SummitLocationService $banner = $location->getBannerById($banner_id); - if(is_null($banner)){ + if (is_null($banner)) { throw new EntityNotFoundException ( trans ( 'not_found_errors.LocationService.deleteLocationBanner.BannerNotFound', [ - 'location_id' => $location_id, - 'banner_id' => $banner_id, + 'location_id' => $location_id, + 'banner_id' => $banner_id, ] ) ); @@ -1153,9 +1159,9 @@ final class SummitLocationService public function addLocationMap(Summit $summit, $location_id, array $metadata, UploadedFile $file) { $map = $this->tx_service->transaction(function () use ($summit, $location_id, $metadata, $file) { - $max_file_size = config('file_upload.max_file_upload_size') ; - $allowed_extensions = ['png','jpg','jpeg','gif','pdf']; - $location = $summit->getLocation($location_id); + $max_file_size = config('file_upload.max_file_upload_size'); + $allowed_extensions = ['png', 'jpg', 'jpeg', 'gif', 'pdf']; + $location = $summit->getLocation($location_id); if (is_null($location)) { throw new EntityNotFoundException @@ -1169,7 +1175,7 @@ final class SummitLocationService ); } - if(!$location instanceof SummitGeoLocatedLocation){ + if (!$location instanceof SummitGeoLocatedLocation) { throw new EntityNotFoundException ( trans( @@ -1181,7 +1187,7 @@ final class SummitLocationService ); } - if(!in_array($file->extension(), $allowed_extensions)){ + if (!in_array($file->extension(), $allowed_extensions)) { throw new ValidationException ( trans( @@ -1193,22 +1199,21 @@ final class SummitLocationService ); } - if($file->getSize() > $max_file_size) - { + if ($file->getSize() > $max_file_size) { throw new ValidationException ( trans ( 'validation_errors.LocationService.addLocationMap.FileMaxSize', [ - 'max_file_size' => (($max_file_size/1024)/1024) + 'max_file_size' => (($max_file_size / 1024) / 1024) ] ) ); } - $pic = $this->file_uploader->build($file, sprintf('summits/%s/locations/%s/maps', $location->getSummitId(), $location->getId()), true); - $map = SummitLocationImageFactory::buildMap($metadata); + $pic = $this->file_uploader->build($file, sprintf('summits/%s/locations/%s/maps', $location->getSummitId(), $location->getId()), true); + $map = SummitLocationImageFactory::buildMap($metadata); $map->setPicture($pic); $location->addMap($map); return $map; @@ -1241,9 +1246,9 @@ final class SummitLocationService public function updateLocationMap(Summit $summit, $location_id, $map_id, array $metadata, UploadedFile $file = null) { return $this->tx_service->transaction(function () use ($summit, $location_id, $map_id, $metadata, $file) { - $max_file_size = config('file_upload.max_file_upload_size') ; - $allowed_extensions = ['png','jpg','jpeg','gif','pdf']; - $location = $summit->getLocation($location_id); + $max_file_size = config('file_upload.max_file_upload_size'); + $allowed_extensions = ['png', 'jpg', 'jpeg', 'gif', 'pdf']; + $location = $summit->getLocation($location_id); if (is_null($location)) { throw new EntityNotFoundException @@ -1257,7 +1262,7 @@ final class SummitLocationService ); } - if(!$location instanceof SummitGeoLocatedLocation){ + if (!$location instanceof SummitGeoLocatedLocation) { throw new EntityNotFoundException ( trans( @@ -1277,14 +1282,14 @@ final class SummitLocationService trans( 'not_found_errors.LocationService.updateLocationMap.MapNotFound', [ - 'map_id' => $map_id, + 'map_id' => $map_id, 'location_id' => $location_id, ] ) ); } - if(!is_null($file)) { + if (!is_null($file)) { if (!in_array($file->extension(), $allowed_extensions)) { throw new ValidationException ( @@ -1350,29 +1355,29 @@ final class SummitLocationService $location = $summit->getLocation($location_id); - if(is_null($location)){ + if (is_null($location)) { throw new EntityNotFoundException ( trans ( 'not_found_errors.LocationService.deleteLocationMap.LocationNotFound', [ - 'summit_id' => $summit->getId(), - 'location_id' => $location_id, + 'summit_id' => $summit->getId(), + 'location_id' => $location_id, ] ) ); } - if(!$location instanceof SummitGeoLocatedLocation){ + if (!$location instanceof SummitGeoLocatedLocation) { throw new EntityNotFoundException ( trans ( 'not_found_errors.LocationService.deleteLocationMap.LocationNotFound', [ - 'summit_id' => $summit->getId(), - 'location_id' => $location_id, + 'summit_id' => $summit->getId(), + 'location_id' => $location_id, ] ) ); @@ -1380,7 +1385,7 @@ final class SummitLocationService $map = $location->getMap($map_id); - if(is_null($map)){ + if (is_null($map)) { throw new EntityNotFoundException ( trans @@ -1388,7 +1393,7 @@ final class SummitLocationService 'not_found_errors.LocationService.deleteLocationMap.MapNotFound', [ 'location_id' => $location_id, - 'map_id' => $map_id, + 'map_id' => $map_id, ] ) ); @@ -1422,9 +1427,9 @@ final class SummitLocationService public function addLocationImage(Summit $summit, $location_id, array $metadata, UploadedFile $file) { $image = $this->tx_service->transaction(function () use ($summit, $location_id, $metadata, $file) { - $max_file_size = config('file_upload.max_file_upload_size') ; - $allowed_extensions = ['png','jpg','jpeg','gif','pdf']; - $location = $summit->getLocation($location_id); + $max_file_size = config('file_upload.max_file_upload_size'); + $allowed_extensions = ['png', 'jpg', 'jpeg', 'gif', 'pdf']; + $location = $summit->getLocation($location_id); if (is_null($location)) { throw new EntityNotFoundException @@ -1438,7 +1443,7 @@ final class SummitLocationService ); } - if(!$location instanceof SummitGeoLocatedLocation){ + if (!$location instanceof SummitGeoLocatedLocation) { throw new EntityNotFoundException ( trans( @@ -1450,7 +1455,7 @@ final class SummitLocationService ); } - if(!in_array($file->extension(), $allowed_extensions)){ + if (!in_array($file->extension(), $allowed_extensions)) { throw new ValidationException ( trans( @@ -1462,22 +1467,21 @@ final class SummitLocationService ); } - if($file->getSize() > $max_file_size) - { + if ($file->getSize() > $max_file_size) { throw new ValidationException ( trans ( 'validation_errors.LocationService.addLocationImage.FileMaxSize', [ - 'max_file_size' => (($max_file_size/1024)/1024) + 'max_file_size' => (($max_file_size / 1024) / 1024) ] ) ); } - $pic = $this->file_uploader->build($file, sprintf('summits/%s/locations/%s/images', $location->getSummitId(), $location->getId()), true); - $image = SummitLocationImageFactory::buildImage($metadata); + $pic = $this->file_uploader->build($file, sprintf('summits/%s/locations/%s/images', $location->getSummitId(), $location->getId()), true); + $image = SummitLocationImageFactory::buildImage($metadata); $image->setPicture($pic); $location->addImage($image); return $image; @@ -1510,9 +1514,9 @@ final class SummitLocationService public function updateLocationImage(Summit $summit, $location_id, $image_id, array $metadata, UploadedFile $file = null) { return $this->tx_service->transaction(function () use ($summit, $location_id, $image_id, $metadata, $file) { - $max_file_size = config('file_upload.max_file_upload_size') ; - $allowed_extensions = ['png','jpg','jpeg','gif','pdf']; - $location = $summit->getLocation($location_id); + $max_file_size = config('file_upload.max_file_upload_size'); + $allowed_extensions = ['png', 'jpg', 'jpeg', 'gif', 'pdf']; + $location = $summit->getLocation($location_id); if (is_null($location)) { throw new EntityNotFoundException @@ -1526,7 +1530,7 @@ final class SummitLocationService ); } - if(!$location instanceof SummitGeoLocatedLocation){ + if (!$location instanceof SummitGeoLocatedLocation) { throw new EntityNotFoundException ( trans( @@ -1546,14 +1550,14 @@ final class SummitLocationService trans( 'not_found_errors.LocationService.updateLocationImage.ImageNotFound', [ - 'image_id' => $image, + 'image_id' => $image, 'location_id' => $location_id, ] ) ); } - if(!is_null($file)) { + if (!is_null($file)) { if (!in_array($file->extension(), $allowed_extensions)) { throw new ValidationException ( @@ -1619,29 +1623,29 @@ final class SummitLocationService $location = $summit->getLocation($location_id); - if(is_null($location)){ + if (is_null($location)) { throw new EntityNotFoundException ( trans ( 'not_found_errors.LocationService.deleteLocationImage.LocationNotFound', [ - 'summit_id' => $summit->getId(), - 'location_id' => $location_id, + 'summit_id' => $summit->getId(), + 'location_id' => $location_id, ] ) ); } - if(!$location instanceof SummitGeoLocatedLocation){ + if (!$location instanceof SummitGeoLocatedLocation) { throw new EntityNotFoundException ( trans ( 'not_found_errors.LocationService.deleteLocationImage.LocationNotFound', [ - 'summit_id' => $summit->getId(), - 'location_id' => $location_id, + 'summit_id' => $summit->getId(), + 'location_id' => $location_id, ] ) ); @@ -1649,15 +1653,15 @@ final class SummitLocationService $image = $location->getImage($image_id); - if(is_null($image)){ + if (is_null($image)) { throw new EntityNotFoundException ( trans ( 'not_found_errors.LocationService.deleteLocationImage.ImageNotFound', [ - 'location_id' => $location_id, - 'image_id' => $image_id, + 'location_id' => $location_id, + 'image_id' => $image_id, ] ) ); @@ -1694,11 +1698,11 @@ final class SummitLocationService $room = $summit->getLocation($room_id); if (is_null($room)) { - throw new EntityNotFoundException(); + throw new EntityNotFoundException("room not found"); } - if(!$room instanceof SummitBookableVenueRoom){ - throw new EntityNotFoundException(); + if (!$room instanceof SummitBookableVenueRoom) { + throw new EntityNotFoundException("room not found"); } $owner_id = $payload["owner_id"]; @@ -1706,9 +1710,12 @@ final class SummitLocationService $owner = $this->member_repository->getById($owner_id); if (is_null($owner)) { - throw new EntityNotFoundException(); + throw new EntityNotFoundException('member not found'); } + if($owner->getReservationsCountBySummit($summit) >= $summit->getMeetingRoomBookingMaxAllowed()) + throw new ValidationException(sprintf("member %s already reached maximun qty of reservations (%s)", $owner->getId(), $summit->getMeetingRoomBookingMaxAllowed() )); + $payload['owner'] = $owner; $reservation = SummitRoomReservationFactory::build($summit, $payload); @@ -1720,9 +1727,15 @@ final class SummitLocationService $reservation ); + if(!isset($result['cart_id'])) + throw new ValidationException("payment gateway error"); + + if(!isset($result['client_token'])) + throw new ValidationException("payment gateway error"); + $reservation->setPaymentGatewayCartId($result['cart_id']); $reservation->setPaymentGatewayClientToken($result['client_token']); - + Event::fire(new CreatedBookableRoomReservation($reservation->getId())); return $reservation; }); } @@ -1736,12 +1749,13 @@ final class SummitLocationService $this->tx_service->transaction(function () use ($payload) { $reservation = $this->reservation_repository->getByPaymentGatewayCartId($payload['cart_id']); - if(is_null($reservation)){ + if (is_null($reservation)) { throw new EntityNotFoundException(); } - if($this->payment_gateway->isSuccessFullPayment($payload)) { + if ($this->payment_gateway->isSuccessFullPayment($payload)) { $reservation->setPayed(); + Event::fire(new PaymentBookableRoomReservationConfirmed($reservation->getId())); return; } @@ -1753,32 +1767,437 @@ final class SummitLocationService * @param Summit $summit * @param Member $owner * @param int $reservation_id + * @return SummitRoomReservation * @throws EntityNotFoundException * @throws ValidationException */ - public function cancelReservation(Summit $summit, Member $owner, int $reservation_id): void + public function cancelReservation(Summit $summit, Member $owner, int $reservation_id): SummitRoomReservation { - $this->tx_service->transaction(function () use ($summit, $owner, $reservation_id) { + return $this->tx_service->transaction(function () use ($summit, $owner, $reservation_id) { $reservation = $owner->getReservationById($reservation_id); - if(is_null($reservation)){ + if (is_null($reservation)) { throw new EntityNotFoundException(); } - if($reservation->getRoom()->getSummitId() != $summit->getId()){ + if ($reservation->getRoom()->getSummitId() != $summit->getId()) { throw new EntityNotFoundException(); } - if($reservation->getStatus() == SummitRoomReservation::ReservedStatus) + if ($reservation->getStatus() == SummitRoomReservation::ReservedStatus) throw new ValidationException("can not request a refund on a reserved booking!"); - if($reservation->getStatus() == SummitRoomReservation::RequestedRefundStatus || + if ($reservation->getStatus() == SummitRoomReservation::RequestedRefundStatus || $reservation->getStatus() == SummitRoomReservation::RefundedStatus ) throw new ValidationException("can not request a refund on an already refunded booking!"); $reservation->requestRefund(); + + Event::fire(new RequestedBookableRoomReservationRefund($reservation->getId())); + + return $reservation; + }); + } + + /** + * @param SummitBookableVenueRoom $room + * @param int $reservation_id + * @param int $amount + * @return SummitRoomReservation + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function refundReservation(SummitBookableVenueRoom $room, int $reservation_id, int $amount): SummitRoomReservation + { + return $this->tx_service->transaction(function () use ($room, $reservation_id, $amount) { + + $reservation = $room->getReservationById($reservation_id); + + if (is_null($reservation)) { + throw new EntityNotFoundException(); + } + + if ($reservation->getStatus() == SummitRoomReservation::ReservedStatus) + throw new ValidationException("can not request a refund on a reserved booking!"); + + if($amount > intval($reservation->getAmount())){ + throw new ValidationException("can mot refund an amount greater than paid one!"); + } + + $this->payment_gateway->refundPayment($reservation->getPaymentGatewayCartId(), $amount); + + $reservation->setStatus(SummitRoomReservation::RefundedStatus); + + Event::fire(new CreatedBookableRoomReservation($reservation->getId())); + + return $reservation; + }); + } + + /** + * @param Summit $summit + * @param $venue_id + * @param array $data + * @return SummitBookableVenueRoom + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function addVenueBookableRoom(Summit $summit, $venue_id, array $data) + { + return $this->tx_service->transaction(function () use ($summit, $venue_id, $data) { + + if (isset($data['name'])) { + $old_location = $summit->getLocationByName(trim($data['name'])); + + if (!is_null($old_location)) { + throw new ValidationException + ( + trans + ( + 'validation_errors.LocationService.addVenueRoom.LocationNameAlreadyExists', + [ + 'summit_id' => $summit->getId() + ] + ) + ); + } + } + + $venue = $summit->getLocation($venue_id); + + if (is_null($venue)) { + throw new EntityNotFoundException + ( + trans + ( + 'not_found_errors.LocationService.addVenueRoom.VenueNotFound', + [ + 'summit_id' => $summit->getId(), + 'venue_id' => $venue_id, + ] + ) + ); + } + + if (!$venue instanceof SummitVenue) { + throw new EntityNotFoundException + ( + trans + ( + 'not_found_errors.LocationService.addVenueRoom.VenueNotFound', + [ + 'summit_id' => $summit->getId(), + 'venue_id' => $venue_id, + ] + ) + ); + } + + $data['class_name'] = SummitBookableVenueRoom::ClassName; + $room = SummitLocationFactory::build($data); + + if (is_null($room)) { + throw new ValidationException + ( + trans + ( + 'validation_errors.LocationService.addVenueRoom.InvalidClassName' + ) + ); + } + + if (isset($data['floor_id'])) { + $floor_id = intval($data['floor_id']); + $floor = $venue->getFloor($floor_id); + + if (is_null($floor)) { + throw new EntityNotFoundException + ( + trans + ( + 'not_found_errors.LocationService.addVenueRoom.FloorNotFound', + [ + 'floor_id' => $floor_id, + 'venue_id' => $venue_id + ] + ) + ); + } + + $floor->addRoom($room); + } + + $summit->addLocation($room); + $venue->addRoom($room); + + return $room; + }); + } + + /** + * @param Summit $summit + * @param int $venue_id + * @param int $room_id + * @param array $data + * @return SummitBookableVenueRoom + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function updateVenueBookableRoom(Summit $summit, $venue_id, $room_id, array $data) + { + return $this->tx_service->transaction(function () use ($summit, $venue_id, $room_id, $data) { + + if (isset($data['name'])) { + $old_location = $summit->getLocationByName(trim($data['name'])); + + if (!is_null($old_location) && $old_location->getId() != $room_id) { + throw new ValidationException + ( + trans + ( + 'validation_errors.LocationService.updateVenueRoom.LocationNameAlreadyExists', + [ + 'summit_id' => $summit->getId() + ] + ) + ); + } + } + + $venue = $summit->getLocation($venue_id); + + if (is_null($venue)) { + throw new EntityNotFoundException + ( + trans + ( + 'not_found_errors.LocationService.updateVenueRoom.VenueNotFound', + [ + 'summit_id' => $summit->getId(), + 'venue_id' => $venue_id, + ] + ) + ); + } + + if (!$venue instanceof SummitVenue) { + throw new EntityNotFoundException + ( + trans + ( + 'not_found_errors.LocationService.updateVenueRoom.VenueNotFound', + [ + 'summit_id' => $summit->getId(), + 'venue_id' => $venue_id, + ] + ) + ); + } + + $room = $summit->getLocation($room_id); + if (is_null($room)) { + throw new EntityNotFoundException + ( + trans + ( + 'not_found_errors.LocationService.updateVenueRoom.RoomNotFound', + [ + 'summit_id' => $summit->getId(), + 'venue_id' => $venue_id, + 'room_id' => $room_id, + ] + ) + ); + } + + if (!$room instanceof SummitBookableVenueRoom) { + throw new EntityNotFoundException + ( + trans + ( + 'not_found_errors.LocationService.updateVenueRoom.RoomNotFound', + [ + 'summit_id' => $summit->getId(), + 'venue_id' => $venue_id, + 'room_id' => $room_id, + ] + ) + ); + } + + SummitLocationFactory::populate($room, $data); + $floor = null; + + if (isset($data['floor_id'])) { + $old_floor_id = intval($room->getFloorId()); + $new_floor_id = intval($data['floor_id']); + if ($old_floor_id != $new_floor_id) { + $floor = $venue->getFloor($new_floor_id); + if (is_null($floor)) { + throw new EntityNotFoundException + ( + trans + ( + 'not_found_errors.LocationService.updateVenueRoom.FloorNotFound', + [ + 'floor_id' => $new_floor_id, + 'venue_id' => $venue_id + ] + ) + ); + } + if ($old_floor_id > 0) { + // remove from old floor + $room->getFloor()->removeRoom($room); + + } + $floor->addRoom($room); + } + } + + // request to update order + if (isset($data['order']) && intval($data['order']) != $room->getOrder()) { + + if (!is_null($floor)) { + $floor->recalculateRoomsOrder($room, intval($data['order'])); + } else { + $venue->recalculateRoomsOrder($room, intval($data['order'])); + } + } + + return $room; + }); + + } + + /** + * @param Summit $summit + * @param int $venue_id + * @param int $room_id + * @return void + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function deleteVenueBookableRoom(Summit $summit, $venue_id, $room_id) + { + return $this->tx_service->transaction(function () use ($summit, $venue_id, $room_id) { + + $venue = $summit->getLocation($venue_id); + + if (is_null($venue)) { + throw new EntityNotFoundException + ( + "venue not found" + ); + } + + if (!$venue instanceof SummitVenue) { + throw new EntityNotFoundException + ( + "venue not found" + ); + } + + $room = $venue->getRoom($room_id); + + if (is_null($room)) { + throw new EntityNotFoundException("room not found"); + } + + $venue->removeRoom($room); + + if ($room->hasFloor()) { + $floor = $room->getFloor(); + $floor->removeRoom($room); + } + + }); + } + + /** + * @param Summit $summit + * @param int $venue_id + * @param int $room_id + * @param int $attribute_id + * @return SummitBookableVenueRoom + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function addVenueBookableRoomAttribute(Summit $summit, int $venue_id, int $room_id, int $attribute_id): SummitBookableVenueRoom + { + return $this->tx_service->transaction(function () use ($summit, $venue_id, $room_id, $attribute_id) { + $venue = $summit->getLocation($venue_id); + + if (is_null($venue)) { + throw new EntityNotFoundException("venue not found"); + } + + if (!$venue instanceof SummitVenue) { + throw new EntityNotFoundException("venue not found"); + } + + $room = $venue->getRoom($room_id); + + if (is_null($room) || !$room instanceof SummitBookableVenueRoom) { + throw new EntityNotFoundException("room not found"); + } + + $attribute = $summit->getMeetingBookingRoomAllowedAttributeValueById($attribute_id); + + if (is_null($attribute)) { + throw new EntityNotFoundException("attribute not found"); + } + + $room->addAttribute($attribute); + + return $room; + + }); + } + + /** + * @param Summit $summit + * @param int $venue_id + * @param int $room_id + * @param int $attribute_id + * @return SummitBookableVenueRoom + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function deleteVenueBookableRoomAttribute(Summit $summit, int $venue_id, int $room_id, int $attribute_id): SummitBookableVenueRoom + { + return $this->tx_service->transaction(function () use ($summit, $venue_id, $room_id, $attribute_id) { + $venue = $summit->getLocation($venue_id); + + if (is_null($venue)) { + throw new EntityNotFoundException + ("venue not found"); + } + + if (!$venue instanceof SummitVenue) { + throw new EntityNotFoundException + ("venue not found"); + } + + $room = $venue->getRoom($room_id); + + if (is_null($room) || !$room instanceof SummitBookableVenueRoom) { + throw new EntityNotFoundException + ("room not found"); + } + + $attribute = $summit->getMeetingBookingRoomAllowedAttributeValueById($attribute_id); + + if (is_null($attribute)) { + throw new EntityNotFoundException + ("attribute not found"); + } + + $room->removeAttribute($attribute); + + return $room; }); } } \ No newline at end of file diff --git a/app/Services/Model/SummitService.php b/app/Services/Model/SummitService.php index cf9fa4e0..9797f3df 100644 --- a/app/Services/Model/SummitService.php +++ b/app/Services/Model/SummitService.php @@ -55,6 +55,8 @@ use models\summit\PresentationType; use models\summit\Summit; use models\summit\SummitAttendee; use models\summit\SummitAttendeeTicket; +use models\summit\SummitBookableVenueRoomAttributeType; +use models\summit\SummitBookableVenueRoomAttributeValue; use models\summit\SummitEvent; use models\summit\SummitEventFactory; use models\summit\SummitEventFeedback; @@ -1891,4 +1893,163 @@ final class SummitService extends AbstractService implements ISummitService }); } + + /** + * @param Summit $summit + * @param array $payload + * @return SummitBookableVenueRoomAttributeType + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function addBookableRoomAttribute(Summit $summit, array $payload): SummitBookableVenueRoomAttributeType + { + return $this->tx_service->transaction(function () use ($summit, $payload) { + + $type_name = trim($payload['type']); + $former_type = $summit->getBookableAttributeTypeByTypeName($type_name); + if(!is_null($former_type)) + throw new ValidationException(sprintf("bookable room attr type %s already exists on summit %s", $type_name, $summit->getId())); + + $type = new SummitBookableVenueRoomAttributeType(); + $type->setType($type_name); + + $summit->addMeetingBookingRoomAllowedAttribute($type); + + return $type; + + }); + } + + /** + * @param Summit $summit + * @param int $type_id + * @param array $payload + * @return SummitBookableVenueRoomAttributeType + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function updateBookableRoomAttribute(Summit $summit, int $type_id, array $payload): SummitBookableVenueRoomAttributeType + { + return $this->tx_service->transaction(function () use ($summit, $type_id, $payload) { + $type = $summit->getBookableAttributeTypeById($type_id); + if(is_null($type)) + throw new EntityNotFoundException(); + + $type_name = trim($payload['type']); + $former_type = $summit->getBookableAttributeTypeByTypeName($type_name); + if(!is_null($former_type) && $type_id != $former_type->getId()) + throw new ValidationException(sprintf("bookable room attr type %s already exists on summit %s", $type_name, $summit->getId())); + + $type->setType($type_name); + + return $type; + + }); + } + + /** + * @param Summit $summit + * @param int $type_id + * @return void + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function deleteBookableRoomAttribute(Summit $summit, int $type_id): void + { + $this->tx_service->transaction(function () use ($summit, $type_id) { + $type = $summit->getBookableAttributeTypeById($type_id); + if(is_null($type)) + throw new EntityNotFoundException(); + + $summit->removeMeetingBookingRoomAllowedAttribute($type); + }); + } + + /** + * @param Summit $summit + * @param int $type_id + * @param array $payload + * @return SummitBookableVenueRoomAttributeValue + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function addBookableRoomAttributeValue(Summit $summit, int $type_id, array $payload): SummitBookableVenueRoomAttributeValue + { + return $this->tx_service->transaction(function () use ($summit, $type_id, $payload) { + + $type = $summit->getBookableAttributeTypeById($type_id); + if (is_null($type)) + throw new EntityNotFoundException(); + + $value_name = trim($payload['value']); + $former_value = $type->getValueByValue($value_name); + if (!is_null($former_value)) + throw new ValidationException(sprintf("bookable room attr value %s already exists on summit %s", $value_name, $summit->getId())); + + $value = new SummitBookableVenueRoomAttributeValue(); + $value->setValue($value_name); + $type->addValue($value); + + return $value; + + }); + } + + /** + * @param Summit $summit + * @param int $type_id + * @param int $value_id + * @param array $payload + * @return SummitBookableVenueRoomAttributeValue + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function updateBookableRoomAttributeValue(Summit $summit, int $type_id, int $value_id, array $payload): SummitBookableVenueRoomAttributeValue + { + return $this->tx_service->transaction(function () use ($summit, $type_id, $value_id, $payload) { + + $type = $summit->getBookableAttributeTypeById($type_id); + if (is_null($type)) + throw new EntityNotFoundException(); + + $value = $type->getValueById($value_id); + if (is_null($value)) + throw new EntityNotFoundException(); + + $value_name = trim($payload['value']); + $former_value = $type->getValueByValue($value_name); + if (!is_null($former_value) && $value_id != $former_value->getId()) + throw new ValidationException(sprintf("bookable room attr value %s already exists on summit %s", $value_name, $summit->getId())); + + $value->setValue($value_name); + + return $value; + + }); + } + + /** + * @param Summit $summit + * @param int $type_id + * @param int $value_id + * @return void + * @throws ValidationException + * @throws EntityNotFoundException + */ + public function deleteBookableRoomAttributeValue(Summit $summit, int $type_id, int $value_id): void + { + $this->tx_service->transaction(function () use ($summit, $type_id, $value_id) { + + $type = $summit->getBookableAttributeTypeById($type_id); + if (is_null($type)) + throw new EntityNotFoundException(); + + $value = $type->getValueById($value_id); + if (is_null($value)) + throw new EntityNotFoundException(); + + $type->removeValue($value); + + }); + } } \ No newline at end of file diff --git a/database/seeds/ApiEndpointsSeeder.php b/database/seeds/ApiEndpointsSeeder.php index deaa185d..a94d294d 100644 --- a/database/seeds/ApiEndpointsSeeder.php +++ b/database/seeds/ApiEndpointsSeeder.php @@ -152,6 +152,91 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::ReadAllSummitData, $current_realm) ], ], + // bookable rooms attributes types + [ + 'name' => 'get-summit-bookable-room-attribute-types', + 'route' => '/api/v1/summits/{id}/bookable-room-attribute-types', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadSummitData, $current_realm), + sprintf(SummitScopes::ReadAllSummitData, $current_realm) + ], + ], + [ + 'name' => 'get-summit-bookable-room-attribute-types-by-id', + 'route' => '/api/v1/summits/{id}/bookable-room-attribute-types/{type_id}', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadSummitData, $current_realm), + sprintf(SummitScopes::ReadAllSummitData, $current_realm) + ], + ], + [ + 'name' => 'update-summit-bookable-room-attribute-type', + 'route' => '/api/v1/summits/{id}/bookable-room-attribute-types/{type_id}', + 'http_method' => 'PUT', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + ], + ], + [ + 'name' => 'delete-summit-bookable-room-attribute-type', + 'route' => '/api/v1/summits/{id}/bookable-room-attribute-types/{type_id}', + 'http_method' => 'DELETE', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + ], + ], + [ + 'name' => 'add-summit-bookable-room-attribute-type', + 'route' => '/api/v1/summits/{id}/bookable-room-attribute-types', + 'http_method' => 'POST', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + ], + ], + [ + 'name' => 'get-summit-bookable-room-attribute-type-values', + 'route' => '/api/v1/summits/{id}/bookable-room-attribute-types/{type_id}/values', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadSummitData, $current_realm), + sprintf(SummitScopes::ReadAllSummitData, $current_realm) + ], + ], + [ + 'name' => 'add-summit-bookable-room-attribute-type-values', + 'route' => '/api/v1/summits/{id}/bookable-room-attribute-types/{type_id}/values', + 'http_method' => 'POST', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + ], + ], + [ + 'name' => 'get-summit-bookable-room-attribute-type-value', + 'route' => '/api/v1/summits/{id}/bookable-room-attribute-types/{type_id}/values/{value_id}', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadSummitData, $current_realm), + sprintf(SummitScopes::ReadAllSummitData, $current_realm) + ], + ], + [ + 'name' => 'update-summit-bookable-room-attribute-type-value', + 'route' => '/api/v1/summits/{id}/bookable-room-attribute-types/{type_id}/values/{value_id}', + 'http_method' => 'PUT', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + ], + ], + [ + 'name' => 'delete-summit-bookable-room-attribute-type-value', + 'route' => '/api/v1/summits/{id}/bookable-room-attribute-types/{type_id}/values/{value_id}', + 'http_method' => 'DELETE', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + ], + ], // attendees [ 'name' => 'get-attendees', @@ -1103,6 +1188,33 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::WriteMyBookableRoomsReservationData, $current_realm), ], ], + [ + 'name' => 'refund-bookable-venue-room-reservation', + 'route' => '/api/v1/summits/{id}/locations/bookable-rooms/{room_id}/reservations/{reservation_id}/refund', + 'http_method' => 'DELETE', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteBookableRoomsData, $current_realm), + ], + ], + [ + 'name' => 'get-bookable-venue-room-reservations-by-summit', + 'route' => '/api/v1/summits/{id}/locations/bookable-rooms/all/reservations', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadAllSummitData, $current_realm), + sprintf(SummitScopes::ReadSummitData, $current_realm), + ], + ], + [ + 'name' => 'get-bookable-venue-room-reservation', + 'route' => '/api/v1/summits/{id}/locations/bookable-rooms/{room_id}/reservations/{reservation_id}', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadAllSummitData, $current_realm), + sprintf(SummitScopes::ReadSummitData, $current_realm), + ], + ], [ 'name' => 'create-bookable-venue-room-reservation', 'route' => '/api/v1/summits/{id}/locations/bookable-rooms/{room_id}/reservations', @@ -1138,6 +1250,25 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::WriteBookableRoomsData, $current_realm), ], ], + // bookable room attributes + [ + 'name' => 'add-bookable-venue-room-attribute', + 'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/bookable-rooms/{room_id}/attributes/{attribute_id}', + 'http_method' => 'PUT', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteBookableRoomsData, $current_realm), + ], + ], + [ + 'name' => 'remove-bookable-venue-room-attribute', + 'route' => '/api/v1/summits/{id}/locations/venues/{venue_id}/bookable-rooms/{room_id}/attributes/{attribute_id}', + 'http_method' => 'DELETE', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteBookableRoomsData, $current_realm), + ], + ], // floor rooms [ 'name' => 'get-venue-floor-room', diff --git a/tests/OAuth2BookableRoomAttributeTypesApiTest.php b/tests/OAuth2BookableRoomAttributeTypesApiTest.php new file mode 100644 index 00000000..c847c97b --- /dev/null +++ b/tests/OAuth2BookableRoomAttributeTypesApiTest.php @@ -0,0 +1,117 @@ + $summit_id, + 'page' => 1 , + 'per_page' => 10, + 'expand' => 'values' + ]; + + $headers = array("HTTP_Authorization" => " Bearer " .$this->access_token); + $response = $this->action( + "GET", + "OAuth2SummitBookableRoomsAttributeTypeApiController@getAllBookableRoomAttributeTypes", + $params, + [], + [], + [], + $headers + ); + + $content = $response->getContent(); + $attributes = json_decode($content); + + $this->assertResponseStatus(200); + $this->assertTrue(count($attributes->data) > 0); + } + + + public function testAddAttributeType($summit_id = 27){ + $params = [ + 'id' => $summit_id, + ]; + + $type = str_random(16).'_attribute_type'; + + $data = [ + 'type' => $type + ]; + + $headers = [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action( + "POST", + "OAuth2SummitBookableRoomsAttributeTypeApiController@addBookableRoomAttributeType", + $params, + [], + [], + [], + $headers, + json_encode($data) + ); + + $content = $response->getContent(); + $this->assertResponseStatus(201); + $attribute_type = json_decode($content); + $this->assertTrue(!is_null($attribute_type)); + return $attribute_type; + } + + public function testAddAttributeValue($summit_id = 27){ + $type = $this->testAddAttributeType($summit_id); + $params = [ + 'id' => $summit_id, + 'type_id' => $type->id, + ]; + + $val = str_random(16).'_attribute_value'; + + $data = [ + 'value' => $val + ]; + + $headers = [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action( + "POST", + "OAuth2SummitBookableRoomsAttributeTypeApiController@addBookableRoomAttributeValue", + $params, + [], + [], + [], + $headers, + json_encode($data) + ); + + $content = $response->getContent(); + $this->assertResponseStatus(201); + $attribute_value = json_decode($content); + $this->assertTrue(!is_null($attribute_value)); + return $attribute_value; + } +} \ No newline at end of file diff --git a/tests/OAuth2SummitLocationsApiTest.php b/tests/OAuth2SummitLocationsApiTest.php index 8d36c982..aa9082ef 100644 --- a/tests/OAuth2SummitLocationsApiTest.php +++ b/tests/OAuth2SummitLocationsApiTest.php @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ - +use LaravelDoctrine\ORM\Facades\EntityManager; /** * Class OAuth2SummitLocationsApiTest */ @@ -1527,4 +1527,185 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest $this->assertTrue(!is_null($reservations)); } + /** + * @param int $summit_id + */ + public function testAddBookableRoom($summit_id = 27){ + $summit_repository = EntityManager::getRepository(\models\summit\Summit::class); + $summit = $summit_repository->getById($summit_id); + $this->assertTrue(!is_null($summit)); + if(!$summit instanceof \models\summit\Summit) return; + $venues = $summit->getVenues(); + $this->assertTrue($venues->count() > 0 ); + $venue = $venues->first(); + + $params = [ + 'id' => $summit_id, + 'venue_id' => $venue->getId() + ]; + + $name = str_random(16).'_bookable_room'; + + $data = [ + 'name' => $name, + 'capacity' => 10, + 'description' => 'test bookable room', + 'time_slot_cost' => 200, + 'currency' => 'USD', + ]; + + $headers = + [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action + ( + "POST", + "OAuth2SummitLocationsApiController@addVenueBookableRoom", + $params, + [], + [], + [], + $headers, + json_encode($data) + ); + + $content = $response->getContent(); + $this->assertResponseStatus(201); + + $bookable_room = json_decode($content); + $this->assertTrue(!is_null($bookable_room)); + $this->assertTrue($bookable_room->name == $name); + + return $bookable_room; + } + + public function testUpdateBookableRooms($summit_id = 27){ + $bookable_room = $this->testAddBookableRoom($summit_id); + $this->assertTrue(!is_null($bookable_room)); + + $params = [ + 'id' => $summit_id, + 'venue_id' => $bookable_room->venue_id, + 'room_id' => $bookable_room->id, + ]; + + $name = str_random(16).'_bookable_room_update'; + + $data = [ + 'name' => $name, + 'capacity' => 14, + 'time_slot_cost' => 250, + ]; + + $headers = + [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action + ( + "PUT", + "OAuth2SummitLocationsApiController@updateVenueBookableRoom", + $params, + [], + [], + [], + $headers, + json_encode($data) + ); + + $content = $response->getContent(); + $this->assertResponseStatus(201); + + $bookable_room = json_decode($content); + $this->assertTrue(!is_null($bookable_room)); + $this->assertTrue($bookable_room->name == $name); + + return $bookable_room; + + } + + + /** + * @param int $summit_id + */ + public function testAddBookableRoomAttributeValue($summit_id = 27){ + $summit_repository = EntityManager::getRepository(\models\summit\Summit::class); + $summit = $summit_repository->getById($summit_id); + $this->assertTrue(!is_null($summit)); + if(!$summit instanceof \models\summit\Summit) return; + + $rooms = $summit->getBookableRooms(); + $room = $rooms->first(); + $attributes = $summit->getMeetingBookingRoomAllowedAttributes(); + $attribute = $attributes->last(); + $values = $attribute->getValues(); + $value = $values->first(); + + $params = [ + 'id' => $summit_id, + 'venue_id' => $room->getVenueId(), + 'room_id' => $room->getId(), + 'attribute_id' => $value->getId() + ]; + + $headers = + [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action + ( + "PUT", + "OAuth2SummitLocationsApiController@addVenueBookableRoomAttribute", + $params, + [], + [], + [], + $headers + ); + + $content = $response->getContent(); + $this->assertResponseStatus(201); + + $bookable_room = json_decode($content); + $this->assertTrue(!is_null($bookable_room)); + + } + + + public function testGetAllReservationsBySummit($summit_id =27){ + $params = [ + 'id' => $summit_id, + 'filter' => 'status==Reserved,room_id==1' + ]; + + $headers = + [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action + ( + "GET", + "OAuth2SummitLocationsApiController@getAllReservationsBySummit", + $params, + [], + [], + [], + $headers + ); + + $content = $response->getContent(); + $this->assertResponseStatus(200); + + $reservations = json_decode($content); + $this->assertTrue(!is_null($reservations)); + } } \ No newline at end of file