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