mirror of
https://github.com/Karaka-Management/oms-Navigation.git
synced 2026-02-14 07:48:41 +00:00
Move schema to json
This commit is contained in:
parent
9474814d2f
commit
6eebe5a51b
|
|
@ -16,11 +16,14 @@ namespace Modules\Navigation\Admin;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\DatabasePool;
|
use phpOMS\DataStorage\Database\DatabasePool;
|
||||||
use phpOMS\DataStorage\Database\DatabaseType;
|
use phpOMS\DataStorage\Database\DatabaseType;
|
||||||
|
use phpOMS\DataStorage\Database\RelationType;
|
||||||
use phpOMS\Module\InfoManager;
|
use phpOMS\Module\InfoManager;
|
||||||
use phpOMS\Module\InstallerAbstract;
|
use phpOMS\Module\InstallerAbstract;
|
||||||
|
use Modules\Navigation\Models\NavElement;
|
||||||
|
use Modules\Navigation\Models\NavElementMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigation class.
|
* Installer class.
|
||||||
*
|
*
|
||||||
* @package Modules\Navigation\Admin
|
* @package Modules\Navigation\Admin
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
|
|
@ -30,38 +33,6 @@ use phpOMS\Module\InstallerAbstract;
|
||||||
class Installer extends InstallerAbstract
|
class Installer extends InstallerAbstract
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public static function install(DatabasePool $dbPool, InfoManager $info) : void
|
|
||||||
{
|
|
||||||
parent::install($dbPool, $info);
|
|
||||||
|
|
||||||
switch ($dbPool->get()->getType()) {
|
|
||||||
case DatabaseType::MYSQL:
|
|
||||||
$dbPool->get()->con->prepare(
|
|
||||||
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->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_permission` int(11) DEFAULT NULL,
|
|
||||||
`nav_permission_type` int(11) DEFAULT NULL,
|
|
||||||
`nav_permission_element` int(11) DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`nav_id`)
|
|
||||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8;'
|
|
||||||
)->execute();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install data from providing modules.
|
* Install data from providing modules.
|
||||||
*
|
*
|
||||||
|
|
@ -97,32 +68,27 @@ class Installer extends InstallerAbstract
|
||||||
*/
|
*/
|
||||||
private static function installLink($dbPool, $data) : void
|
private static function installLink($dbPool, $data) : void
|
||||||
{
|
{
|
||||||
$sth = $dbPool->get()->con->prepare(
|
$navElement = new NavElement();
|
||||||
'INSERT INTO `' . $dbPool->get()->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_permission`, `nav_permission_type`, `nav_permission_element`) VALUES
|
|
||||||
(:id, :pid, :name, :type, :subtype, :icon, :uri, :target, :from, :order, :parent, :perm_perm, :perm_type, :perm_element);'
|
|
||||||
);
|
|
||||||
|
|
||||||
$sth->bindValue(':id', $data['id'] ?? 0, \PDO::PARAM_INT);
|
$navElement->id = (int) ($data['id'] ?? 0);
|
||||||
$sth->bindValue(':pid', sha1(\str_replace('/', '', $data['pid'] ?? '')), \PDO::PARAM_STR);
|
$navElement->pid = (string) (\sha1(\str_replace('/', '', $data['pid'] ?? '')));
|
||||||
$sth->bindValue(':name', $data['name'] ?? '', \PDO::PARAM_STR);
|
$navElement->name = (string) ($data['name'] ?? '');
|
||||||
$sth->bindValue(':type', $data['type'] ?? 1, \PDO::PARAM_INT);
|
$navElement->type = (int) ($data['type'] ?? 1);
|
||||||
$sth->bindValue(':subtype', $data['subtype'] ?? 2, \PDO::PARAM_INT);
|
$navElement->subtype = (int) ($data['subtype'] ?? 2);
|
||||||
$sth->bindValue(':icon', $data['icon'] ?? null, \PDO::PARAM_STR);
|
$navElement->icon = $data['icon'] ?? null;
|
||||||
$sth->bindValue(':uri', $data['uri'] ?? null, \PDO::PARAM_STR);
|
$navElement->uri = $data['uri'] ?? null;
|
||||||
$sth->bindValue(':target', $data['target'] ?? "self", \PDO::PARAM_STR);
|
$navElement->target = (string) ($data['target'] ?? 'self');
|
||||||
$sth->bindValue(':from', $data['from'] ?? 0, \PDO::PARAM_STR);
|
$navElement->from = (string) ($data['from'] ?? '0');
|
||||||
$sth->bindValue(':order', $data['order'] ?? 1, \PDO::PARAM_INT);
|
$navElement->order = (int) ($data['order'] ?? 1);
|
||||||
$sth->bindValue(':parent', $data['parent'], \PDO::PARAM_INT);
|
$navElement->parent = (int) ($data['parent'] ?? 0);
|
||||||
$sth->bindValue(':perm_perm', $data['permission']['permission'] ?? null, \PDO::PARAM_INT);
|
$navElement->permissionPerm = $data['permission']['permission'] ?? null;
|
||||||
$sth->bindValue(':perm_type', $data['permission']['type'] ?? null, \PDO::PARAM_INT);
|
$navElement->permissionType = $data['permission']['type'] ?? null;
|
||||||
$sth->bindValue(':perm_element', $data['permission']['element'] ?? null, \PDO::PARAM_INT);
|
$navElement->permissionElement = $data['permission']['element'] ?? null;
|
||||||
|
|
||||||
$sth->execute();
|
$lastInsertID = NavElementMapper::create($navElement, RelationType::ALL, true);
|
||||||
|
|
||||||
$lastInsertID = $dbPool->get()->con->lastInsertId();
|
|
||||||
|
|
||||||
foreach ($data['children'] as $link) {
|
foreach ($data['children'] as $link) {
|
||||||
$parent = ($link['parent'] == null ? $lastInsertID : $link['parent']);
|
$parent = ($link['parent'] === null ? $lastInsertID : $link['parent']);
|
||||||
self::installLink($dbPool, $link);
|
self::installLink($dbPool, $link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user