mirror of
https://github.com/Karaka-Management/oms-Navigation.git
synced 2026-01-22 13:28:40 +00:00
allow language installtion
This commit is contained in:
parent
3f3b6b8c01
commit
37cbe7bdb8
16
Admin/Install/NavigationSkeleton.php
Normal file
16
Admin/Install/NavigationSkeleton.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\Localization
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://karaka.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
return ['Navigation' => [
|
||||
]];
|
||||
|
|
@ -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, '<?php return ' . ArrayParser::serializeArray($new) . ';');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Install navigation element.
|
||||
*
|
||||
|
|
@ -103,7 +130,7 @@ final class Installer extends InstallerAbstract
|
|||
$navElement->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user