public function activate($id) { $maillist = Maillist::find($id); $maillist->active = 1; $maillist->save(); return Redirect::back()->withSuccess('List activated. Please note that this does NOT activate the subscribers in the list.'); }
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); } } } }