Skip to content

Commit 1ec5096

Browse files
author
s.kochin
committed
core (add) Added controller Modules
1 parent 417b0dc commit 1ec5096

File tree

4 files changed

+225
-169
lines changed

4 files changed

+225
-169
lines changed

core/src/Controllers/Modules.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace EvolutionCMS\Controllers;
6+
7+
use EvolutionCMS\Interfaces\ManagerTheme;
8+
use EvolutionCMS\Models\Category;
9+
use EvolutionCMS\Support\ContextMenu;
10+
use Illuminate\Database\Eloquent\Builder;
11+
use Illuminate\Support\Collection;
12+
13+
class Modules extends AbstractController implements ManagerTheme\PageControllerInterface
14+
{
15+
/**
16+
* @var string
17+
*/
18+
protected $view = 'page.modules';
19+
20+
/**
21+
* @return bool
22+
*/
23+
public function canView(): bool
24+
{
25+
return $this->managerTheme->getCore()
26+
->hasAnyPermissions([
27+
'exec_module',
28+
'new_module',
29+
'edit_module',
30+
'save_module',
31+
'delete_module'
32+
]);
33+
}
34+
35+
/**
36+
* @return string|null
37+
*/
38+
public function checkLocked(): ?string
39+
{
40+
return null;
41+
}
42+
43+
/**
44+
* @return bool
45+
*/
46+
public function process(): bool
47+
{
48+
$this->parameters = [
49+
'contextMenu' => $this->getContextMenu(),
50+
'categories' => $this->getCategories(),
51+
];
52+
53+
return true;
54+
}
55+
56+
/**
57+
* @return array
58+
*/
59+
protected function getContextMenu(): array
60+
{
61+
// context menu
62+
$cm = new ContextMenu('cntxm', 150);
63+
64+
$cm->addItem(__('global.run_module'), "js:menuAction(1)", $this->managerTheme->getStyle('icon_play'), (!$this->managerTheme->getCore()
65+
->hasPermission('exec_module') ? 1 : 0));
66+
if ($this->managerTheme->getCore()
67+
->hasAnyPermissions([
68+
'new_module',
69+
'edit_module',
70+
'delete_module'
71+
])) {
72+
$cm->addSeparator();
73+
}
74+
$cm->addItem(__('global.edit'), 'js:menuAction(2)', $this->managerTheme->getStyle('icon_edit'), (!$this->managerTheme->getCore()
75+
->hasPermission('edit_module') ? 1 : 0));
76+
$cm->addItem(__('global.duplicate'), 'js:menuAction(3)', $this->managerTheme->getStyle('icon_clone'), (!$this->managerTheme->getCore()
77+
->hasPermission('new_module') ? 1 : 0));
78+
$cm->addItem(__('global.delete'), 'js:menuAction(4)', $this->managerTheme->getStyle('icon_trash'), (!$this->managerTheme->getCore()
79+
->hasPermission('delete_module') ? 1 : 0));
80+
81+
return [
82+
'menu' => $cm->render(),
83+
'script' => $cm->getClientScriptObject()
84+
];
85+
}
86+
87+
/**
88+
* @return Collection
89+
*/
90+
protected function getCategories(): Collection
91+
{
92+
return Category::with('modules')
93+
->whereHas('modules', function (Builder $builder) {
94+
return $builder->lockedView();
95+
})
96+
->orderBy('rank', 'ASC')
97+
->get();
98+
}
99+
}

core/src/ManagerTheme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class ManagerTheme implements ManagerThemeInterface
9898
/** empty cache & synchronisation */
9999
26 => Controllers\RefreshSite::class,
100100
/** Module management */
101-
106,
101+
106 => Controllers\Modules::class,
102102
107,
103103
108,
104104
109,

manager/actions/modules.static.php

Lines changed: 0 additions & 168 deletions
This file was deleted.

0 commit comments

Comments
 (0)