当前位置: 首页>>代码示例>>PHP>>正文


PHP Subscriber::whereIn方法代码示例

本文整理汇总了PHP中Subscriber::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Subscriber::whereIn方法的具体用法?PHP Subscriber::whereIn怎么用?PHP Subscriber::whereIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subscriber的用法示例。


在下文中一共展示了Subscriber::whereIn方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: send_email

 public function send_email($dummy)
 {
     $rules = array('from_name' => 'required|max:128', 'from_email' => 'required|email|max:255', 'subject' => 'required|max:128', 'emailbody' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Response::json(array('validation' => $validator->messages()->toArray()));
     } else {
         $from_name = Input::get('from_name');
         $from_email = Input::get('from_email');
         $selected = Input::get('to');
         $subject = Input::get('subject');
         $emailbody = Input::get('emailbody');
         $from = $from_name . ' (' . $from_email . ')';
         $recipients = Subscriber::whereIn('email', $selected)->where('active', '=', 1)->get();
         $email = new Email();
         $email->from = $from;
         $email->subject = $subject;
         $email->message = $emailbody;
         $email->save();
         $email_id = $email->id;
         $numrecipients = $recipients->count();
         $numsent = 0;
         foreach ($recipients as $key => $recipient) {
             $tracker = new Tracker();
             $tracker->subscriber_id = $recipient->id;
             $tracker->email_id = $email_id;
             $tracker->save();
             $tracker_id = $tracker->id;
             $tracker_url = URL::to('tracker/' . $tracker_id);
             $unsubscriber_url = URL::to('unsubscribe/' . $tracker_id);
             $subscriber = $recipient;
             $data = array('emailbody' => $emailbody, 'tracker' => $tracker_url, 'unsubscribe' => $unsubscriber_url, 'subscriber' => $subscriber);
             $to_email = $subscriber->email;
             $to_name = $subscriber->first_name . ' ' . $subscriber->last_name;
             $issent = Mail::send('emails.sub-emails', $data, function ($message) use($from_email, $from_name, $to_email, $to_name, $subject) {
                 $message->from($from_email, $from_name)->to($to_email, $to_name)->subject($subject);
             });
             if ($issent) {
                 $numsent += 1;
             } else {
                 $tracker->bounced = 1;
                 $tracker->save();
             }
         }
         if ($numsent == $numrecipients) {
             return Response::json(array('success' => 'Your email was successfully sent to <b>' . $numsent . '</b> subscribers out of the ' . $numrecipients . ' subscribers you selected. <b>Rejoice!</b>'));
         } else {
             return Response::json(array('success' => 'Your email was successfully sent to <b>' . $numsent . '</b> subscribers out of the ' . $numrecipients . 'All bounces have been logged.'));
         }
     }
 }
开发者ID:shinichi81,项目名称:Laravel4-Newsletter-Application,代码行数:51,代码来源:EmailController.php

