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