From e47806985146bb9ba6a9933097f1442f1e493598 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 16 May 2024 02:14:54 +0000 Subject: [PATCH] Test fixes --- Controller/BackendController.php | 150 ++++++++++++++++++++-- Controller/Controller.js | 2 +- Docs/Dev/en/SUMMARY.md | 1 + Docs/{Help/de => Dev/en}/documentation.md | 0 Docs/Dev/en/structure.md | 5 - Docs/Help/de/SUMMARY.md | 3 - Docs/Help/de/introduction.md | 11 -- Docs/Help/en/SUMMARY.md | 3 - Docs/Help/en/documentation.md | 17 --- Docs/Help/en/introduction.md | 2 +- Docs/Help/img.json | 7 + info.json | 2 +- 12 files changed, 150 insertions(+), 53 deletions(-) rename Docs/{Help/de => Dev/en}/documentation.md (100%) mode change 100755 => 100644 delete mode 100755 Docs/Dev/en/structure.md delete mode 100755 Docs/Help/de/SUMMARY.md delete mode 100755 Docs/Help/de/introduction.md delete mode 100755 Docs/Help/en/SUMMARY.md delete mode 100755 Docs/Help/en/documentation.md create mode 100644 Docs/Help/img.json diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 61ac1ef..55c88b9 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -167,6 +167,12 @@ final class BackendController extends Controller $view->data['modules'] = $this->app->moduleManager->getInstalledModules(); + foreach ($view->data['modules'] as $idx => $_) { + if (!\is_file(__DIR__ . '/../../' . $idx . '/Docs/Help/en/introduction.md')) { + unset($view->data['modules'][$idx]); + } + } + $tableView = new TableView($this->app->l11nManager, $request, $response); $tableView->module = 'Help'; $tableView->theme = 'Backend'; @@ -230,6 +236,18 @@ final class BackendController extends Controller return $view; } + /** + * Show module ER diagram + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return RenderableInterface + * + * @since 1.0.0 + * @codeCoverageIgnore + */ public function viewHelpModuleER(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface { $active = $this->app->moduleManager->getActiveModules(); @@ -260,15 +278,40 @@ final class BackendController extends Controller return $view; } + /** + * Create ER diagram for module using Mappers (*Mapper.php) and database definition (db.json) + * + * @param string $module Module name + * + * @return string + * + * @since 1.0.0 + */ private function createERFromMappers(string $module) : string { $mappers = \scandir(__DIR__ . '/../../../Modules/' . $module . '/Models'); + if (!\is_array($mappers)) { + return ''; + } $toParse = "```mermaid\n"; $toParse .= "erDiagram\n"; $indent = 4; + $db = []; + if (\is_file(__DIR__ . '/../../../Modules/' . $module . '/Admin/Install/db.json')) { + $dbContent = \file_get_contents(__DIR__ . '/../../../Modules/' . $module . '/Admin/Install/db.json'); + + if ($dbContent !== false) { + $db = \json_decode($dbContent, true); + } + } + + if (!\is_array($db)) { + $db = []; + } + foreach ($mappers as $mapper) { if (!\str_ends_with($mapper, 'Mapper.php')) { continue; @@ -285,37 +328,122 @@ final class BackendController extends Controller $toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . " {\n"; - foreach ($class::COLUMNS as $data) { - $toParse .= \str_repeat(' ', $indent + 4) . $data['type'] . ' ' . \str_replace('/', '_', $data['internal']) . "\n"; + foreach ($class::COLUMNS as $column => $data) { + $toParse .= \str_repeat(' ', $indent + 4) . $data['type'] . ' ' . \str_replace('/', '_', $data['internal']); + + $relations = []; + if ($class::PRIMARYFIELD === $column) { + $relations[] = 'PK'; + } + + if (isset($db[$class::TABLE]['fields'][$column]['foreignTable'])) { + $relations[] = 'FK'; + } + + if (!empty($relations)) { + $toParse .= ' ' . \implode(', ', $relations); + } + + if (isset($db[$class::TABLE]['fields'][$column]['comment'])) { + $toParse .= ' "' . $db[$class::TABLE]['fields'][$column]['comment'] . '"'; + } + + $toParse .= "\n"; } foreach ($class::HAS_MANY as $name => $data) { - $toParse .= \str_repeat(' ', $indent + 4) . 'array ' . \str_replace('/', '_', $name) . "\n"; + $toParse .= \str_repeat(' ', $indent + 4) . 'array ' . \str_replace('/', '_', $name); + + $relations = []; + if (isset($db[$data['table']]['fields'][$data['self']]['foreignTable'])) { + $relations[] = 'FK'; + } + + if (!empty($relations)) { + $toParse .= ' ' . \implode(', ', $relations); + } + + if (isset($db[$data['table']]['fields'][$data['self']]['comment'])) { + $toParse .= ' "' . $db[$data['table']]['fields'][$data['self']]['comment'] . '"'; + } + + $toParse .= "\n"; } $toParse .= \str_repeat(' ', $indent) . "}\n"; foreach ($class::BELONGS_TO as $name => $data) { $childMapper = \substr($data['mapper'], \strrpos($data['mapper'], '\\') + 1, -6); - $toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--o| ' . $childMapper . " : references\n"; + $toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--o| ' . $childMapper . " : \"belongs to\"\n"; } foreach ($class::OWNS_ONE as $name => $data) { $childMapper = \substr($data['mapper'], \strrpos($data['mapper'], '\\') + 1, -6); - $toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--o| ' . $childMapper . " : references\n"; + $toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--o| ' . $childMapper . " : owns\n"; } foreach ($class::HAS_MANY as $name => $data) { $childMapper = \substr($data['mapper'], \strrpos($data['mapper'], '\\') + 1, -6); - $toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--|{ ' . $childMapper . " : references\n"; + $toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--|{ ' . $childMapper . " : has\n"; + } + + foreach ($db[$class::TABLE]['fields'] as $column => $field) { + if (!\is_array($field) + || !isset($field['foreignTable']) + || !isset($db[$field['foreignTable']]) + ) { + continue; + } + + foreach ($class::OWNS_ONE as $name => $data) { + if ($data['external'] === $field['foreignKey']) { + continue 2; + } + } + + foreach ($class::BELONGS_TO as $name => $data) { + if ($data['external'] === $field['foreignKey']) { + continue 2; + } + } + + foreach ($class::HAS_MANY as $name => $data) { + if ($data['external'] === $field['foreignKey']) { + continue 2; + } + } + + foreach ($mappers as $mapper2) { + if ($mapper === $mapper2) { + continue; + } + + if (!\str_ends_with($mapper2, 'Mapper.php')) { + continue; + } + + $childMapper = \substr($mapper2, 0, -10); + + $class2 = '\\Modules\\' . $module . '\\Models\\' . \substr($mapper2, 0, -4); + + if (!empty($class2::MODEL) + && \is_file(__DIR__ . '/../../../Modules/' . $module . '/Models/' . \substr($class2::MODEL, \strrpos($class2::MODEL, '\\') + 1) . 'Mapper.php') + && \substr($class2::MODEL, \strrpos($class2::MODEL, '\\') + 1) !== \substr($mapper2, 0, -10) + ) { + continue; + } + + if ($class2::TABLE === $field['foreignTable'] + && \stripos($toParse, \substr($mapper, 0, -10) . ' }|--|{ ' . $childMapper) === false + && \stripos($toParse, $childMapper . ' }|--|{ ' . \substr($mapper, 0, -10)) === false + ) { + $toParse .= \str_repeat(' ', $indent) . \substr($mapper, 0, -10) . ' }|--|{ ' . $childMapper . " : references\n"; + } + } } } - $toParse .= "\n```\n"; - - //echo $toParse; - - return $toParse; + return $toParse . "\n```\n"; } /** diff --git a/Controller/Controller.js b/Controller/Controller.js index 47b8eac..4f6e3d4 100644 --- a/Controller/Controller.js +++ b/Controller/Controller.js @@ -33,7 +33,7 @@ omsApp.Modules.Help = class { svg.html('' + svg.html() + ''); const inner = svg.select('g'); const zoom = d3.zoom().on('zoom', function(event) { - inner.attr('transform', event.transform); + inner.attr('transform', event.transform); }); svg.call(zoom); }); diff --git a/Docs/Dev/en/SUMMARY.md b/Docs/Dev/en/SUMMARY.md index 8a97952..f06fdb4 100755 --- a/Docs/Dev/en/SUMMARY.md +++ b/Docs/Dev/en/SUMMARY.md @@ -1,3 +1,4 @@ # Developer Content +* [Documentation]({%}&page=Dev/documentation) * [Structure]({%}&page=Dev/structure) diff --git a/Docs/Help/de/documentation.md b/Docs/Dev/en/documentation.md old mode 100755 new mode 100644 similarity index 100% rename from Docs/Help/de/documentation.md rename to Docs/Dev/en/documentation.md diff --git a/Docs/Dev/en/structure.md b/Docs/Dev/en/structure.md deleted file mode 100755 index dbc16f3..0000000 --- a/Docs/Dev/en/structure.md +++ /dev/null @@ -1,5 +0,0 @@ -# Structure - -## ER - -![ER](Modules/Help/Docs/Dev/img/er.png) \ No newline at end of file diff --git a/Docs/Help/de/SUMMARY.md b/Docs/Help/de/SUMMARY.md deleted file mode 100755 index ee41ebe..0000000 --- a/Docs/Help/de/SUMMARY.md +++ /dev/null @@ -1,3 +0,0 @@ -# User Content - -* [Documentation]({%}&page=Help/documentation) \ No newline at end of file diff --git a/Docs/Help/de/introduction.md b/Docs/Help/de/introduction.md deleted file mode 100755 index e23d9b5..0000000 --- a/Docs/Help/de/introduction.md +++ /dev/null @@ -1,11 +0,0 @@ -# Introduction - -The **Help** module is one of the essential core modules that is always required. This module allows other modules to provide helpful documentation for users, administrators and developers. - -## Target Group - -The target group for this module is everyone. - -# Setup - -This module doesn't have any additional setup requirements since it is installed during the application install process. This module cannot be uninstalled if it is manually deleted from the hard drive please manually download the module from the page and put it into the `Modules/` directory. \ No newline at end of file diff --git a/Docs/Help/en/SUMMARY.md b/Docs/Help/en/SUMMARY.md deleted file mode 100755 index ee41ebe..0000000 --- a/Docs/Help/en/SUMMARY.md +++ /dev/null @@ -1,3 +0,0 @@ -# User Content - -* [Documentation]({%}&page=Help/documentation) \ No newline at end of file diff --git a/Docs/Help/en/documentation.md b/Docs/Help/en/documentation.md deleted file mode 100755 index 25d1dca..0000000 --- a/Docs/Help/en/documentation.md +++ /dev/null @@ -1,17 +0,0 @@ -# Documentation - -A documentation can be added to every module by adding the `Docs/Help/{lang}` directory in the module. The language directory needs to be a 2 character ISO code. Inside of this directory you can add/find all the documentation files provided by the module. - -Mandatory files are a `SUMMARY.md` file which contains the list of all documents and a `introduction.md` file which contains a general description of the module. - -## SUMMARY.md example - -```md -# Table of Contents - -* [Link Name 1]({%}&page=Help/document_name_1) -* [Link Name 2]({%}&page=Help/document_name_2) -* [Link Name 3]({%}&page=Help/document_name_3) -``` - -![Directory Structure](Modules/Help/Docs/Help/img/directory_structure.png) \ No newline at end of file diff --git a/Docs/Help/en/introduction.md b/Docs/Help/en/introduction.md index e23d9b5..79e420f 100755 --- a/Docs/Help/en/introduction.md +++ b/Docs/Help/en/introduction.md @@ -8,4 +8,4 @@ The target group for this module is everyone. # Setup -This module doesn't have any additional setup requirements since it is installed during the application install process. This module cannot be uninstalled if it is manually deleted from the hard drive please manually download the module from the page and put it into the `Modules/` directory. \ No newline at end of file +This module doesn't have any additional setup requirements. This module cannot be uninstalled if it is manually deleted from the hard drive please manually download the module from the page and put it into the `Modules/` directory. \ No newline at end of file diff --git a/Docs/Help/img.json b/Docs/Help/img.json new file mode 100644 index 0000000..07af053 --- /dev/null +++ b/Docs/Help/img.json @@ -0,0 +1,7 @@ +[ + [ + "/?darkmode", + "/html/body", + "/../User-Guide/ui/img/darkmode.png" + ] +] \ No newline at end of file diff --git a/info.json b/info.json index a9a26db..efedadd 100755 --- a/info.json +++ b/info.json @@ -12,7 +12,7 @@ }, "creator": { "name": "Jingga", - "website": "jingga.app" + "website": "https://jingga.app" }, "description": "The backend help module.", "directory": "Help",