1
|
|
|
<?php namespace Anomaly\DashboardModule\Http\Controller\Admin; |
2
|
|
|
|
3
|
|
|
use Anomaly\DashboardModule\Dashboard\Contract\DashboardInterface; |
4
|
|
|
use Anomaly\DashboardModule\Dashboard\Contract\DashboardRepositoryInterface; |
5
|
|
|
use Anomaly\DashboardModule\Dashboard\Form\DashboardFormBuilder; |
6
|
|
|
use Anomaly\DashboardModule\Dashboard\Table\DashboardTableBuilder; |
7
|
|
|
use Anomaly\Streams\Platform\Http\Controller\AdminController; |
8
|
|
|
use Anomaly\UsersModule\User\Contract\UserInterface; |
9
|
|
|
use Illuminate\Contracts\Auth\Guard; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DashboardsController |
13
|
|
|
* |
14
|
|
|
* @link http://pyrocms.com/ |
15
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
16
|
|
|
* @author Ryan Thompson <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class DashboardsController extends AdminController |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Display a management index of existing entries. |
23
|
|
|
* |
24
|
|
|
* @param DashboardRepositoryInterface $dashboards |
25
|
|
|
* @return \Illuminate\Contracts\View\View|mixed |
26
|
|
|
*/ |
27
|
|
|
public function index(DashboardRepositoryInterface $dashboards) |
28
|
|
|
{ |
29
|
|
|
$dashboards = $dashboards->allowed(); |
30
|
|
|
|
31
|
|
|
/* @var DashboardInterface $dashboard */ |
32
|
|
|
if (!$dashboard = $dashboards->first()) { |
33
|
|
|
return $this->redirect->to('admin/dashboard/manage'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $this->redirect->to('admin/dashboard/view/' . $dashboard->getSlug()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Display a management index of existing entries. |
41
|
|
|
* |
42
|
|
|
* @param DashboardTableBuilder $table |
43
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
44
|
|
|
*/ |
45
|
|
|
public function manage(DashboardTableBuilder $table) |
46
|
|
|
{ |
47
|
|
|
return $table->render(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Create a new entry. |
52
|
|
|
* |
53
|
|
|
* @param DashboardFormBuilder $form |
54
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
55
|
|
|
*/ |
56
|
|
|
public function create(DashboardFormBuilder $form) |
57
|
|
|
{ |
58
|
|
|
return $form->render(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Edit an existing entry. |
63
|
|
|
* |
64
|
|
|
* @param DashboardFormBuilder $form |
65
|
|
|
* @param $id |
66
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
67
|
|
|
*/ |
68
|
|
|
public function edit(DashboardFormBuilder $form, $id) |
69
|
|
|
{ |
70
|
|
|
return $form->render($id); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* View a dashboard. |
75
|
|
|
* |
76
|
|
|
* @param DashboardRepositoryInterface $dashboards |
77
|
|
|
* @param Guard $guard |
78
|
|
|
* @param $dashboard |
79
|
|
|
* @return \Illuminate\Contracts\View\View|mixed |
80
|
|
|
*/ |
81
|
|
|
public function view(DashboardRepositoryInterface $dashboards, Guard $guard, $dashboard) |
82
|
|
|
{ |
83
|
|
|
$dashboards = $dashboards->allowed(); |
84
|
|
|
|
85
|
|
|
/* @var DashboardInterface $dashboard */ |
86
|
|
|
if (!$dashboard = $dashboards->find($dashboard)) { |
87
|
|
|
abort(404); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$dashboard->setActive(true); |
91
|
|
|
|
92
|
|
|
/* @var UserInterface $user */ |
93
|
|
|
$user = $guard->user(); |
94
|
|
|
$roles = $dashboard->getAllowedRoles(); |
95
|
|
|
|
96
|
|
|
if (!$roles->isEmpty() && !$user->hasAnyRole($roles)) { |
97
|
|
|
abort(403); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$this->template->set('show_banner', true); |
101
|
|
|
|
102
|
|
|
return $this->view->make( |
103
|
|
|
'module::admin/dashboards/dashboard', |
104
|
|
|
[ |
105
|
|
|
'dashboard' => $dashboard, |
106
|
|
|
'dashboards' => $dashboards, |
107
|
|
|
] |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|