mirror of
https://github.com/Karaka-Management/oms-Navigation.git
synced 2026-01-25 22:58: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\DatabaseType;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
use phpOMS\Module\InfoManager;
|
||||
use phpOMS\Module\InstallerAbstract;
|
||||
use Modules\Navigation\Models\NavElement;
|
||||
use Modules\Navigation\Models\NavElementMapper;
|
||||
|
||||
/**
|
||||
* Navigation class.
|
||||
* Installer class.
|
||||
*
|
||||
* @package Modules\Navigation\Admin
|
||||
* @license OMS License 1.0
|
||||
|
|
@ -30,38 +33,6 @@ use phpOMS\Module\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.
|
||||
*
|
||||
|
|
@ -97,32 +68,27 @@ class Installer extends InstallerAbstract
|
|||
*/
|
||||
private static function installLink($dbPool, $data) : void
|
||||
{
|
||||
$sth = $dbPool->get()->con->prepare(
|
||||
'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);'
|
||||
);
|
||||
$navElement = new NavElement();
|
||||
|
||||
$sth->bindValue(':id', $data['id'] ?? 0, \PDO::PARAM_INT);
|
||||
$sth->bindValue(':pid', sha1(\str_replace('/', '', $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_STR);
|
||||
$sth->bindValue(':order', $data['order'] ?? 1, \PDO::PARAM_INT);
|
||||
$sth->bindValue(':parent', $data['parent'], \PDO::PARAM_INT);
|
||||
$sth->bindValue(':perm_perm', $data['permission']['permission'] ?? null, \PDO::PARAM_INT);
|
||||
$sth->bindValue(':perm_type', $data['permission']['type'] ?? null, \PDO::PARAM_INT);
|
||||
$sth->bindValue(':perm_element', $data['permission']['element'] ?? null, \PDO::PARAM_INT);
|
||||
$navElement->id = (int) ($data['id'] ?? 0);
|
||||
$navElement->pid = (string) (\sha1(\str_replace('/', '', $data['pid'] ?? '')));
|
||||
$navElement->name = (string) ($data['name'] ?? '');
|
||||
$navElement->type = (int) ($data['type'] ?? 1);
|
||||
$navElement->subtype = (int) ($data['subtype'] ?? 2);
|
||||
$navElement->icon = $data['icon'] ?? null;
|
||||
$navElement->uri = $data['uri'] ?? null;
|
||||
$navElement->target = (string) ($data['target'] ?? 'self');
|
||||
$navElement->from = (string) ($data['from'] ?? '0');
|
||||
$navElement->order = (int) ($data['order'] ?? 1);
|
||||
$navElement->parent = (int) ($data['parent'] ?? 0);
|
||||
$navElement->permissionPerm = $data['permission']['permission'] ?? null;
|
||||
$navElement->permissionType = $data['permission']['type'] ?? null;
|
||||
$navElement->permissionElement = $data['permission']['element'] ?? null;
|
||||
|
||||
$sth->execute();
|
||||
|
||||
$lastInsertID = $dbPool->get()->con->lastInsertId();
|
||||
$lastInsertID = NavElementMapper::create($navElement, RelationType::ALL, true);
|
||||
|
||||
foreach ($data['children'] as $link) {
|
||||
$parent = ($link['parent'] == null ? $lastInsertID : $link['parent']);
|
||||
$parent = ($link['parent'] === null ? $lastInsertID : $link['parent']);
|
||||
self::installLink($dbPool, $link);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user