repository = $summit_repository; $this->speaker_repository = $speaker_repository; $this->event_repository = $event_repository; $this->event_feedback_repository = $event_feedback_repository; $this->service = $service; } public function getLocations($summit_id) { try { $summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id); if (is_null($summit)) return $this->error404(); //locations $locations = array(); foreach ($summit->getLocations() as $location) { $locations[] = SerializerRegistry::getInstance()->getSerializer($location)->serialize(); } $response = new PagingResponse ( count($locations), count($locations), 1, 1, $locations ); return $this->ok($response->toArray($expand = Input::get('expand',''))); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @param $location_id * @return mixed */ public function getLocation($summit_id, $location_id) { try { $expand = Request::input('expand', ''); $relations = Request::input('relations', ''); $relations = !empty($relations) ? explode(',', $relations) : []; $summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id); if (is_null($summit)) return $this->error404(); $location = $summit->getLocation($location_id); if (is_null($location)) { return $this->error404(); } return $this->ok(SerializerRegistry::getInstance()->getSerializer($location)->serialize($expand,[], $relations)); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param string $summit_id * @param int $location_id * @param bool $published * @return PagingResponse * @throws EntityNotFoundException * @throws ValidationException */ private function _getLocationEvents($summit_id, $location_id, $published = true) { $summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id); if (is_null($summit)) throw new EntityNotFoundException; $location = $summit->getLocation($location_id); if (is_null($location)) throw new EntityNotFoundException; $values = Input::all(); $rules = array ( 'page' => 'integer|min:1', 'per_page' => 'required_with:page|integer|min:5|max:100', ); $validation = Validator::make($values, $rules); if ($validation->fails()) { $ex = new ValidationException(); throw $ex->setMessages($validation->messages()->toArray()); } // default values $page = 1; $per_page = 5; 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'), [ 'title' => ['=@', '=='], 'start_date' => ['>', '<', '<=', '>=', '=='], 'end_date' => ['>', '<', '<=', '>=', '=='], 'speaker' => ['=@', '=='], 'tags' => ['=@', '=='], 'event_type_id' => ['=='], 'track_id' => ['=='] ]); } $order = null; if (Input::has('order')) { $order = OrderParser::parse(Input::get('order'), [ 'title', 'start_date', 'end_date', 'id', 'created', ]); } if(is_null($filter)) $filter = new Filter(); $filter->addFilterCondition(FilterParser::buildFilter('location_id','==', $location_id)); if($published) { $filter->addFilterCondition(FilterParser::buildFilter('published','==', 1)); } return $this->event_repository->getAllByPage(new PagingInfo($page, $per_page), $filter, $order); } /** * @param $summit_id * @param $location_id * @return mixed */ public function getLocationEvents($summit_id, $location_id) { try { return $this->ok($this->_getLocationEvents($summit_id, $location_id, false)->toArray(Request::input('expand', ''))); } catch (EntityNotFoundException $ex1) { Log::warning($ex1); return $this->error404(); } catch (ValidationException $ex2) { Log::warning($ex2); return $this->error412($ex2->getMessages()); } catch(FilterParserException $ex3){ Log::warning($ex3); return $this->error412($ex3->getMessages()); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @param $location_id * @return mixed */ public function getLocationPublishedEvents($summit_id, $location_id) { try { return $this->ok($this->_getLocationEvents($summit_id, $location_id, true)->toArray(Request::input('expand', ''))); } catch (EntityNotFoundException $ex1) { Log::warning($ex1); return $this->error404(); } catch (ValidationException $ex2) { Log::warning($ex2); return $this->error412($ex2->getMessages()); } catch(FilterParserException $ex3){ Log::warning($ex3); return $this->error412($ex3->getMessages()); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @return mixed */ public function getVenues($summit_id) { try { $summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id); if (is_null($summit)) return $this->error404(); //locations $locations = array(); foreach ($summit->getVenues() as $location) { $locations[] = SerializerRegistry::getInstance()->getSerializer($location)->serialize(); } $response = new PagingResponse ( count($locations), count($locations), 1, 1, $locations ); return $this->ok($response->toArray($expand = Input::get('expand',''))); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @return mixed */ public function getExternalLocations($summit_id) { try { $summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id); if (is_null($summit)) return $this->error404(); //locations $locations = array(); foreach ($summit->getExternalLocations() as $location) { $locations[] = SerializerRegistry::getInstance()->getSerializer($location)->serialize(); } $response = new PagingResponse ( count($locations), count($locations), 1, 1, $locations ); return $this->ok($response->toArray($expand = Input::get('expand',''))); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @return mixed */ public function getHotels($summit_id) { try { $summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id); if (is_null($summit)) return $this->error404(); //locations $locations = array(); foreach ($summit->getHotels() as $location) { $locations[] = SerializerRegistry::getInstance()->getSerializer($location)->serialize(); } $response = new PagingResponse ( count($locations), count($locations), 1, 1, $locations ); return $this->ok($response->toArray($expand = Input::get('expand',''))); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @return mixed */ public function getAirports($summit_id) { try { $summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id); if (is_null($summit)) return $this->error404(); //locations $locations = array(); foreach ($summit->getAirports() as $location) { $locations[] = SerializerRegistry::getInstance()->getSerializer($location)->serialize(); } $response = new PagingResponse ( count($locations), count($locations), 1, 1, $locations ); return $this->ok($response->toArray($expand = Input::get('expand',''))); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } }