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