示例2: store

 public function store()
 {
     $name = Jamesy\Sanitiser::trimInput(Input::get('name'));
     $validation = Jamesy\MyValidations::validate(['name' => $name], $this->rules);
     if ($validation != NULL) {
         return Redirect::back()->withErrors($validation)->withInput();
     } else {
         if (Input::file('file')) {
             $fileValidation = Jamesy\MyValidations::validate(['file' => Input::file('file')], $this->fileSizeRules);
             if ($fileValidation != NULL) {
                 return Redirect::back()->withErrors($fileValidation)->withInput();
             } else {
                 $maillist = new Maillist();
                 $maillist->name = $name;
                 if (Input::get('active') == '0' || Input::get('active') == '1') {
                     $maillist->active = Input::get('active');
                 }
                 $maillist->save();
                 $input = Input::file('file');
                 $ext = pathinfo($input->getClientOriginalName(), PATHINFO_EXTENSION);
                 if ($ext != 'xlt' && $ext != 'xls' && $ext != 'csv') {
                     return Redirect::back()->withIssues('You attempted the import with an invalid file. File must be Excel or CSV')->withInput();
                 } else {
                     $import = new Jamesy\Imports($input, $this->subscriberRules);
                     $importResult = $import->getInsertArray();
                     if (is_array($importResult)) {
                         $totalNum = $importResult[0];
                         $duplicatesNum = $importResult[1];
                         $passedArr = $importResult[2];
                         $passedNum = count($passedArr);
                         $failedNum = (int) $totalNum - (int) $duplicatesNum - (int) $passedNum;
                         $timestamp = $importResult[3];
                         $existingEmails = $importResult[4];
                         $newPassedArr = [];
                         if ($maillist->active == 0) {
                             foreach ($passedArr as $subscriber) {
                                 $subscriber['active'] = 0;
                                 $newPassedArr[] = $subscriber;
                             }
                         } else {
                             $newPassedArr = $passedArr;
                         }
                         if (count($newPassedArr)) {
                             Subscriber::insert($newPassedArr);
                             $generalList = Maillist::find(1);
                             $generalList->touch();
                             $maillist->touch();
                             $subscribers = Subscriber::where('created_at', $timestamp)->where('updated_at', $timestamp)->get();
                             foreach ($subscribers as $subscriber) {
                                 $generalList->subscribers()->attach($subscriber->id);
                                 $maillist->subscribers()->attach($subscriber->id);
                             }
                         }
                         if (count($existingEmails)) {
                             $alreadySubs = Subscriber::whereIn('email', $existingEmails)->get();
                             if (count($alreadySubs)) {
                                 foreach ($alreadySubs as $subscriber) {
                                     $maillist->subscribers()->attach($subscriber->id);
                                     if ($maillist->active == 0) {
                                         $subscriber->active = 0;
                                         $subscriber->save();
                                     }
                                 }
                             }
                         }
                         $message = "New list created.";
                         $message .= "<br /><b>{$totalNum}</b> " . str_plural('row', $totalNum) . " found in excel file.";
                         if ($duplicatesNum) {
                             $message .= "<br /><b>{$duplicatesNum}</b> had duplicate email addresses.";
                         }
                         if ($passedNum == 1) {
                             $message .= "<br /><b>1</b> out of the <b>" . ($totalNum - $duplicatesNum) . "</b> with unique emails passed validation and was stored.";
                         } else {
                             $message .= "<br /><b>{$passedNum}</b> out of the <b>" . ($totalNum - $duplicatesNum) . "</b> with unique emails passed validation and were stored.";
                         }
                         if ($failedNum == 1) {
                             $message .= "<br /><b>1</b> out of the <b>" . ($totalNum - $duplicatesNum) . "</b> with unique emails failed validation (no first name, last name or bad email) and was NOT stored.";
                         } elseif ($failedNum > 1) {
                             $message .= "<br /><b>{$failedNum}</b> out of the <b>" . ($totalNum - $duplicatesNum) . "</b> with unique emails failed validation (no first name, last name or bad email) and were NOT stored.";
                         }
                         return Redirect::to('dashboard/lists')->withSuccess($message);
                     } else {
                         return Redirect::back()->withIssues($importResult);
                     }
                 }
             }
         } else {
             $maillist = new Maillist();
             $maillist->name = $name;
             if (Input::get('active') == '0' || Input::get('active') == '1') {
                 $maillist->active = Input::get('active');
             }
             $maillist->save();
             return Redirect::to('dashboard/lists')->withSuccess('New list created');
         }
     }
 }
开发者ID:shinichi81,项目名称:Nifty-Newsletter,代码行数:97,代码来源:MaillistController.php

示例3: get_subscribers

 public function get_subscribers($dummy)
 {
     $selected_subs = Subscriber::whereIn('id', Input::get('subsarray'))->get();
     return Response::json($selected_subs);
 }
开发者ID:shinichi81,项目名称:Laravel4-Newsletter-Application,代码行数:5,代码来源:SubscriberController.php

示例4: bulk_destroy

 public function bulk_destroy()
 {
     Subscriber::whereIn('id', Input::get('subscribers'))->delete();
     $destroyedNum = count(Input::get('subscribers'));
     return Redirect::to('dashboard/subscribers/trash')->withSuccess($destroyedNum . ' ' . str_plural('subscriber', $destroyedNum) . ' permanently deleted.');
 }
开发者ID:shinichi81,项目名称:Nifty-Newsletter,代码行数:6,代码来源:SubscriberController.php


注:本文中的Subscriber::whereIn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。