2015-06-30 11:30:59 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
|
|
|
* (c) Alt Three Services Limited
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-08-31 18:59:17 +01:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
|
2015-06-30 11:30:59 -05:00
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
use AltThree\Validator\ValidationException;
|
2015-08-06 21:16:49 -05:00
|
|
|
use CachetHQ\Cachet\Commands\Subscriber\SubscribeSubscriberCommand;
|
|
|
|
use CachetHQ\Cachet\Commands\Subscriber\UnsubscribeSubscriberCommand;
|
2015-06-30 11:30:59 -05:00
|
|
|
use CachetHQ\Cachet\Models\Subscriber;
|
|
|
|
use GrahamCampbell\Binput\Facades\Binput;
|
2015-08-06 21:16:49 -05:00
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
2015-08-05 17:18:51 -05:00
|
|
|
use Illuminate\Routing\Controller;
|
2015-06-30 11:30:59 -05:00
|
|
|
use Illuminate\Support\Facades\Redirect;
|
|
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
|
2015-08-05 17:18:51 -05:00
|
|
|
class SubscriberController extends Controller
|
2015-06-30 11:30:59 -05:00
|
|
|
{
|
2015-08-06 21:16:49 -05:00
|
|
|
use DispatchesJobs;
|
|
|
|
|
2015-06-30 11:30:59 -05:00
|
|
|
/**
|
|
|
|
* Shows the subscribers view.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showSubscribers()
|
|
|
|
{
|
|
|
|
$subscribers = Subscriber::all();
|
|
|
|
|
|
|
|
return View::make('dashboard.subscribers.index')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withPageTitle(trans('dashboard.subscribers.subscribers').' - '.trans('dashboard.dashboard'))
|
|
|
|
->withSubscribers(Subscriber::all());
|
2015-06-30 11:30:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the add subscriber view.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showAddSubscriber()
|
|
|
|
{
|
|
|
|
return View::make('dashboard.subscribers.add')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withPageTitle(trans('dashboard.subscribers.add.title').' - '.trans('dashboard.dashboard'));
|
2015-06-30 11:30:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new subscriber.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function createSubscriberAction()
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
2015-08-15 22:15:06 -05:00
|
|
|
$this->dispatch(new SubscribeSubscriberCommand(Binput::get('email')));
|
2015-08-03 22:32:36 +01:00
|
|
|
} catch (ValidationException $e) {
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.subscribers.add')
|
2015-06-30 11:30:59 -05:00
|
|
|
->withInput(Binput::all())
|
2015-08-03 22:32:36 +01:00
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.subscribers.add.failure')))
|
|
|
|
->withErrors($e->getMessageBag());
|
2015-06-30 11:30:59 -05:00
|
|
|
}
|
|
|
|
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.subscribers.add')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.subscribers.add.success')));
|
2015-06-30 11:30:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a subscriber.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
|
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function deleteSubscriberAction(Subscriber $subscriber)
|
|
|
|
{
|
2015-08-06 21:16:49 -05:00
|
|
|
$this->dispatch(new UnsubscribeSubscriberCommand($subscriber));
|
2015-06-30 11:30:59 -05:00
|
|
|
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.subscribers.index');
|
2015-06-30 11:30:59 -05:00
|
|
|
}
|
|
|
|
}
|