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