Ejemplo n.º 1
0
 public function addRecipient($data)
 {
     //If this user is already a mailing recipient in the system
     if (MailingRecipient::where('email_address', $data['email_address'])->count() > 0) {
         $recipient = MailingRecipient::where('email_address', $data['email_address'])->first();
         //If the recipient is already in the list, do nothing
         if ($this->recipients()->where('id', $recipient->id)->count() > 0) {
             return 0;
         } else {
             DB::table('mailing_list_recipients')->insert(['mailing_list_id' => $this->id, 'recipient_id' => $recipient->id]);
             return 1;
         }
     } else {
         $recipient = MailingRecipient::addNew(['first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'email_address' => $data['email_address'], 'mobile_number' => $data['mobile_number']]);
         DB::table('mailing_list_recipients')->insert(['mailing_list_id' => $this->id, 'recipient_id' => $recipient->id]);
         $recipient->attemptLinkToPatient();
         return 1;
     }
 }
Ejemplo n.º 2
0
 public function doRecipientAdd(Request $request)
 {
     if (MailingRecipient::where('email_address', $request->input('email_address'))->count() == 0) {
         $recipient = MailingRecipient::addNew(['first_name' => $request->input('first_name'), 'last_name' => $request->input('last_name'), 'email_address' => $request->input('email_address'), 'mobile_number' => $request->input('mobile_number')]);
         $recipient->attemptLinkToPatient();
         if (count($request->input('mailing_lists')) > 0) {
             foreach ($request->input('mailing_lists') as $list_id) {
                 $list = MailingList::findOrFail($list_id);
                 $recipient->addToList($list);
             }
         }
         return redirect()->to('marketing/recipients')->with('recipient-added', true);
     } else {
         return redirect()->to('marketing/recipients')->with(['recipient-already-exists' => true, 'recipient_id' => MailingRecipient::where('email_address', $request->input('email_address'))->first()->id]);
     }
 }