-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBuildNavigationArray.php
More file actions
98 lines (85 loc) · 3.25 KB
/
Copy pathBuildNavigationArray.php
File metadata and controls
98 lines (85 loc) · 3.25 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
90
91
92
93
94
95
96
97
98
<?php
namespace FriendsOfRedaxo\QuickNavigation\Utility;
use rex;
use rex_addon;
use rex_article;
use rex_category;
use rex_clang;
use rex_context;
use rex_i18n;
use rex_url;
use rex_yrewrite;
class BuildNavigationArray
{
/**
* @return array<mixed>
*/
public static function GenerateBackendNavArray(int $clangId = null, bool $ignoreOffline = true, int $parentId = null, bool $includeHome = true): array
{
$user = rex::getUser();
if ($clangId === null) {
$clangId = rex_clang::getCurrentId();
}
$backendContext = rex_context::fromGet();
$backendContext->setParam('rex-api-call', 0);
$backendContext->setParam('clang', $clangId);
if ($backendContext->getParam('page') !== 'content/edit') {
if ($backendContext->getParam('page') !== 'linkmap') {
$backendContext->setParam('page', 'structure');
}
}
$articleId = rex_request('article_id', 'int');
$currentId = rex_request('category_id', 'int', $articleId);
if ($article = rex_article::get($articleId)) {
$currentId = $article->getCategoryId();
}
$categoriesArray = [];
if ($includeHome) {
$categoriesArray[] = [
'id' => 0,
'name' => rex_i18n::msg('root_level'),
'current' => $currentId === 0,
'domain' => 'default',
'url' => rex_url::backendPage('structure', ['clang' => $clangId]),
'children' => [],
];
}
$categories = [];
if ($parentId === null) {
$mountpoints = $user->getComplexPerm('structure')->getMountpoints();
if (!empty($mountpoints)) {
foreach ($mountpoints as $mpId) {
if ($mpCategory = rex_category::get($mpId, $clangId)) {
$categories[] = $mpCategory;
}
}
} else {
$categories = rex_category::getRootCategories($ignoreOffline, $clangId);
}
} elseif ($parentCategory = rex_category::get($parentId, $clangId)) {
$categories = $parentCategory->getChildren($ignoreOffline);
}
foreach ($categories as $category) {
if (!$user->getComplexPerm('structure')->hasCategoryPerm($category->getId())) {
continue;
}
$categoryId = $category->getId();
$backendContext->setParam('category_id', $categoryId);
$backendContext->setParam('article_id', $categoryId);
$domainName = '';
if (rex_addon::get('yrewrite')->isAvailable()) {
$domainName = rex_escape(rex_yrewrite::getDomainByArticleId($categoryId)->getName());
}
$current = $categoryId == $currentId;
$categoriesArray[] = [
'id' => $category->getId(),
'name' => $category->getName(),
'current' => $current,
'domain' => $domainName,
'url' => $backendContext->getUrl(),
'children' => self::generateBackendNavArray($clangId, $ignoreOffline, $category->getId(), false),
];
}
return $categoriesArray;
}
}