Exemple #1
0
 public static function addNew($data)
 {
     $mailing_list = new MailingList();
     $mailing_list->name = $data['name'];
     $mailing_list->save();
     return $mailing_list;
 }
 public function doRecipientSearch(Request $request)
 {
     $recipient_string = explode(' ', $request->input('search_string'));
     $list = null;
     if ($request->has('list')) {
         $recipient_ids = DB::table('mailing_recipients')->select('mailing_recipients.id', 'mailing_list_recipients.mailing_list_id')->join('mailing_list_recipients', 'mailing_recipients.id', '=', 'mailing_list_recipients.recipient_id')->where('mailing_list_recipients.mailing_list_id', $request->input('list'))->where(function ($outer_query) use($recipient_string) {
             $outer_query->where(function ($query) use($recipient_string) {
                 $where = [];
                 foreach ($recipient_string as $string) {
                     $where[] = "`first_name` LIKE '%" . $string . "%'";
                 }
                 $query->whereRaw(implode(' OR ', $where));
             })->orWhere(function ($query) use($recipient_string) {
                 $where = [];
                 foreach ($recipient_string as $string) {
                     $where[] = "`last_name` LIKE '%" . $string . "%'";
                 }
                 $query->whereRaw(implode(' OR ', $where));
             })->orWhere(function ($query) use($recipient_string) {
                 $where = [];
                 foreach ($recipient_string as $string) {
                     $where[] = "`email_address` LIKE '%" . $string . "%'";
                 }
                 $query->whereRaw(implode(' OR ', $where));
             })->orWhere(function ($query) use($recipient_string) {
                 $where = [];
                 foreach ($recipient_string as $string) {
                     $where[] = "`mobile_number` LIKE '%" . $string . "%'";
                 }
                 $query->whereRaw(implode(' OR ', $where));
             });
         })->take(50)->get();
         $ids = [];
         foreach ($recipient_ids as $id) {
             $ids[] = $id->id;
         }
         $recipients = MailingRecipient::whereIn('id', $ids)->get();
         $list = MailingList::findOrFail($request->has('list'));
     } else {
         $recipients = MailingRecipient::where(function ($query) use($recipient_string) {
             $where = [];
             foreach ($recipient_string as $string) {
                 $where[] = "`first_name` LIKE '%" . $string . "%'";
             }
             $query->whereRaw(implode(' OR ', $where));
         })->orWhere(function ($query) use($recipient_string) {
             $where = [];
             foreach ($recipient_string as $string) {
                 $where[] = "`last_name` LIKE '%" . $string . "%'";
             }
             $query->whereRaw(implode(' OR ', $where));
         })->orWhere(function ($query) use($recipient_string) {
             $where = [];
             foreach ($recipient_string as $string) {
                 $where[] = "`email_address` LIKE '%" . $string . "%'";
             }
             $query->whereRaw(implode(' OR ', $where));
         })->orWhere(function ($query) use($recipient_string) {
             $where = [];
             foreach ($recipient_string as $string) {
                 $where[] = "`mobile_number` LIKE '%" . $string . "%'";
             }
             $query->whereRaw(implode(' OR ', $where));
         })->take(50)->get();
     }
     $response = ['html' => view('backend.partials.marketing.recipient-list')->with(['recipients' => $recipients, 'list' => $list])->render()];
     header('Content-Type: application/json');
     die(json_encode($response));
 }
 /**
  * Create a new job instance.
  *
  * @return void
  */
 public function __construct($filename, $user_id, $list_id)
 {
     $this->user = User::findOrFail($user_id);
     $this->filename = $filename;
     $this->mailing_list = MailingList::findOrFail($list_id);
 }