|
| 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 | +} |
0 commit comments