private function migrateTouches($currentCampaign, $destinationCampaign)
 {
     $touch = Touch::create(["title" => $currentCampaign->name, "campaign_id" => $destinationCampaign->id, "template" => $currentCampaign->template, "title_slug" => $currentCampaign->title_slug]);
     \DB::table('emails')->where('campaign_id', $currentCampaign->id)->update(['touch_id' => $touch->id, 'campaign_id' => $destinationCampaign->id]);
     DB::table('actions')->where('campaign_id', $currentCampaign->id)->update(['touch_id' => $touch->id, 'campaign_id' => $destinationCampaign->id]);
     $lastEmail = Email::where('touch_id', '=', $touch->id)->orderBy('send_on', 'DESC')->first();
     if ($lastEmail) {
         $touch->send_on = $lastEmail->send_on;
         $touch->save();
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('touches', function ($table) {
         $table->text('template_html');
         $table->text('template_text');
         $table->text('preview_text');
     });
     $touches = Touch::all();
     $touches->each(function ($touch) {
         $html = view("emails.{$touch->template}")->with(['salted_id' => null, 'campaign' => $touch->campaign, 'email' => false]);
         $text = view("text_emails.{$touch->template}")->with('campaign', $touch->campaign);
         $touch->template_html = $html;
         $touch->template_text = $text;
         $touch->save();
     });
 }
 public function touchActions($id)
 {
     $touch = Touch::find($id);
     $actions = Action::with('contact')->where('touch_id', '=', $touch->id)->orderBy('action')->orderBy('contact_id', 'DESC')->get(['action', 'contact_id']);
     $actions = array_map(function ($action) {
         foreach ($action['contact'] as $key => $value) {
             $action[$key] = $value;
         }
         unset($action['contact_id'], $action['id'], $action['contact'], $action['unsubscribe'], $action['client_id'], $action['updated_at'], $action['created_at'], $action['bounced']);
         return $action;
     }, $actions->toArray());
     $metrics = Excel::create("{$touch->title} Metrics", function ($excel) use($touch, $actions) {
         $excel->setTitle("Email Metrics for {$touch->title}");
         $excel->setCreator("EP-Productions");
         $excel->setCompany('Exhibit Partners');
         $excel->setDescription("Email metrics from an email campaign for {$touch->campaign}->client->name by Exhibit Partners");
         $excel->sheet('Metrics', function ($sheet) use($actions) {
             $sheet->fromArray($actions);
         });
         $excel->sheet('Bounces', function ($sheet) use($touch) {
             $bounces = $touch->bounces->toArray();
             $bounces = array_map(function ($contact) {
                 unset($contact['id'], $contact['client_id'], $contact['bounced'], $contact['unsubscribe'], $contact['updated_at'], $contact['created_at']);
                 return $contact;
             }, $bounces);
             $sheet->fromArray($bounces);
         });
         $excel->sheet('Unsubscribes', function ($sheet) use($touch) {
             $unsubscribes = $touch->unsubscribes->toArray();
             $unsubscribes = array_map(function ($contact) {
                 unset($contact['id'], $contact['client_id'], $contact['bounced'], $contact['unsubscribe'], $contact['updated_at'], $contact['created_at']);
                 return $contact;
             }, $unsubscribes);
             $sheet->fromArray($unsubscribes);
         });
     })->download('xlsx');
     return $metrics;
 }
Пример #4
0
 public function store($touch_id, Request $request)
 {
     $date = \Carbon\Carbon::now()->toDateTimeString();
     $emails = explode(',', $request->input('email'));
     $count = 0;
     foreach ($emails as $email) {
         $email = trim($email);
         if (!$this->checkEmail($email)) {
             continue;
         }
         $touch = Touch::find($touch_id);
         $contact = Contact::firstOrCreate(['email' => $email, 'client_id' => $touch->campaign->client->id]);
         if ($contact->unsubscribe || $contact->bounced) {
             return redirect()->back()->with('message', "{$contact->email} is unreachable or has unsubscribed");
         }
         $email = Email::create(['subject' => $touch->subject, 'reply_to' => $touch->campaign->client->reply_to, 'from' => $touch->campaign->client->reply_to, 'send_on' => $date, 'template' => "emails.{$touch->template}", 'draft' => false, 'trackable' => false, 'campaign_id' => $touch->campaign->id, 'contact_id' => $contact->id, 'touch_id' => $touch->id]);
         $email->salted_id = bcrypt($email->id);
         $email->save();
         $count++;
     }
     return redirect()->back()->with('message', "{$count} test emails sent");
 }
 public function getTemplate($id)
 {
     $touch = Touch::find($id);
     return $touch->template_html;
 }
 public function engage($name, Request $request)
 {
     $email = $request->input('email') ? Email::where('salted_id', '=', $request->input('email'))->first() : null;
     $touch = $email ? $email->touch : Touch::where('title_slug', '=', $name)->first();
     $campaign = $touch->campaign;
     if ($email && $email->trackable) {
         Action::firstOrCreate(['action' => 'clicked register', 'contact_id' => $email->contact->id, 'campaign_id' => $email->campaign->id, 'touch_id' => $email->touch_id]);
     }
     return view()->make('signups.engage')->with(['campaign' => $campaign, 'email' => $email]);
 }