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