all(); $viewing = ViewingWorkflow::run($trasition, $viewing, $request); $data = new ViewingResource($viewing); return $this->response->message(trans('messages.success.updated', ['Module' => trans('opportunity::viewing.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('opportunity/viewing/' . $viewing->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('opportunity/viewing/' . $viewing->getRouteKey())) ->redirect(); } } /** * Get the viewing and user for the workflow. * * @param PublicRequest $request * @param string $viewing * @param string $user * * @return Response */ public function get(PublicRequest $request, $viewing, $user) { if (!$request->hasValidSignature()) { abort(403, 'This url is expired!'); } $auth = Auth::guard()->getProvider()->getModel(); $user = $auth::findBySignedId($user); Auth::guard()->login($user); $viewing = Viewing::findBySignedId($viewing); $transitions = $this->transitions($viewing, $user); $user = user(); Auth::logout(); return $this->response->setMetaTitle(trans('opportunity::viewing.name') . ' ' . trans('Approvals')) ->view('opportunity::public.viewing.workflow') ->layout('mobile') ->data(compact('viewing', 'user', 'transitions')) ->output(); } /** * Display the workflow form for the viewing. * * @param PublicRequest $request * @param string $viewing * @param string $user * * @return Response */ public function post(PublicRequest $request, $viewing, $user) { if (!$request->hasValidSignature()) { abort(403, 'This url is expired!'); } $transition = $request->transition; $auth = Auth::guard()->getProvider()->getModel(); $user = $auth::findBySignedId($user); Auth::guard()->login($user); $viewing = Viewing::findBySignedId($viewing); $user = user(); $viewing = ViewingWorkflow::run($transition, $viewing, $request->all()); Auth::logout(); return response()->json( [ 'status' => 'success', 'url' => $request->url(), ] ); } private function transitions($viewing, $user) { $transitions = []; foreach ($viewing->workflow()->transitions($viewing) as $key => $value) { $name = $value->getName(); $array['url'] = URL::temporarySignedRoute('litecms.viewing.workflow', now()->addMinutes(3), [ 'guard' => 'admin', 'transition' => $name, 'viewing' => $viewing->getSignedId(now()->addMinutes(3)), 'user' => $user->getSignedId(now()->addMinutes(3)), 'trans' => 'en', ] ); $array['name'] = $name; $array['key'] = $name; $array['form'] = $viewing->workflow()->form($value); $array['label'] = trans('opportunity::viewing.workflow.' . $name); $transitions[] = $array; } return $transitions; } }