本文整理汇总了PHP中Subscriber::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Subscriber::insert方法的具体用法?PHP Subscriber::insert怎么用?PHP Subscriber::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subscriber
的用法示例。
在下文中一共展示了Subscriber::insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import_csv
public function import_csv($num)
{
$input = Input::file('csvfile');
$ext = pathinfo($input->getClientOriginalName(), PATHINFO_EXTENSION);
$rules = array('csvfile' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
$error = array('files' => array(array('error' => $validator->messages()->first(), 'name' => 'none', 'size' => 'none', 'url' => 'none', 'thumbnail_url' => 'none', 'delete_url' => 'none', 'delete_type' => 'DELETE')));
return Response::json($error);
} elseif ($ext != 'csv') {
$error = array('files' => array(array('error' => 'Only CSV files are allowed', 'name' => 'none', 'size' => 'none', 'url' => 'none', 'thumbnail_url' => 'none', 'delete_url' => 'none', 'delete_type' => 'DELETE')));
return Response::json($error);
} else {
$destination = 'imports';
$filename = date('Y_m_d_H_i') . '_subscribers.' . $ext;
$filepath = asset('imports/' . $filename);
if ($input->move($destination, $filename)) {
$csvpath = public_path() . '/imports/' . $filename;
$processed = CsvManipulation::csvToArray($csvpath);
$thecsv = $processed['uniqueSubscribers'];
$rules = array('first_name' => 'required|alpha_num|max:128', 'last_name' => 'required|alpha_num|max:128', 'email' => 'required|email|max:255|unique:subscribers');
$length = count($thecsv);
$failedValidation = 0;
for ($i = 0; $i < $length; $i++) {
$validator = Validator::make($thecsv[$i], $rules);
if ($validator->fails()) {
unset($thecsv[$i]);
$failedValidation++;
}
}
$newcsvarray = array_values($thecsv);
$newlength = count($newcsvarray);
$timestamp = date("Y-m-d H:i:s");
$defaults = ['active' => 1, 'created_at' => $timestamp, 'updated_at' => $timestamp];
$arrayforinsert = [];
foreach ($newcsvarray as $key => $value) {
$arrayforinsert[] = array_merge($value, $defaults);
}
if (count($arrayforinsert) > 0) {
Subscriber::insert($arrayforinsert);
$list = Addressbook::find(1);
$subscribers = Subscriber::get();
foreach ($subscribers as $key => $subscriber) {
$list->subscribers()->attach($subscriber->id);
}
$successful = Subscriber::where('created_at', '=', $timestamp)->count();
$successMsg = "Total no. of subscribers successfully imported: <b>" . $successful . "</b><br />" . "Total no. of rows in the CSV file: <b>" . $processed['allRows'] . "</b><br />" . "Total no. of rows with the required 3 fields: <b>" . $processed['rowsWithThreeFields'] . "</b><br />" . "Total no. of unique emails in the CSV file: <b>" . $processed['noOfUniqueEmails'] . "</b><br />" . "Total no. of failed validations: <b>" . $failedValidation . "</b>";
$success = array('files' => array(array('success' => $successMsg, 'name' => $filename, 'size' => 'none', 'url' => $filepath, 'thumbnail_url' => 'none', 'delete_url' => 'none', 'delete_type' => 'DELETE')));
return Response::json($success);
} else {
$error = array('files' => array(array('error' => 'None of the subscribers has been imported. Kindly try again.', 'name' => 'none', 'size' => 'none', 'url' => 'none', 'thumbnail_url' => 'none', 'delete_url' => 'none', 'delete_type' => 'DELETE')));
return Response::json($error);
}
} else {
return Response::json(array('error' => "An error was encountered. Kindly refresh and try again."));
}
}
}
示例2: _seedSubscribers
private function _seedSubscribers()
{
$accounts = [['uname' => 'admin', 'pword' => Hash::make('123456'), 'plan_type' => 1, 'clear_pword' => '123456', 'fname' => 'Admin', 'status' => 1, 'is_admin' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')], ['uname' => 'demo', 'clear_pword' => '123456', 'pword' => Hash::make('123456'), 'plan_type' => 1, 'fname' => 'Demo', 'status' => 1, 'is_admin' => 0, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]];
Subscriber::truncate();
Subscriber::insert($accounts);
}
示例3: update
public function update($id)
{
$maillist = Maillist::getMaillistWithSubs($id);
$name = Jamesy\Sanitiser::trimInput(Input::get('name'));
if ($name == $maillist->name) {
$validation = NULL;
} else {
$validation = Jamesy\MyValidations::validate(['name' => $name], $this->rules);
}
if ($validation != NULL) {
return Redirect::back()->withErrors($validation)->withInput();
} else {
$maillist->name = $name;
$maillist->active = Input::get('active');
$maillist->save();
if ($maillist->active == 0) {
$subscribers = $maillist->subscribers;
foreach ($subscribers as $subscriber) {
$subscriber->active = 0;
$subscriber->save();
}
}
if (Input::file('file')) {
$fileValidation = Jamesy\MyValidations::validate(['file' => Input::file('file')], $this->fileSizeRules);
if ($fileValidation != NULL) {
return Redirect::back()->withErrors($fileValidation)->withInput();
} else {
$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 $key => $subscriber) {
$generalList->subscribers()->attach($subscriber->id);
$maillist->subscribers()->attach($subscriber->id);
}
}
if (count($existingEmails)) {
$alreadySubs = Subscriber::with('maillists')->whereIn('email', $existingEmails)->get();
if (count($alreadySubs)) {
foreach ($alreadySubs as $subscriber) {
if (!$subscriber->maillists->contains($maillist->id)) {
$maillist->subscribers()->attach($subscriber->id);
}
if ($maillist->active == 0) {
$subscriber->active = 0;
$subscriber->save();
}
}
}
}
$message = "List updated.";
$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 {
return Redirect::to('dashboard/lists')->withSuccess($maillist->active == 0 ? 'List updated. NOTE: All subscribers in the list are now inactive.' : 'List updated.');
}
//.........这里部分代码省略.........
示例4: import
public function import()
{
$validation = Jamesy\MyValidations::validate(Input::all(), $this->fileRules);
if ($validation != NULL) {
return Redirect::back()->withErrors($validation);
} else {
$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');
} else {
$import = new Jamesy\Imports($input, $this->rules);
$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];
if (count($passedArr)) {
Subscriber::insert($passedArr);
$list = Maillist::find(1);
$list->touch();
$subscribers = Subscriber::where('created_at', $timestamp)->where('updated_at', $timestamp)->get();
foreach ($subscribers as $key => $subscriber) {
$list->subscribers()->attach($subscriber->id);
}
}
$message = "<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::back()->withSuccess($message);
} else {
return Redirect::back()->withIssues($importResult);
}
}
}
}