summit_repository = $summit_repository; $this->selection_plan_service = $selection_plan_service; } /** * @param $summit_id * @param $selection_plan_id * @return mixed */ public function getSelectionPlan($summit_id, $selection_plan_id){ try { $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); $selection_plan = $summit->getSelectionPlanById($selection_plan_id); if (is_null($selection_plan)) return $this->error404(); return $this->ok(SerializerRegistry::getInstance()->getSerializer($selection_plan)->serialize(Request::input('expand', ''))); } catch (ValidationException $ex) { Log::warning($ex); return $this->error412($ex->getMessages()); } catch(EntityNotFoundException $ex) { Log::warning($ex); return $this->error404($ex->getMessage()); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @param $selection_plan_id * @return mixed */ public function updateSelectionPlan($summit_id, $selection_plan_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 = SummitSelectionPlanValidationRulesFactory::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 ); } $selection_plan = $this->selection_plan_service->updateSelectionPlan($summit, $selection_plan_id, $payload); return $this->updated(SerializerRegistry::getInstance()->getSerializer($selection_plan)->serialize()); } catch (ValidationException $ex) { Log::warning($ex); return $this->error412($ex->getMessages()); } catch(EntityNotFoundException $ex) { Log::warning($ex); return $this->error404($ex->getMessage()); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @return mixed */ public function addSelectionPlan($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 = SummitSelectionPlanValidationRulesFactory::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 ); } $selection_plan = $this->selection_plan_service->addSelectionPlan($summit, $payload); return $this->created(SerializerRegistry::getInstance()->getSerializer($selection_plan)->serialize()); } catch (ValidationException $ex) { Log::warning($ex); return $this->error412($ex->getMessages()); } catch(EntityNotFoundException $ex) { Log::warning($ex); return $this->error404($ex->getMessage()); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @param $selection_plan_id * @return mixed */ public function deleteSelectionPlan($summit_id, $selection_plan_id){ try { $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); $this->selection_plan_service->deleteSelectionPlan($summit, $selection_plan_id); return $this->deleted(); } catch (ValidationException $ex) { Log::warning($ex); return $this->error412($ex->getMessages()); } catch(EntityNotFoundException $ex) { Log::warning($ex); return $this->error404($ex->getMessage()); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @param $selection_plan_id * @param $track_group_id * @return mixed */ public function addTrackGroupToSelectionPlan($summit_id, $selection_plan_id, $track_group_id){ try { $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); $this->selection_plan_service->addTrackGroupToSelectionPlan($summit, $selection_plan_id, $track_group_id); return $this->deleted(); } catch (ValidationException $ex) { Log::warning($ex); return $this->error412($ex->getMessages()); } catch(EntityNotFoundException $ex) { Log::warning($ex); return $this->error404($ex->getMessage()); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @param $selection_plan_id * @param $track_group_id * @return mixed */ public function deleteTrackGroupToSelectionPlan($summit_id, $selection_plan_id, $track_group_id){ try { $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); $this->selection_plan_service->deleteTrackGroupToSelectionPlan($summit, $selection_plan_id, $track_group_id); return $this->deleted(); } catch (ValidationException $ex) { Log::warning($ex); return $this->error412($ex->getMessages()); } catch(EntityNotFoundException $ex) { Log::warning($ex); return $this->error404($ex->getMessage()); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } /** * @param $summit_id * @param $status * @return \Illuminate\Http\JsonResponse|mixed */ public function getCurrentSelectionPlanByStatus($summit_id, $status){ try { $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); $selection_plan = $this->selection_plan_service->getCurrentSelectionPlanByStatus($summit, $status); if (is_null($selection_plan)) return $this->error404(); return $this->ok(SerializerRegistry::getInstance()->getSerializer($selection_plan)->serialize(Request::input('expand', ''))); } catch (ValidationException $ex) { Log::warning($ex); return $this->error412($ex->getMessages()); } catch(EntityNotFoundException $ex) { Log::warning($ex); return $this->error404($ex->getMessage()); } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); } } }