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