예제 #1
0
 public function templates($departments)
 {
     foreach ($departments as $department) {
         if (!isset($this->data['templates'][$department->id])) {
             $this->data['templates'][$department->id] = simpleSelect(EmailTemplate::where('system', 1)->where('department_id', $department->id)->get(), true);
         }
     }
     return $this->data['templates'];
 }
예제 #2
0
 public function templates()
 {
     $records = $templates = [];
     $records[] = ['' => trans('static.select')];
     if (request()->has('department_id')) {
         $templates = EmailTemplate::where('department_id', request()->get('department_id'))->where('system', 0)->get();
     }
     foreach ($templates as $template) {
         $records[] = [$template->id => $template->name];
     }
     return $records;
 }
예제 #3
0
 /**
  * Handle the event.
  *
  * @param  PaperWasCreated $event
  * @return void
  */
 public function handle(PaperWasCreated $event)
 {
     $template = new Template();
     $settings = $event->paper->department->settings()->key('email_add_paper');
     if (isset($settings->value) && $settings->value) {
         $emailTemplate = EmailTemplate::findOrFail($settings->value);
         $emailTemplate->body = $template->parser($emailTemplate->body, ['name' => $event->paper->user->name, 'time' => $event->paper->created_at, 'link' => buildPaperLink($event->paper)]);
         $this->mailer->send('layouts.partials.email', ['body' => $emailTemplate->body], function ($message) use($emailTemplate, $event) {
             $message->subject($emailTemplate->subject);
             $message->to($event->paper->user->email);
         });
     }
 }
 /**
  * Handle the event.
  *
  * @param  PaperWasCreated  $event
  * @return void
  */
 public function handle($event)
 {
     $template = new Template();
     $department = $event->paper->department;
     $settings = $department->settings()->key('email_notification');
     if (isset($settings->value) && $settings->value) {
         $users = User::where('department_id', $department->id)->whereHas('type.access', function ($query) {
             $query->where('access_id', 12);
         })->get();
         if (count($users)) {
             $emailTemplate = EmailTemplate::findOrFail($settings->value);
             $emails = $users->pluck('email')->toArray();
             $body = $template->parser($emailTemplate->body, ['author_name' => $event->paper->user->name, 'time' => $event->paper->updated_at, 'operation' => $event->operation, 'link' => action('Admin\\PaperController@show', [$event->paper->id])]);
             $this->mailer->send('layouts.partials.email', ['body' => $body], function ($message) use($emailTemplate, $emails) {
                 $message->subject($emailTemplate->subject);
                 $message->to($emails);
             });
         }
     }
 }
예제 #5
0
 public function postEmail(Request $request, TokenRepositoryInterface $token)
 {
     $department = $this->getDepartment();
     $this->validate($request, ['email' => 'required|email|exists:users,email,department_id,' . $department->id]);
     $template = new Template();
     $user = User::where('email', $request->get('email'))->where('department_id', $department->id)->first();
     if (!$user) {
         return redirect()->back()->with('error', 'error');
     }
     $settings = $user->department->settings()->key('email_password_reset');
     if (!isset($settings->value) || !$settings->value) {
         return redirect()->back()->with('error', 'no-template');
     }
     $emailTemplate = EmailTemplate::findOrFail($settings->value);
     $emailTemplate->body = $template->parser($emailTemplate->body, ['name' => $user->name, 'expire' => Carbon::now()->addMinutes(config('auth.password.expire'))->format('d.m.Y H:i'), 'link' => route('department::auth::reset_token', $user->department->keyword) . '/' . $token->create($user)]);
     Mail::send('layouts.partials.email', ['body' => $emailTemplate->body], function ($message) use($emailTemplate, $user) {
         $message->subject($emailTemplate->subject);
         $message->to($user->email);
     });
     return redirect()->back()->with('success', 'email-send');
 }
 public function postEmail(Request $request, Mailer $mailer)
 {
     $this->validate($request, ['template_id' => 'required|exists:email_template,id']);
     $departmentId = auth()->user()->department_id;
     if ($request->get('department_id')) {
         $departmentId = $request->get('department_id');
     }
     $users = [];
     if ($request->get('user_type')) {
         $users = array_merge(User::where('department_id', $departmentId)->where('user_type_id', $request->get('user_type'))->get()->toArray());
     }
     if ($request->get('users')) {
         $users = array_merge($users, User::whereIn('id', $request->get('users'))->get()->toArray());
     }
     $emailTemplate = EmailTemplate::find($request->get('template_id'));
     if (strpos($emailTemplate->body, '[name]')) {
         $template = new Template();
         foreach ($users as $user) {
             $body = $template->parser($emailTemplate->body, ['name' => $user['name']]);
             $mailer->send('layouts.partials.email', ['body' => $body], function ($message) use($emailTemplate, $user) {
                 $message->subject($emailTemplate->subject);
                 $message->to($user['email']);
             });
         }
     } else {
         $emails = array_column($users, 'email');
         $emails = array_unique($emails);
         $mailer->send('layouts.partials.email', ['body' => $emailTemplate->body], function ($message) use($emailTemplate, $emails) {
             $message->subject($emailTemplate->subject);
             $message->to($emails);
         });
     }
     return redirect()->action('Admin\\EmailTemplateController@getEmail')->with('success', 'emails-send');
 }
예제 #7
0
 public function store_email_template(Request $request)
 {
     $file = $request->file('email_template');
     $content = File::get($file);
     $tem = new EmailTemplate();
     $tem->name = $file->getClientOriginalName();
     $tem->owner_id = $this->user->id;
     $tem->content = $content;
     $tem->save();
     $cam = EmailCampaign::find($request->id);
     $cam->template_id = $tem->id;
     $cam->save();
     return redirect('manage/campaign?id=' . $request->id);
 }