public function postAdd(Request $request) { $volunteers = \teambernieny\Volunteer::where('Email', '=', $request->Email)->get(); if (sizeof($volunteers) > 0) { return $this->returnEdit($volunteers[0], ""); } else { $volunteer = new \teambernieny\Volunteer(); $neighborhoods = \teambernieny\Neighborhood::select('id')->where('Name', '=', $request->Neighborhood)->get(); if (sizeof($neighborhoods) > 0) { $neighborhood = $neighborhoods->first(); } else { $neighborhood = new \teambernieny\Neighborhood(); $neighborhood->Name = $request->Neighborhood; $neighborhood->Borough = $request->City; $neighborhood->save(); } $neighborhood_id = $neighborhood->id; $volunteer->FirstName = $request->FirstName; $volunteer->LastName = $request->LastName; $volunteer->Email = $request->Email; $volunteer->Phone = $request->Phone; $volunteer->Zip = $request->Zip; $volunteer->neighborhood_id = $neighborhood_id; $volunteer->Street = $request->Street; $volunteer->neighborhood->Borough = $request->City; $volunteer->City = $request->City; $volunteer->save(); return view('volunteer.check')->with('message', 'Volunteer Added'); } }
public function postCityProcess(Request $request) { ini_set('auto_detect_line_endings', TRUE); $file = fopen(Config::get('app.filepath') . $request->FileName, "r"); ## Get the header line = FirstName(0),LastName(1),Phone(2),Neighborhood(3),Borough(4),Caller(5),Called(6), ## VM(7),Texted(8),RSVP(9),Event(10),Date(11),DoNotContact(12),BadPhone(13),Comments(14) $x = 0; while (($data = fgetcsv($file)) !== FALSE) { if ($x == 0) { $x = $x + 1; continue; } #; Find Volunteer or add if does not exist if ($data[2] != "") { // check first by phone number $volunteers = \teambernieny\Volunteer::where('Phone', '=', $data[2])->get(); } if (sizeof($volunteers) == 0) { $volunteer = new \teambernieny\Volunteer(); $volunteer->FirstName = $data[0]; $volunteer->LastName = $data[1]; $volunteer->Phone = $data[2]; $volunteer->County = $data[4]; $volunteer->neighborhood_id = $this->checkNeighborhood($data[3], $data[4]); if ($request->CDistrict != "") { $volunteer->CDistrict = $request->CDistrict; } $volunteer->user_id = "1"; $volunteer->save(); $volunteer_id = $volunteer->id; } else { $volunteer_id = $volunteers[0]->id; $volunteer = $volunteers[0]; } if ($data[12] == "1") { $volunteer->DoNotContact = true; } if ($data[13] == "1") { $volunteer->BadPhone = true; } #; Check to see if volunteer was Called or texted -- add contact event if so $data[6] = strtoupper($data[6]); $data[7] = strtoupper($data[7]); $data[8] = strtoupper($data[8]); $data[9] = strtoupper($data[9]); if ($data[6] == "Y" || $data[8] == "Y" || $data[6] == "YES" || $data[8] == "YES") { if ($data[10] != "") { //get event info if there is a name in the event column $events = \teambernieny\Event::where('Name', '=', $data[10])->get(); if (sizeof($events) > 0) { $event_id = $events[0]->id; } else { //add if event doesn't exist $event = new \teambernieny\Event(); $event->Name = $data[12]; $event->neighborhood_id = "1"; $event->Date = date('Y/m/d'); $event->save(); $event_id = $event->id; } } else { $event_id = null; //no event indicated } #; create contact event $contactevent = new \teambernieny\Contactevent(); $contactevent->volunteer_id = $volunteer_id; $contactevent->event_id = $event_id; $contactevent->Purpose = "Invitation"; // if RSVPed if ($data[9] == "Y" || $data[9] == "SENT" || $data[9] == "YES") { $contactevent->RSVP = true; } else { $contactevent->RSVP = false; } // if Called if ($data[6] == "Y" || $data[6] == "YES") { $contactevent->Call = true; } else { $contactevent->Call = false; } // if Texted if ($data[8] == "Y" || $data[8] == "YES") { $contactevent->Text = true; } else { $contactevent->Text = false; } //if left a voicemail if ($data[7] == "Y" || $data[7] == "YES") { $contactevent->VoiceMail = true; } else { $contactevent->VoiceMail = false; } $contactevent->Date = date('Y-m-d', strtotime($data[11])); $contactevent->Comment = $data[14]; $contactevent->Caller = $data[5]; $contactevent->Completed = true; $contactevent->user_id = null; $contactevent->save(); } } fclose($file); return view('contactevent.process')->with(['message' => "File Processed"]); }