allow language installtion

This commit is contained in:
Dennis Eichhorn 2022-03-11 23:20:25 +01:00
parent 3f3b6b8c01
commit 37cbe7bdb8
3 changed files with 56 additions and 3 deletions

View 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' => [
]];

View File

@ -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);
}
}
}

View File

@ -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();