1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Http\Controllers\Dashboard; |
13
|
|
|
|
14
|
|
|
use AltThree\Validator\ValidationException; |
15
|
|
|
use Gitamin\Commands\Subscriber\SubscribeSubscriberCommand; |
16
|
|
|
use Gitamin\Commands\Subscriber\UnsubscribeSubscriberCommand; |
17
|
|
|
use Gitamin\Models\Subscriber; |
18
|
|
|
use GrahamCampbell\Binput\Facades\Binput; |
19
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
20
|
|
|
use Illuminate\Routing\Controller; |
21
|
|
|
use Illuminate\Support\Facades\Redirect; |
22
|
|
|
use Illuminate\Support\Facades\View; |
23
|
|
|
|
24
|
|
|
class SubscriberController extends Controller |
25
|
|
|
{ |
26
|
|
|
use DispatchesJobs; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Shows the subscribers view. |
30
|
|
|
* |
31
|
|
|
* @return \Illuminate\View\View |
32
|
|
|
*/ |
33
|
|
|
public function indexAction() |
34
|
|
|
{ |
35
|
|
|
return View::make('dashboard.subscribers.index') |
36
|
|
|
->withPageTitle(trans('dashboard.subscribers.subscribers').' - '.trans('dashboard.dashboard')) |
37
|
|
|
->withSubscribers(Subscriber::all()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Shows the add subscriber view. |
42
|
|
|
* |
43
|
|
|
* @return \Illuminate\View\View |
44
|
|
|
*/ |
45
|
|
|
public function showAddSubscriber() |
46
|
|
|
{ |
47
|
|
|
return View::make('dashboard.subscribers.add') |
48
|
|
|
->withPageTitle(trans('dashboard.subscribers.add.title').' - '.trans('dashboard.dashboard')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Creates a new subscriber. |
53
|
|
|
* |
54
|
|
|
* @return \Illuminate\Http\RedirectResponse |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function createSubscriberAction() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
try { |
59
|
|
|
$this->dispatch(new SubscribeSubscriberCommand(Binput::get('email'))); |
60
|
|
|
} catch (ValidationException $e) { |
61
|
|
|
return Redirect::route('dashboard.subscribers.add') |
62
|
|
|
->withInput(Binput::all()) |
63
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.subscribers.add.failure'))) |
64
|
|
|
->withErrors($e->getMessageBag()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return Redirect::route('dashboard.subscribers.add') |
68
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.subscribers.add.success'))); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Deletes a subscriber. |
73
|
|
|
* |
74
|
|
|
* @param \Gitamin\Models\Subscriber $subscriber |
75
|
|
|
* |
76
|
|
|
* @throws \Exception |
77
|
|
|
* |
78
|
|
|
* @return \Illuminate\Http\RedirectResponse |
79
|
|
|
*/ |
80
|
|
|
public function deleteSubscriberAction(Subscriber $subscriber) |
81
|
|
|
{ |
82
|
|
|
$this->dispatch(new UnsubscribeSubscriberCommand($subscriber)); |
83
|
|
|
|
84
|
|
|
return Redirect::route('dashboard.subscribers.index'); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.