diff --git a/Admin/Activate.php b/Admin/Activate.php new file mode 100644 index 0000000..6eede60 --- /dev/null +++ b/Admin/Activate.php @@ -0,0 +1,44 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Navigation\Admin; + + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\ActivateAbstract; +use phpOMS\Module\InfoManager; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Activate extends ActivateAbstract +{ + + /** + * {@inheritdoc} + */ + public static function activate(DatabasePool $dbPool, InfoManager $info) + { + parent::activate($dbPool, $info); + } +} diff --git a/Admin/Deactivate.php b/Admin/Deactivate.php new file mode 100644 index 0000000..1133c7c --- /dev/null +++ b/Admin/Deactivate.php @@ -0,0 +1,44 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Navigation\Admin; + + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\DeactivateAbstract; +use phpOMS\Module\InfoManager; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Deactivate extends DeactivateAbstract +{ + + /** + * {@inheritdoc} + */ + public static function deactivate(DatabasePool $dbPool, InfoManager $info) + { + parent::deactivate($dbPool, $info); + } +} diff --git a/Admin/Installer.php b/Admin/Installer.php new file mode 100644 index 0000000..57e54dc --- /dev/null +++ b/Admin/Installer.php @@ -0,0 +1,132 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Navigation\Admin; + +use phpOMS\DataStorage\Database\DatabaseType; +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\InfoManager; +use phpOMS\Module\InstallerAbstract; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Navigation + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Installer extends InstallerAbstract +{ + + /** + * {@inheritdoc} + */ + public static function install(string $path, DatabasePool $dbPool, InfoManager $info) + { + parent::install($path, $dbPool, $info); + + switch ($dbPool->get('core')->getType()) { + case DatabaseType::MYSQL: + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'nav` ( + `nav_id` int(11) NOT NULL, + `nav_pid` varchar(40) NOT NULL, + `nav_name` varchar(40) NOT NULL, + `nav_type` tinyint(1) NOT NULL, + `nav_subtype` tinyint(1) NOT NULL, + `nav_icon` varchar(40) DEFAULT NULL, + `nav_uri` varchar(255) DEFAULT NULL, + `nav_target` varchar(10) DEFAULT NULL, + `nav_from` varchar(255) DEFAULT NULL, + `nav_order` smallint(3) DEFAULT NULL, + `nav_parent` int(11) DEFAULT NULL, + `nav_permission` int(11) DEFAULT NULL, + PRIMARY KEY (`nav_id`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8;' + )->execute(); + break; + } + } + + /** + * Install data from providing modules. + * + * @param Pool $dbPool Database pool + * @param array $data Module info + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function installExternal(DatabasePool $dbPool, array $data) + { + try { + $dbPool->get('core')->con->query('select 1 from `' . $dbPool->get('core')->prefix . 'nav`'); + } catch (\Exception $e) { + return; + } + + foreach ($data as $link) { + self::installLink($dbPool, $link, $link['parent']); + } + } + + /** + * Install navigation element. + * + * @param Pool $dbPool Database instance + * @param array $data Link info + * @param int $parent Parent element (default is 0 for none) + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + private static function installLink($dbPool, $data, $parent = 0) + { + $sth = $dbPool->get('core')->con->prepare( + 'INSERT INTO `' . $dbPool->get('core')->prefix . 'nav` (`nav_id`, `nav_pid`, `nav_name`, `nav_type`, `nav_subtype`, `nav_icon`, `nav_uri`, `nav_target`, `nav_from`, `nav_order`, `nav_parent`, `nav_permission`) VALUES + (:id, :pid, :name, :type, :subtype, :icon, :uri, :target, :from, :order, :parent, :perm);' + ); + + $sth->bindValue(':id', $data['id'] ?? 0, \PDO::PARAM_INT); + $sth->bindValue(':pid', $data['pid'] ?? '', \PDO::PARAM_STR); + $sth->bindValue(':name', $data['name'] ?? '', \PDO::PARAM_STR); + $sth->bindValue(':type', $data['type'] ?? 1, \PDO::PARAM_INT); + $sth->bindValue(':subtype', $data['subtype'] ?? 2, \PDO::PARAM_INT); + $sth->bindValue(':icon', $data['icon'] ?? null, \PDO::PARAM_STR); + $sth->bindValue(':uri', $data['uri'] ?? null, \PDO::PARAM_STR); + $sth->bindValue(':target', $data['target'] ?? "self", \PDO::PARAM_STR); + $sth->bindValue(':from', $data['from'] ?? 0, \PDO::PARAM_INT); + $sth->bindValue(':order', $data['order'] ?? 1, \PDO::PARAM_INT); + $sth->bindValue(':parent', $parent, \PDO::PARAM_INT); + $sth->bindValue(':perm', $data['permission'] ?? 0, \PDO::PARAM_INT); + + $sth->execute(); + + $lastInsertID = $dbPool->get('core')->con->lastInsertId(); + + foreach ($data['children'] as $link) { + $parent = ($link['parent'] == null ? $lastInsertID : $link['parent']); + self::installLink($dbPool, $link, $parent); + } + } +} diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php new file mode 100644 index 0000000..0b67a5f --- /dev/null +++ b/Admin/Routes/Web/Backend.php @@ -0,0 +1,3 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Navigation\Admin; + + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\DataStorage\Database\Schema\Builder; +use phpOMS\Module\UninstallAbstract; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Uninstall extends UninstallAbstract +{ + + /** + * {@inheritdoc} + */ + public static function uninstall(DatabasePool $dbPool, InfoManager $info) + { + parent::uninstall($dbPool, $info); + + $query = new Builder($dbPool->get()); + + $query->prefix($dbPool->get('core')->getPrefix())->drop( + 'nav' + ); + + $dbPool->get()->con->prepare($query->toSql())->execute(); + } +} diff --git a/Admin/Update.php b/Admin/Update.php new file mode 100644 index 0000000..5676489 --- /dev/null +++ b/Admin/Update.php @@ -0,0 +1,46 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Navigation\Admin; + + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\UpdateAbstract; +use phpOMS\System\File\Directory; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Update extends UpdateAbstract +{ + + /** + * {@inheritdoc} + */ + public static function update(DatabasePool $dbPool, array $info) + { + Directory::deletePath(__DIR__ . '/Update'); + mkdir('Update'); + parent::update($dbPool, $info); + } +} diff --git a/Controller.js b/Controller.js new file mode 100644 index 0000000..c9aee0c --- /dev/null +++ b/Controller.js @@ -0,0 +1,132 @@ +/** + * Navigation controller. + * + * @author OMS Development Team + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 * @since 1.0.0 + */ +(function (jsOMS) +{ + "use strict"; + + /** @namespace jsOMS.Modules.Navigation.Models */ + jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Navigation'); + + /** + * Constructor + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation = function () + { + this.navigation = {}; + this.rawNavData = JSON.parse(localStorage.getItem(jsOMS.Modules.Navigation.MODULE_NAME)); + this.rawNavData = this.rawNavData !== null ? this.rawNavData : {}; + }; + + /** + * Module id + * + * @var {string} + * @since 1.0.0 + */ + jsOMS.Modules.Navigation.MODULE_NAME = '1000500001'; + + /** + * Bind navigation + * + * @param {string} id Navigation to bind (optional) + * + * @return {void} + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation.prototype.bind = function (id) + { + let e = typeof id === 'undefined' ? document.getElementsByClassName('nav') : [document.getElementById(id)], + length = e.length; + + for (let i = 0; i < length; i++) { + this.bindElement(e[i]); + } + }; + + /** + * Bind navigation element + * + * @param {Element} e Element to bind + * + * @return {void} + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation.prototype.bindElement = function (e) + { + if (typeof e === 'undefined' || !e) { + // todo: do logging here + + return; + } + + let extend = e.querySelectorAll('li label'), + self = this; + + this.navigation[e.id] = new jsOMS.Modules.Navigation.Models.Navigation(this.rawNavData[e.id]); + + // On load + let open = this.navigation[e.id].getOpen(); + + for (let key in open) { + if (open.hasOwnProperty(key)) { + document.getElementById(key).checked = open[key]; + } + } + + if (!this.navigation[e.id].isVisible()) { + e.nextElementSibling.checked = false; + } + + e.scrollTop = this.navigation[e.id].getScrollPosition().y; + e.scrollLeft = this.navigation[e.id].getScrollPosition().x; + + // Bind minimize/maximize + jsOMS.addEventListenerToAll(extend, 'click', function () + { + let box = document.getElementById(this.getAttribute('for')); + + if (!box.checked) { + self.navigation[e.id].setOpen(box.id); + } else { + self.navigation[e.id].setClose(box.id); + } + + localStorage.setItem(jsOMS.Modules.Navigation.MODULE_NAME, JSON.stringify(self.navigation)); + }); + + // Bind show/hide + e.nextElementSibling.addEventListener('change', function () + { + self.navigation[e.id].setVisible(this.checked); + localStorage.setItem(jsOMS.Modules.Navigation.MODULE_NAME, JSON.stringify(self.navigation)); + }); + + // Bind scroll + e.addEventListener('scroll', function () + { + self.navigation[e.id].setScrollPosition(this.scrollLeft, this.scrollTop); + localStorage.setItem(jsOMS.Modules.Navigation.MODULE_NAME, JSON.stringify(self.navigation)); + }); + }; +}(window.jsOMS = window.jsOMS || {})); + +jsOMS.ready(function () +{ + "use strict"; + + window.omsApp.moduleManager.get('Navigation').bind('nav-side'); +}); \ No newline at end of file diff --git a/Controller.php b/Controller.php new file mode 100644 index 0000000..c70aa34 --- /dev/null +++ b/Controller.php @@ -0,0 +1,173 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Navigation; + +use Modules\Navigation\Models\Navigation; +use Modules\Navigation\Models\NavigationType; +use Modules\Navigation\Views\NavigationView; +use phpOMS\Contract\RenderableInterface; +use phpOMS\Message\RequestAbstract; +use phpOMS\Message\ResponseAbstract; +use phpOMS\Module\ModuleAbstract; +use phpOMS\Module\WebInterface; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Navigation + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Controller extends ModuleAbstract implements WebInterface +{ + + /** + * Module path. + * + * @var string + * @since 1.0.0 + */ + /* public */ const MODULE_PATH = __DIR__; + + /** + * Module version. + * + * @var string + * @since 1.0.0 + */ + /* public */ const MODULE_VERSION = '1.0.0'; + + /** + * Module name. + * + * @var string + * @since 1.0.0 + */ + /* public */ const MODULE_NAME = 'Navigation'; + + /** + * Providing. + * + * @var string[] + * @since 1.0.0 + */ + protected static $providing = [ + ]; + + /** + * Dependencies. + * + * @var string[] + * @since 1.0.0 + */ + protected static $dependencies = [ + ]; + + /** + * Constructor. + * + * @param \Web\WebApplication $app Application + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function __construct($app) + { + parent::__construct($app); + } + + /** + * @param int $pageId Page/parent Id for navigation + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * + * @return RenderableInterface + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function createNavigationMid(int $pageId, RequestAbstract $request, ResponseAbstract $response) + { + $nav = Navigation::getInstance($request, $this->app->dbPool); + $navView = new NavigationView($this->app, $request, $response); + $navView->setTemplate('/Modules/Navigation/Theme/Backend/mid'); + $navView->setNav($nav->getNav()); + $navView->setLanguage($request->getL11n()->getLanguage()); + $navView->setParent($pageId); + + return $navView; + } + + public function getView(RequestAbstract $request, ResponseAbstract $response) + { + $navObj = \Modules\Navigation\Models\Navigation::getInstance($request, $this->app->dbPool); + $nav = new \Modules\Navigation\Views\NavigationView($this->app, $request, $response); + $nav->setNav($navObj->getNav()); + $nav->setLanguage($request->getL11n()->getLanguage()); + $unread = []; + + foreach($this->receiving as $receiving) { + $unread[$receiving] = $this->app->moduleManager->get($receiving)->openNav($request->getAccount()); + } + + $nav->setData('unread', $unread); + + return $nav; + } + + public function loadLanguage(RequestAbstract $request, ResponseAbstract $response) { + $languages = $this->app->moduleManager->getLanguageFiles($request); + + foreach ($languages as $path) { + if ($path[strlen($path) - 1] === '/') { + // Is not a navigation file + continue; + } + + $path = __DIR__ . '/../..' . $path . '.' . $response->getL11n()->getLanguage() . '.lang.php'; + + /** @noinspection PhpIncludeInspection */ + $lang = include $path; + $this->app->l11nManager->loadLanguage($response->getL11n()->getLanguage(), 'Navigation', $lang); + } + } + + /** + * @param int $pageId Page/parent Id for navigation + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * + * @return RenderableInterface + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function createNavigationSplash(int $pageId, RequestAbstract $request, ResponseAbstract $response) + { + $nav = Navigation::getInstance($request, $this->app->dbPool); + $navView = new NavigationView($this->app, $request, $response); + $navView->setTemplate('/Modules/Navigation/Theme/Backend/splash'); + $navView->setNav($nav->getNav()); + $navView->setLanguage($request->getL11n()->getLanguage()); + $navView->setParent($pageId); + + return $navView; + } +} diff --git a/Models/LinkType.php b/Models/LinkType.php new file mode 100644 index 0000000..8fb8001 --- /dev/null +++ b/Models/LinkType.php @@ -0,0 +1,36 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Navigation\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Link type enum. + * + * @category Modules + * @package Framework + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +abstract class LinkType extends Enum +{ + /* public */ const CATEGORY = 0; + + /* public */ const LINK = 1; +} diff --git a/Models/Navigation.js b/Models/Navigation.js new file mode 100644 index 0000000..cfd64be --- /dev/null +++ b/Models/Navigation.js @@ -0,0 +1,154 @@ +/** + * Navigation class. + * + * @author OMS Development Team + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 * @since 1.0.0 + */ +(function (jsOMS) +{ + "use strict"; + + /** @namespace jsOMS.Modules.Navigation.Models */ + jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Navigation.Models'); + + /** + * Construct + * + * @param {Object} data Initialization (optional) + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation.Models.Navigation = function (data) + { + if (typeof data === 'undefined') { + this.scrollPosition = {x: 0, y: 0}; + this.activeLinks = {}; + this.visible = true; + this.openCategories = {}; + } else { + this.scrollPosition = typeof data.scrollPosition === 'undefined' ? {x: 0, y: 0} : data.scrollPosition; + this.activeLinks = typeof data.activeLinks === 'undefined' ? {} : data.activeLinks; + this.visible = typeof data.visible === 'undefined' ? true : data.visible; + this.openCategories = typeof data.openCategories === 'undefined' ? {} : data.openCategories; + } + }; + + /** + * Set scroll position + * + * @param {int} x Horizontal position + * @param {int} y Vertical position + * + * @return {void} + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation.Models.Navigation.prototype.setScrollPosition = function (x, y) + { + this.scrollPosition.x = x; + this.scrollPosition.y = y; + }; + + /** + * Get scroll position + * + * @return {Object} + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation.Models.Navigation.prototype.getScrollPosition = function () + { + return this.scrollPosition; + }; + + /** + * Open navigation category + * + * @param {string} id Category id + * + * @return {void} + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation.Models.Navigation.prototype.setOpen = function (id) + { + this.openCategories[id] = true; + }; + + /** + * Close navigation category + * + * @param {string} id Category id + * + * @return {void} + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation.Models.Navigation.prototype.setClose = function (id) + { + delete this.openCategories[id]; + }; + + /** + * Get open navigation elements + * + * @return {Object} + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation.Models.Navigation.prototype.getOpen = function () + { + return this.openCategories; + }; + + jsOMS.Modules.Navigation.Models.Navigation.prototype.active = function (id) + { + this.allInactive(); + }; + + jsOMS.Modules.Navigation.Models.Navigation.prototype.allInactive = function () + { + + }; + + jsOMS.Modules.Navigation.Models.Navigation.prototype.inactive = function (id) + { + }; + + /** + * Set navigation visibility + * + * @param {bool} visible Visibility + * + * @return {bool} + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation.Models.Navigation.prototype.setVisible = function (visible) + { + this.visible = visible; + }; + + /** + * Is navigation visible + * + * @return {bool} + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Modules.Navigation.Models.Navigation.prototype.isVisible = function () + { + return this.visible; + }; +}(window.jsOMS = window.jsOMS || {})); diff --git a/Models/Navigation.php b/Models/Navigation.php new file mode 100644 index 0000000..0050ef7 --- /dev/null +++ b/Models/Navigation.php @@ -0,0 +1,156 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Navigation\Models; + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Message\RequestAbstract; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Navigation + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Navigation +{ + + /** + * Navigation array. + * + * Array of all navigation elements sorted by type->parent->id + * + * @var array + * @since 1.0.0 + */ + private $nav = []; + + /** + * Singleton instance. + * + * @var \Modules\Navigation\Models\Navigation + * @since 1.0.0 + */ + private static $instance = null; + + /** + * Database pool. + * + * @var Pool + * @since 1.0.0 + */ + private $dbPool = null; + + /** + * Constructor. + * + * @param RequestAbstract $request Request hashes + * @param Pool $dbPool Database pool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + private function __construct(RequestAbstract $request, DatabasePool $dbPool = null) + { + $this->dbPool = $dbPool; + $this->load($request->getHash()); + } + + /** + * Load navigation based on request. + * + * @param string[] $request Request hashes + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + private function load($request) + { + if (empty($this->nav)) { + $this->nav = []; + $uriPdo = ''; + + $i = 1; + foreach ($request as $hash) { + $uriPdo .= ':pid' . $i . ','; + $i++; + } + + $uriPdo = rtrim($uriPdo, ','); + $sth = $this->dbPool->get('core')->con->prepare('SELECT * FROM `' . $this->dbPool->get('core')->prefix . 'nav` WHERE `nav_pid` IN(' . $uriPdo . ') ORDER BY `nav_order` ASC'); + + $i = 1; + foreach ($request as $hash) { + $sth->bindValue(':pid' . $i, $hash, \PDO::PARAM_STR); + $i++; + } + + $sth->execute(); + $tempNav = $sth->fetchAll(); + + foreach ($tempNav as $link) { + $this->nav[$link['nav_type']][$link['nav_subtype']][$link['nav_id']] = $link; + } + } + } + + /** + * Get instance. + * + * @param RequestAbstract $request Request hashes + * @param Pool $dbPool Database pool + * + * @return \Modules\Navigation\Models\Navigation + * + * @throws \Exception + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function getInstance(RequestAbstract $request = null, DatabasePool $dbPool = null) + { + if (!isset(self::$instance)) { + if(!isset($request) || !isset($dbPool)) { + throw new \Exception('Invalid parameters'); + } + + self::$instance = new self($request, $dbPool); + } + + return self::$instance; + } + + /** + * Overwriting clone in order to maintain singleton pattern. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function __clone() + { + } + + public function getNav() + { + return $this->nav; + } +} diff --git a/Models/NavigationType.php b/Models/NavigationType.php new file mode 100644 index 0000000..155b421 --- /dev/null +++ b/Models/NavigationType.php @@ -0,0 +1,44 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Navigation\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Navigation type enum. + * + * @category Modules + * @package Framework + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +abstract class NavigationType extends Enum +{ + /* public */ const TOP = 1; + + /* public */ const SIDE = 2; + + /* public */ const CONTENT = 3; + + /* public */ const TAB = 4; + + /* public */ const CONTENT_SIDE = 5; + + /* public */ const BOTTOM = 6; +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..686a0e5 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Navigation # diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php new file mode 100644 index 0000000..e49c24a --- /dev/null +++ b/Theme/Backend/Lang/en.lang.php @@ -0,0 +1,16 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +return ['Navigation' => []]; \ No newline at end of file diff --git a/Theme/Backend/mid-side.tpl.php b/Theme/Backend/mid-side.tpl.php new file mode 100644 index 0000000..cef6a2f --- /dev/null +++ b/Theme/Backend/mid-side.tpl.php @@ -0,0 +1,40 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +/** + * @var \Modules\Navigation\Views\NavigationView $this + */ + +/* Looping through all links */ +if (isset($this->nav[\Modules\Navigation\Models\NavigationType::CONTENT_SIDE])) { + echo '
' + . '

' . $this->getText('Navigation') + . '' + . '

' + . '
' + . '
'; +} diff --git a/Theme/Backend/mid.tpl.php b/Theme/Backend/mid.tpl.php new file mode 100644 index 0000000..646944e --- /dev/null +++ b/Theme/Backend/mid.tpl.php @@ -0,0 +1,32 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +/** + * @var \Modules\Navigation\Views\NavigationView $this + */ +if (isset($this->nav[\Modules\Navigation\Models\NavigationType::CONTENT])) { + echo '
'; +} diff --git a/Theme/Backend/side.tpl.php b/Theme/Backend/side.tpl.php new file mode 100644 index 0000000..b0d7044 --- /dev/null +++ b/Theme/Backend/side.tpl.php @@ -0,0 +1,53 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +/** + * @var \Modules\Navigation\Views\NavigationView $this + */ +if (isset($this->nav[\Modules\Navigation\Models\NavigationType::SIDE])) : ?> + + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ endif; diff --git a/Theme/Backend/splash.tpl.php b/Theme/Backend/splash.tpl.php new file mode 100644 index 0000000..28a38d5 --- /dev/null +++ b/Theme/Backend/splash.tpl.php @@ -0,0 +1,31 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +/** + * @var \Modules\Navigation\Views\NavigationView $this + */ +if (isset($this->nav[\Modules\Navigation\Models\NavigationType::CONTENT])) : + foreach ($this->nav[\Modules\Navigation\Models\NavigationType::CONTENT] as $key => $parent) : + foreach ($parent as $link) : + if ($link['nav_parent'] == $this->parent) : ?> +
+ +
+ + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +/** + * @var \Modules\Navigation\Views\NavigationView $this + */ +if (isset($this->nav[\Modules\Navigation\Models\NavigationType::TOP])): ?> + + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Navigation\Views; + +use phpOMS\Views\View; + +/** + * Navigation view. + * + * @category Modules + * @package Modules\Navigation + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class NavigationView extends View +{ + + /** + * Navigation Id. + * + * This is getting used in order to identify which navigation elements should get rendered. + * This usually is the parent navigation id + * + * @var int + * @since 1.0.0 + */ + protected $navId = null; + + /** + * Navigation. + * + * @var mixed[] + * @since 1.0.0 + */ + protected $nav = []; + + /** + * Language used for the navigation. + * + * @var string + * @since 1.0.0 + */ + protected $language = 'en'; + + /** + * Parent element used for navigation. + * + * @var int + * @since 1.0.0 + */ + protected $parent = 0; + + /** + * {@inheritdoc} + */ + public function __construct($app, $request, $response) + { + parent::__construct($app, $request, $response); + } + + /** + * Get navigation Id. + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getNavId() : int + { + return $this->navId; + } + + /** + * Set navigation Id. + * + * @param int $navId Navigation id used for display + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setNavId(int $navId) + { + $this->navId = $navId; + } + + /** + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getNav() : array + { + return $this->nav; + } + + /** + * @param mixed $nav + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setNav(array $nav) + { + $this->nav = $nav; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getLanguage() : string + { + return $this->language; + } + + /** + * @param string $language + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setLanguage(string $language) + { + $this->language = $language; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getParent() : int + { + return $this->parent; + } + + /** + * @param int $parent + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setParent(int $parent) + { + $this->parent = $parent; + } +} diff --git a/docs/guidelines.dev.md b/docs/guidelines.dev.md new file mode 100644 index 0000000..2796bd7 --- /dev/null +++ b/docs/guidelines.dev.md @@ -0,0 +1,3 @@ +## Installation + +The order of link elements inside the `Navigation.install.json` file needs to be unique. In case the order is not unique it's possible that the link order can vary from page to page. diff --git a/docs/info.md b/docs/info.md new file mode 100644 index 0000000..db3bfa1 --- /dev/null +++ b/docs/info.md @@ -0,0 +1,11 @@ +# Navigation levels + +0. None +1. Top bar +2. Side bar +3. Content bar +4. Content Side +5. Tabs +6. Dashboard +7. Content Footer +8. Footer \ No newline at end of file diff --git a/img/module_teaser_small.png b/img/module_teaser_small.png new file mode 100644 index 0000000..f56e6ff Binary files /dev/null and b/img/module_teaser_small.png differ diff --git a/info.json b/info.json new file mode 100644 index 0000000..9f59c54 --- /dev/null +++ b/info.json @@ -0,0 +1,39 @@ +{ + "name": { + "id": 1000500000, + "internal": "Navigation", + "external": "OMS Navigation" + }, + "version": "1.0.0", + "requirements": { + "phpOMS": "1.0.0", + "phpOMS-db": "1.0.0" + }, + "creator": { + "name": "Orange Management", + "website": "www.spl1nes.com" + }, + "description": "The navigation module.", + "directory": "Navigation", + "dependencies": { + "Admin" : "1.0.0" + }, + "providing": { + "Navigation": "*" + }, + "load": [ + { + "pid": [ + "754a08ddf8bcb1cf22f310f09206dd783d42f7dd", + "40a630e157504605e40ba241f6b1f78ab1dd97b9" + ], + "type": 4, + "for": "Content", + "file": "Navigation", + "from": "Admin" + } + ], + "lang": false, + "js": true, + "css": false +}