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