/**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $latest_registrations = Registration::take(10)->orderBy('created_at', 'desc')->get();
     $registrations = Registration::get();
     return view('admin.index', array('title' => 'Admin: Dashboard', 'registrations_count' => $registrations && $registrations->count() > 0 ? $registrations->count() : 0, 'latest_registrations' => $latest_registrations));
 }
 public function index()
 {
     $registrations = Registration::get();
     return view('admin.registrations.index', array('title' => 'Admin: Registrations', 'registrations' => $registrations));
 }
 public function store()
 {
     $registrations = Registration::get();
     $mailchimp_creation_count = 0;
     $mailchimp_update_count = 0;
     $subscriber_creation_count = 0;
     foreach ($registrations as $registration) {
         // Athlete - first create the newsletter subscriber record
         if (!filter_var($registration->email, FILTER_VALIDATE_EMAIL) === false) {
             $athlete_subscriber = NewsletterSubscriber::where('email', '=', str_replace(" ", '', $registration->email))->first();
             if (!$athlete_subscriber) {
                 $athlete_subscriber = NewsletterSubscriber::create(array('registration_id' => $registration->id, 'first_name' => $registration->first_name, 'last_name' => $registration->last_name, 'email' => str_replace(" ", '', $registration->email)));
                 $subscriber_creation_count++;
             }
             // Athlete - then officially add them to MailChimp
             if (WebsiteHelper::mailchimp_subscriber_exists($athlete_subscriber->email)) {
                 Newsletter::updateMember($athlete_subscriber->email, array('FNAME' => $athlete_subscriber->first_name, 'LNAME' => $athlete_subscriber->last_name));
                 $mailchimp_update_count++;
             } else {
                 Newsletter::subscribe($athlete_subscriber->email, array('FNAME' => $athlete_subscriber->first_name, 'LNAME' => $athlete_subscriber->last_name));
                 $mailchimp_creation_count++;
             }
         }
         if (!filter_var($registration->guardian_1_email, FILTER_VALIDATE_EMAIL) === false) {
             // Guardian 1 - first create the newsletter subscriber record
             $guardian_1_subscriber = NewsletterSubscriber::where('email', '=', str_replace(" ", '', $registration->guardian_1_email))->first();
             if (!$guardian_1_subscriber) {
                 $guardian_1_subscriber = NewsletterSubscriber::create(array('registration_id' => $registration->id, 'first_name' => $registration->guardian_1_first_name, 'last_name' => $registration->guardian_1_last_name, 'email' => str_replace(" ", '', $registration->guardian_1_email)));
                 $subscriber_creation_count++;
             }
             // Guardian 1 - then officially add them to MailChimp
             if (WebsiteHelper::mailchimp_subscriber_exists($guardian_1_subscriber->email)) {
                 Newsletter::updateMember($guardian_1_subscriber->email, array('FNAME' => $guardian_1_subscriber->first_name, 'LNAME' => $guardian_1_subscriber->last_name));
                 $mailchimp_update_count++;
             } else {
                 Newsletter::subscribe($guardian_1_subscriber->email, array('FNAME' => $guardian_1_subscriber->first_name, 'LNAME' => $guardian_1_subscriber->last_name));
                 $mailchimp_creation_count++;
             }
         }
         // Only add the guardian 2 if they have an email present
         if (!filter_var($registration->guardian_2_email, FILTER_VALIDATE_EMAIL) === false) {
             $guardian_2_subscriber = NewsletterSubscriber::where('email', '=', str_replace(" ", '', $registration->guardian_2_email))->first();
             if (!$guardian_2_subscriber) {
                 // Guardian 2 - first create the newsletter subscriber record
                 $guardian_2_subscriber = NewsletterSubscriber::create(array('registration_id' => $registration->id, 'first_name' => $registration->guardian_2_first_name, 'last_name' => $registration->guardian_2_last_name, 'email' => str_replace(" ", '', $registration->guardian_2_email)));
                 $subscriber_creation_count++;
             }
             // Guardian 2 - then officially add them to MailChimp
             if (WebsiteHelper::mailchimp_subscriber_exists($guardian_2_subscriber->email)) {
                 Newsletter::updateMember($guardian_2_subscriber->email, array('FNAME' => $guardian_2_subscriber->first_name, 'LNAME' => $guardian_2_subscriber->last_name));
                 $mailchimp_update_count++;
             } else {
                 Newsletter::subscribe($guardian_2_subscriber->email, array('FNAME' => $guardian_2_subscriber->first_name, 'LNAME' => $guardian_2_subscriber->last_name));
                 $mailchimp_creation_count++;
             }
         }
     }
     if ($subscriber_creation_count > 0 || $mailchimp_creation_count > 0 || $mailchimp_update_count > 0) {
         \Flash::success("New Subscribers: " . $subscriber_creation_count . " New MailChimp Subscribers: " . $mailchimp_creation_count . " Updated MailChimp Subscribers: " . $mailchimp_update_count);
     } else {
         \Flash::error("Looks like there weren't any subscribers added!");
     }
     return redirect()->back();
 }