/
FavoritesNavigationFactory.php
74 lines (64 loc) · 2.03 KB
/
FavoritesNavigationFactory.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
<?php
namespace Concrete\Core\Application\UserInterface\Dashboard\Navigation;
use Concrete\Core\Foundation\Serializer\JsonSerializer;
use Concrete\Core\Navigation\Item\PageItem;
use Concrete\Core\Page\Page;
use Concrete\Core\Permission\Checker;
use Concrete\Core\User\User;
class FavoritesNavigationFactory
{
public $items = [
'/dashboard/welcome',
'/dashboard/composer/write',
'/dashboard/composer/drafts',
'/dashboard/sitemap/full',
'/dashboard/sitemap/search',
'/dashboard/files/search',
'/dashboard/files/sets',
'/dashboard/reports/forms',
];
/**
* @var FavoritesNavigationCache
*/
protected $cache;
/**
* @var User
*/
protected $user;
/**
* @var JsonSerializer
*/
protected $serializer;
public function __construct(FavoritesNavigationCache $cache, User $user, JsonSerializer $serializer)
{
$this->cache = $cache;
$this->user = $user;
$this->serializer = $serializer;
}
public function createNavigation(Page $startingPage = null): Navigation
{
if (!$this->cache->has()) {
$navigation = null;
$favorites = $this->user->config('DASHBOARD_FAVORITES');
if ($favorites) {
$navigation = $this->serializer->deserialize($favorites, Navigation::class, 'json');
}
if (!$navigation instanceof Navigation) {
$navigation = new Navigation();
foreach ($this->items as $path) {
$page = Page::getByPath($path);
if ($page && !$page->isError()) {
$checker = new Checker($page);
if ($checker->canViewPage()) {
$navigation->add(new PageItem($page));
}
}
}
}
$this->cache->set($navigation);
} else {
$navigation = $this->cache->get();
}
return $navigation;
}
}