/
DashboardPageController.php
179 lines (158 loc) · 5.11 KB
/
DashboardPageController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
namespace Concrete\Core\Page\Controller;
use Concrete\Core\Application\Service\DashboardMenu;
use Concrete\Core\Application\UserInterface\Dashboard\Navigation\FavoritesNavigationFactory;
use Concrete\Core\Cookie\CookieJar;
use Concrete\Core\Filesystem\ElementManager;
use Concrete\Core\Navigation\Breadcrumb\BreadcrumbInterface;
use Concrete\Core\Navigation\Breadcrumb\Dashboard\DashboardBreadcrumbFactory;
use Concrete\Core\Navigation\Item\PageItem;
use Doctrine\ORM\EntityManagerInterface;
use Mobile_Detect;
class DashboardPageController extends PageController
{
/**
* The Token instance (available after the on_start method has been called).
*
* @var \Concrete\Core\Validation\CSRF\Token|null
*/
public $token;
/**
* The ErrorList instance (available after the on_start method has been called).
*
* @var \Concrete\Core\Error\ErrorList\ErrorList|null
*/
protected $error;
/**
* The EntityManager instance (available after the on_start method has been called).
*
* @var \Doctrine\ORM\EntityManagerInterface|null
*/
protected $entityManager;
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Page\Controller\PageController::$restrictedMethods
*/
protected $restrictedMethods = [
'enableNativeMobile',
'getEntityManager',
];
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Controller\AbstractController::$helpers
*/
protected $helpers = ['form'];
/**
* Useful for traversing the site for elements and their associated controls, while allowing for overriding.
*
* @var ElementManager
*/
protected $elementManager;
/**
* @var BreadcrumbInterface
*/
protected $breadcrumb;
/**
* Check if the current user is using a mobile device: if so, configure the dashboard page accordingly.
*/
public function enableNativeMobile()
{
$md = new Mobile_Detect();
if ($md->isMobile()) {
$this->addHeaderItem('<meta name="viewport" content="width=device-width,initial-scale=1"/>');
}
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Controller\AbstractController::on_start()
*/
public function on_start()
{
$cookieJar = $this->app->make(CookieJar::class);
$this->token = $this->app->make('token');
$this->error = $this->app->make('error');
$this->entityManager = $this->app->make(EntityManagerInterface::class);
$this->elementManager = $this->app->make(ElementManager::class);
$this->set('interface', $this->app->make('helper/concrete/ui'));
$this->set('dashboard', $this->app->make('helper/concrete/dashboard'));
$this->set('hideDashboardPanel', $cookieJar->get('dashboardPanelStatus') === 'closed');
$favorites = $this->app->make(FavoritesNavigationFactory::class)->createNavigation();
if ($favorites->has(new PageItem($this->getPageObject()))) {
$this->set('_bookmarked', true);
} else {
$this->set('_bookmarked', false);
}
}
/**
* @return mixed
*/
protected function createBreadcrumbFactory()
{
return $this->app->make(DashboardBreadcrumbFactory::class);
}
protected function createBreadcrumb() : BreadcrumbInterface
{
$factory = $this->createBreadcrumbFactory();
return $factory->getBreadcrumb($this->getPageObject());
}
/**
* @return BreadcrumbInterface
*/
protected function getBreadcrumb(): ?BreadcrumbInterface
{
return $this->breadcrumb;
}
protected function setBreadcrumb(BreadcrumbInterface $breadcrumb)
{
$this->breadcrumb = $breadcrumb;
}
protected function getBreadcrumbElement()
{
return 'dashboard/navigation/breadcrumb';
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Controller\AbstractController::on_before_render()
*/
public function on_before_render()
{
$pageTitle = $this->get('pageTitle');
if (!$pageTitle) {
$this->set('pageTitle', t($this->c->getCollectionName()));
}
$breadcrumb = $this->getBreadcrumb();
if (!$breadcrumb) {
$breadcrumb = $this->createBreadcrumb();
}
$_breadcrumb = $this->elementManager->get($this->getBreadcrumbElement(), [
'breadcrumb' => $breadcrumb
]);
$dbConfig = $this->app->make('config/database');
$this->set('showPrivacyPolicyNotice', !$dbConfig->get('app.privacy_policy_accepted'));
$this->set('token', $this->token);
$this->set('error', $this->error);
$this->set('_breadcrumb', $_breadcrumb);
}
/**
* Get the EntityManager instance (available after the on_start method has been called).
*
* @return \Doctrine\ORM\EntityManagerInterface|null
*/
public function getEntityManager()
{
return $this->entityManager;
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Page\Controller\PageController::useUserLocale()
*/
public function useUserLocale()
{
return true;
}
}