customerService = new CustomerService(); $this->smsService = new SmsService($this->customerService); $this->whatsappService = new WhatsAppService($this->customerService); $this->emailService = new EmailService($this->customerService); $this->contactGroupService = new ContactGroupService(); $this->smsGatewayService = new SmsGatewayService(); $this->whatsappGatewayService = new WhatsappGatewayService(); $this->emailGatewayService = new EmailGatewayService(); $this->campaignService = new CampaignService($this->smsService, $this->emailService, $this->whatsappService, $this->contactGroupService, $this->smsGatewayService, $this->whatsappGatewayService, $this->emailGatewayService); } /** * @return \Illuminate\View\View * */ public function index(): View { Session::put("menu_active", true); $title = translate("Campaign Log"); $user = auth()->user(); $campaigns = $this->campaignService->logs(auth()->user()->id); return view('user.communication.campaigns', compact('title', 'campaigns', 'user')); } public function createSms() { Session::put("menu_active", true); $type = "sms"; $user = auth()->user(); $remaining_credit = $user->sms_credit; $title = translate("Create an SMS Camapign"); $groups = $this->smsService->getGroupWhereColumn('sms_contact', $user->id); $templates = $this->smsService->getTemplateWithStatusType(StatusEnum::TRUE->status(), constant(ServiceType::class . '::' . strtoupper($type))->value, $user->id); $plan_access = (object)planAccess($user); $api_gateways = $this->smsService->smsGateway($plan_access->type); $android_gateways = $this->smsService->androidGateways(StatusEnum::TRUE->status(), $plan_access->type); return view('user.communication.sms.campaign.create', compact('title', 'remaining_credit', 'groups', 'type', 'templates', 'plan_access', 'api_gateways', 'android_gateways')); } public function createWhatsapp() { Session::put("menu_active", true); $type = "whatsapp"; $user = auth()->user(); $title = translate("Create an WhatsApp Camapign"); $remaining_credit = $user->whatsapp_credit; $groups = $this->whatsappService->getGroupWhereColumn('whatsapp_contact', $user->id); $templates = $this->whatsappService->getTemplateWithStatusType(StatusEnum::TRUE->status(), constant(ServiceType::class . '::' . strtoupper($type))->value); $plan_access = (object)planAccess($user); $cloud_api_accounts = $this->whatsappService->gateways(StatusEnum::TRUE->status(), $user->id); $devices = $this->whatsappService->gateways(StatusEnum::FALSE->status(), $user->id); return view('user.communication.whatsapp.campaign.create', compact('title', 'remaining_credit', 'groups', 'type', 'templates', 'cloud_api_accounts', 'devices')); } public function createEmail() { Session::put("menu_active", true); $type = "email"; $user = auth()->user(); $title = translate("Create an Email Camapign"); $groups = $this->emailService->getGroupWhereColumn('email_contact', $user->id); $templates = $this->emailService->getTemplateWithStatusType(StatusEnum::TRUE->status(), constant(ServiceType::class . '::' . strtoupper($type))->value); $plan_access = (object)planAccess($user); $gateways = $this->emailService->gateways(StatusEnum::TRUE->status(), $plan_access->type); return view('user.communication.email.campaign.create', compact('title', 'groups', 'type', 'templates', 'gateways')); } public function editSms($id) { Session::put("menu_active", true); $type = "sms"; $user = auth()->user(); $title = translate("Update SMS Camapign"); $campaign = Campaign::find($id); $groups = $this->smsService->getGroupWhereColumn('sms_contact', $user->id); $templates = $this->smsService->getTemplateWithStatusType(StatusEnum::TRUE->status(), constant(ServiceType::class . '::' . strtoupper($type))->value); $remaining_credit = $user->sms_credit; $plan_access = (object)planAccess($user); $api_gateways = $this->smsService->smsGateway($plan_access->type); $android_gateways = $this->smsService->androidGateways(StatusEnum::TRUE->status(), $plan_access->type); return view('user.communication.sms.campaign.edit', compact('title', 'groups', 'type', 'remaining_credit', 'plan_access', 'templates', 'api_gateways', 'android_gateways', 'campaign')); } public function editWhatsapp($id) { Session::put("menu_active", true); $type = "whatsapp"; $user = auth()->user(); $title = translate("Update WhatsApp Camapign"); $campaign = Campaign::find($id); $groups = $this->smsService->getGroupWhereColumn('whatsapp_contact', $user->id); $templates = $this->whatsappService->getTemplateWithStatusType(StatusEnum::TRUE->status(), constant(ServiceType::class . '::' . strtoupper($type))->value); $remaining_credit = $user->whatsapp_credit; $plan_access = (object)planAccess($user); $cloud_api_accounts = $this->whatsappService->gateways(StatusEnum::TRUE->status(), $user->id); $devices = $this->whatsappService->gateways(StatusEnum::FALSE->status(), $user->id); return view('user.communication.whatsapp.campaign.edit', compact('title', 'groups', 'remaining_credit', 'type', 'templates', 'cloud_api_accounts', 'devices', 'campaign')); } public function editEmail($id) { Session::put("menu_active", true); $type = "email"; $user = auth()->user(); $title = translate("Update Email Camapign"); $campaign = Campaign::find($id); $groups = $this->emailService->getGroupWhereColumn('email_contact', $user->id); $templates = $this->emailService->getTemplateWithStatusType(StatusEnum::TRUE->status(),constant(ServiceType::class . '::' . strtoupper($type))->value); $plan_access = (object)planAccess($user); $gateways = $this->emailService->gateways(StatusEnum::TRUE->status(), $plan_access->type); return view('user.communication.email.campaign.edit', compact('title', 'groups', 'type', 'templates', 'gateways', 'campaign')); } public function saveSms(SmsCampaignRequest $request, $type) { $status = 'error'; $message = "Something went wrong"; try { $data = $request->all(); unset($data['_token']); $user = auth()->user(); list($status, $message) = $this->campaignService->save($type, $data, $user->id); } catch (\Exception $e) { $message = translate("Server Error"); } $notify[] = [$status, $message]; return back()->withNotify($notify); } public function saveWhatsapp(WhatsappCampaignRequest $request, $type) { $status = 'error'; $message = "Something went wrong"; try { $data = $request->all(); unset($data['_token']); $user = auth()->user(); list($status, $message) = $this->campaignService->save($type, $data, $user->id); } catch (\Exception $e) { $message = translate("Server Error"); } $notify[] = [$status, $message]; return back()->withNotify($notify); } public function saveEmail(EmailCampaignRequest $request, $type) { $status = 'error'; $message = "Something went wrong"; try { $data = $request->all(); unset($data['_token']); $user = auth()->user(); list($status, $message) = $this->campaignService->save($type, $data, $user->id); } catch (\Exception $e) { $message = translate("Server Error"); } $notify[] = [$status, $message]; return back()->withNotify($notify); } public function delete(Request $request) { $status = 'error'; $message = "Something went wrong"; try { if($request->has('id')) { $campaign = Campaign::find($request->input('id')); $campaign->communicationLog()->delete(); $campaign->delete(); $status = 'success'; $message = translate("Campaign deleted successfully"); } else { $message = translate("Campaign couldnt be found"); } } catch (\Exception $e) { $message = translate("Server Error"); } $notify[] = [$status, $message]; return back()->withNotify($notify); } /** * * @param Request $request * * @return \Illuminate\Http\RedirectResponse * */ public function bulk(Request $request) :RedirectResponse { $status = 'success'; $message = translate("Successfully Performed bulk action"); try { list($status, $message) = $this->bulkAction($request, null, [ "model" => new Campaign(), ]); } catch (\Exception $exception) { $status = 'error'; $message = translate("Server Error: ").$exception->getMessage(); } $notify[] = [$status, $message]; return back()->withNotify($notify); } /** * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\JsonResponse * * @throws ValidationException If the validation fails. * */ public function statusUpdate(Request $request) { try { $this->validate($request,[ 'id' => 'required', 'value' => 'required', 'column' => 'required', ]); $user = auth()->user(); $notify = $this->campaignService->statusUpdate($request, $user->id); return $notify; } catch (ValidationException $validation) { return json_encode([ 'status' => false, 'message' => $validation->errors() ]); } } }