diff --git a/Admin/Install/NavigationSkeleton.php b/Admin/Install/NavigationSkeleton.php new file mode 100644 index 0000000..4c03ca5 --- /dev/null +++ b/Admin/Install/NavigationSkeleton.php @@ -0,0 +1,16 @@ + [ +]]; diff --git a/Admin/Installer.php b/Admin/Installer.php index d154a7f..8ff693a 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -20,6 +20,7 @@ use phpOMS\Application\ApplicationAbstract; use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Module\InstallerAbstract; use phpOMS\System\File\PathException; +use phpOMS\Utils\Parser\Php\ArrayParser; /** * Installer class. @@ -70,6 +71,10 @@ final class Installer extends InstallerAbstract throw new \Exception(); // @codeCoverageIgnore } + if (($data['lang'] ?? null) !== null) { + self::installNavigationLanguage($data['lang'], $app->appName); + } + foreach ($navData as $link) { self::installLink($app->dbPool, $link, $data['app'] ?? null); } @@ -77,6 +82,28 @@ final class Installer extends InstallerAbstract return []; } + private static function installNavigationLanguage(string $path, string $appName) : void + { + $files = \scandir($path); + if ($files !== false) { + foreach ($files as $file) { + if (\stripos($file, 'Navigation') !== 0) { + continue; + } + + $localization = include \rtrim($path, '/') . '/' . $file; + + if (!\is_file($langPath = __DIR__ . '/../../../Web/' . $appName . '/lang/' . $file)) { + \copy(__DIR__ . '/Install/NavigationSkeleton.php', $langPath); + } + + $base = include $langPath; + $new = \array_merge($base, $localization); + \file_put_contents($langPath, 'target = (string) ($data['target'] ?? 'self'); $navElement->action = $data['action'] ?? null; $navElement->app = (int) ($data['app'] ?? ($app ?? 2)); - $navElement->from = (string) ($data['from'] ?? '0'); + $navElement->from = empty($from = (string) ($data['from'] ?? '')) ? '0' : $from; $navElement->order = (int) ($data['order'] ?? 1); $navElement->parent = (int) ($data['parent'] ?? 0); $navElement->permissionPerm = $data['permission']['permission'] ?? null; @@ -113,7 +140,7 @@ final class Installer extends InstallerAbstract NavElementMapper::create()->execute($navElement); foreach ($data['children'] as $link) { - self::installLink($dbPool, $link); + self::installLink($dbPool, $link, $app); } } } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 4934a01..c060f47 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -116,6 +116,9 @@ final class BackendController extends Controller $languages = $this->app->moduleManager->getLanguageFiles($request); $langCode = $response->getLanguage(); + // Add application navigation + $languages[] = '/Web/' . ($this->app->appName) . '/lang/Navigation'; + foreach ($languages as $path) { $path = __DIR__ . '/../../..' . $path . '.' . $langCode . '.lang.php'; @@ -236,7 +239,14 @@ final class BackendController extends Controller $module = $request->getData('id') ?? ''; $view->setData('module', $module); - $activeNavElements = NavElementMapper::getAll()->where('from', $module)->execute(); + $query = NavElementMapper::getAll() + ->where('from', $module); + + if ($module === 'Navigation') { + $query = $query->where('from', '0', connector: 'OR'); + } + + $activeNavElements = $query->execute(); $view->setData('navs', $activeNavElements); $apps = AppMapper::getAll()->execute();