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