-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFavoriteButton.php
More file actions
89 lines (74 loc) · 3.23 KB
/
Copy pathFavoriteButton.php
File metadata and controls
89 lines (74 loc) · 3.23 KB
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
<?php
namespace FriendsOfRedaxo\QuickNavigation\Button;
use rex;
use rex_addon;
use rex_category;
use rex_clang;
use rex_fragment;
use rex_i18n;
use rex_string;
use rex_url;
use function count;
use function rex_escape;
class FavoriteButton implements ButtonInterface
{
public function get(): string
{
$user = rex::getUser();
if (!$user) {
return '';
}
$categoryIds = rex_addon::get('quick_navigation')->getConfig('quick_navigation_favs' . $user->getId());
$listItems = [];
if ($categoryIds && count($categoryIds) > 0) {
$clangId = rex_request('clang', 'int', rex_clang::getStartId());
foreach ($categoryIds as $categoryId) {
if (!$user->getComplexPerm('structure')->hasCategoryPerm($categoryId)) {
continue;
}
$category = rex_category::get($categoryId);
if ($category) {
$name = $category->getName();
} elseif (0 === $categoryId) {
$name = rex_i18n::msg('root_level');
} else {
continue;
}
$attributesArticleAdd = [
'href' => rex_url::backendPage('structure', ['clang' => $clangId, 'category_id' => $categoryId, 'function' => 'add_art']),
'title' => rex_i18n::msg('quick_navigation_favorite_article_add') . ' ' . $name,
];
$attributesCategoryAdd = [
'href' => rex_url::backendPage('structure', ['clang' => $clangId, 'category_id' => $categoryId, 'function' => 'add_cat']),
'title' => rex_i18n::msg('quick_navigation_favorite_category_add') . ' ' . $name,
];
$attributesCategoryLink = [
'href' => rex_url::backendPage('structure', ['clang' => $clangId, 'category_id' => $categoryId]),
'title' => $name,
];
$listItem = '
<div class="quick-navigation-item-row">
<a' . rex_string::buildAttributes($attributesCategoryLink) . '>
' . rex_escape($name) . '
</a>
<a' . rex_string::buildAttributes($attributesCategoryAdd) . '>
<i class="fa fa-folder-plus" aria-hidden="true"></i>
</a>
<a' . rex_string::buildAttributes($attributesArticleAdd) . '>
<i class="fa fa-file-medical" aria-hidden="true"></i>
</a>
</div>
';
$listItems[] = $listItem;
}
} else {
$listItems[] = '<a class="btn manage_favortites" href="'.rex_url::backendPage("quick_navigation/config").'">'.rex_i18n::msg('quick_navigation_manage_favorite').'</a>';
}
$fragment = new rex_fragment([
'label' => rex_i18n::msg('quick_navigation_favorite'),
'icon' => 'fa-regular fa-star',
'listItems' => $listItems,
]);
return $fragment->parse('QuickNavigation/Dropdown.php');
}
}