/**
  * Handle the event.
  *
  * @param  ScheduleResponse  $event
  * @return void
  */
 public function handle(ScheduleResponse $event)
 {
     //
     // if(!$response_templates = ResponseTemplate::where('trigger_event',1)->orderBy('created_at','desc')->get())
     // {
     //     return false;
     // }
     $response_templates = ResponseTemplate::where('trigger_event', 1)->orderBy('created_at', 'desc')->get();
     $contact = Contact::find($event->inquiry->user_id);
     foreach ($response_templates as $t) {
         $this->schedule->create($t, $contact);
     }
     \Mail::raw('Scheduled Responses were created for ' . $contact->fullname, function ($m) {
         $m->to('*****@*****.**', 'Tim Bradshaw')->from('*****@*****.**', 'LTD Sailing')->subject('The Prospect Inquiry Event Handler Fired to Create Scheduled Responses');
     });
 }
Ejemplo n.º 2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show(Contact $contact)
 {
     //
     $user = User::find($contact->id);
     if (!$user->types()->where('user_types.id', 1)->first()) {
         $user->types()->attach([1]);
     }
     $contact = Contact::find($user->id);
     // return $contact;
     $schedules = $this->schedules->contact($contact);
     //Gets any Scheduled Responses for the contact grouped by Template
     // $template_ids = '0,';
     $template_ids = [];
     $template_group_status = [];
     // dd($template_group_status);
     // $template_ids = rtrim($template_ids,',');
     if ($schedules) {
         foreach ($schedules as $s) {
             //If any response schedule is set to 'Paused' set a status for that templateid to paused.
             if ($s->status == 'paused') {
                 !isset($template_group_status[$s->template->id]) ? $template_group_status[$s->template->id] = ['template_id' => $s->template->id, 'status' => 'paused'] : null;
             }
             $template_ids[] = $s->template->id;
         }
         $response_templates = \App\ResponseTemplate::whereIn('id', $template_ids)->get();
     }
     // $schedules = new \App\ResponseSchedule;
     // $response_templates = new \App\ResponseTemplate;
     return view('contacts.show', ['title' => $contact->fullname, 'contact' => $contact, 'schedules' => $schedules, 'response_templates' => $response_templates, 'template_group_status' => $template_group_status]);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     //
     // return $request->all()
     $template = ResponseTemplate::find($id);
     $template->update($request->only('name', 'trigger_event', 'user_type_id'));
     $inputTemplate = $request->input('template');
     $inputSubject = $request->input('subject');
     $inputDetail = $request->input('detail_id');
     foreach ($request->input('days') as $key => $detail) {
         //Check if it exists and update
         $templatedetail = ResponseTemplateDetail::find($inputDetail[$key]);
         $templatedetail->number_of_days = $detail;
         $templatedetail->template = $inputTemplate[$key];
         $templatedetail->subject = $inputSubject[$key];
         $template->details()->save($templatedetail);
     }
     return redirect()->route('admin.response_templates.index');
 }