repository = $theme; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Survey\Survey\Repositories\Criteria\ThemeResourceCriteria::class); } /** * Display a list of theme. * * @return Response */ public function index(ThemeRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Survey\Survey\Repositories\Presenter\ThemePresenter::class) ->$function(); } $themes = $this->repository->paginate(); return $this->response->setMetaTitle(trans('survey::theme.names')) ->view('survey::theme.index', true) ->data(compact('themes', 'view')) ->output(); } /** * Display theme. * * @param Request $request * @param Model $theme * * @return Response */ public function show(ThemeRequest $request, Theme $theme) { if ($theme->exists) { $view = 'survey::theme.show'; } else { $view = 'survey::theme.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('survey::theme.name')) ->data(compact('theme')) ->view($view, true) ->output(); } /** * Show the form for creating a new theme. * * @param Request $request * * @return Response */ public function create(ThemeRequest $request) { $theme = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('survey::theme.name')) ->view('survey::theme.create', true) ->data(compact('theme')) ->output(); } /** * Create new theme. * * @param Request $request * * @return Response */ public function store(ThemeRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $theme = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('survey::theme.name')])) ->code(204) ->status('success') ->url(guard_url('survey/theme/' . $theme->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/survey/theme')) ->redirect(); } } /** * Show theme for editing. * * @param Request $request * @param Model $theme * * @return Response */ public function edit(ThemeRequest $request, Theme $theme) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('survey::theme.name')) ->view('survey::theme.edit', true) ->data(compact('theme')) ->output(); } /** * Update the theme. * * @param Request $request * @param Model $theme * * @return Response */ public function update(ThemeRequest $request, Theme $theme) { try { $attributes = $request->all(); $theme->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('survey::theme.name')])) ->code(204) ->status('success') ->url(guard_url('survey/theme/' . $theme->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('survey/theme/' . $theme->getRouteKey())) ->redirect(); } } /** * Remove the theme. * * @param Model $theme * * @return Response */ public function destroy(ThemeRequest $request, Theme $theme) { try { $theme->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('survey::theme.name')])) ->code(202) ->status('success') ->url(guard_url('survey/theme/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('survey/theme/' . $theme->getRouteKey())) ->redirect(); } } /** * Remove multiple theme. * * @param Model $theme * * @return Response */ public function delete(ThemeRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('survey::theme.name')])) ->status("success") ->code(202) ->url(guard_url('survey/theme')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/survey/theme')) ->redirect(); } } /** * Restore deleted themes. * * @param Model $theme * * @return Response */ public function restore(ThemeRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('survey::theme.name')])) ->status("success") ->code(202) ->url(guard_url('/survey/theme')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/survey/theme/')) ->redirect(); } } }