diff --git a/admin/controllers/Handbook.php b/admin/controllers/Handbook.php new file mode 100644 index 00000000..1755d1a3 --- /dev/null +++ b/admin/controllers/Handbook.php @@ -0,0 +1,23 @@ +rsegment(3); + + $oPage = $oModel->getById($iPageId); + if (empty($oPage)) { + show404(); + } + + // @todo (Pablo - 2018-11-07) - Get immediate children + // @todo (Pablo - 2018-11-07) - Get previous page + // @todo (Pablo - 2018-11-07) - Get next page + + Factory::service('View') + ->setData([ + 'oPage' => $oPage, + ]) + ->load([ + 'structure/header', + 'admin/HandbookFrontEnd/render', + 'structure/footer', + ]); + } + + // -------------------------------------------------------------------------- + + public function search() + { + // @todo (Pablo - 2018-11-07) - Search pages + } +} diff --git a/admin/views/HandbookFrontEnd/render.php b/admin/views/HandbookFrontEnd/render.php new file mode 100644 index 00000000..697f39b1 --- /dev/null +++ b/admin/views/HandbookFrontEnd/render.php @@ -0,0 +1 @@ + function (): Model\Handbook { + if (class_exists('\App\Admin\Model\Handbook')) { + return new \App\Admin\Model\Handbook(); + } else { + return new \Nails\Admin\Model\Handbook(); + } + }, 'Help' => function (): Model\Help { if (class_exists('\App\Admin\Model\Help')) { return new \App\Admin\Model\Help(); diff --git a/src/Api/Controller/Handbook.php b/src/Api/Controller/Handbook.php new file mode 100644 index 00000000..e8544a13 --- /dev/null +++ b/src/Api/Controller/Handbook.php @@ -0,0 +1,22 @@ +query(" + CREATE TABLE `{{NAILS_DB_PREFIX}}admin_handbook` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `slug` varchar(150) DEFAULT NULL, + `parent_id` int(11) unsigned DEFAULT NULL, + `label` varchar(150) DEFAULT NULL, + `body` text, + `order` int(11) DEFAULT '0', + `breadcrumbs` text, + `is_deleted` tinyint(1) DEFAULT '0', + `created` datetime NOT NULL, + `created_by` int(10) unsigned DEFAULT NULL, + `modified` datetime NOT NULL, + `modified_by` int(11) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `created_by` (`created_by`), + KEY `modified_by` (`modified_by`), + KEY `parent_id` (`parent_id`), + CONSTRAINT `{{NAILS_DB_PREFIX}}admin_handbook_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `{{NAILS_DB_PREFIX}}user` (`id`) ON DELETE SET NULL, + CONSTRAINT `{{NAILS_DB_PREFIX}}admin_handbook_ibfk_2` FOREIGN KEY (`modified_by`) REFERENCES `{{NAILS_DB_PREFIX}}user` (`id`) ON DELETE SET NULL, + CONSTRAINT `{{NAILS_DB_PREFIX}}admin_handbook_ibfk_3` FOREIGN KEY (`parent_id`) REFERENCES `{{NAILS_DB_PREFIX}}admin_handbook` (`id`) ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 + "); + } +} diff --git a/src/Model/Handbook.php b/src/Model/Handbook.php new file mode 100644 index 00000000..c4e8aef3 --- /dev/null +++ b/src/Model/Handbook.php @@ -0,0 +1,67 @@ +table = NAILS_DB_PREFIX . 'admin_handbook'; + $this->tableAutoSetSlugs = true; + $this->destructiveDelete = false; + } + + // -------------------------------------------------------------------------- + + public function describeFields($sTable = null) + { + $aFields = parent::describeFields($sTable); + + $aFields['label']->validation[] = 'required'; + $aFields['body']->type = 'cms_widgets'; + + $aFields['parent_id']->label = 'Parent'; + $aFields['parent_id']->class = 'js-searcher'; + $aFields['parent_id']->data = [ + 'api' => 'admin/handbook', + ]; + + return $aFields; + } + + // -------------------------------------------------------------------------- + + protected function formatObject( + &$oObj, + array $aData = [], + array $aIntegers = [], + array $aBools = [], + array $aFloats = [] + ) { + parent::formatObject($oObj, $aData, $aIntegers, $aBools, $aFloats); + $oObj->url = site_url($this->generateUrl($oObj)); + } +} diff --git a/src/Routes.php b/src/Routes.php index fa9e98df..9d2c4ba6 100644 --- a/src/Routes.php +++ b/src/Routes.php @@ -13,17 +13,27 @@ namespace Nails\Admin; use Nails\Common\Interfaces\RouteGenerator; +use Nails\Factory; class Routes implements RouteGenerator { /** * Returns an array of routes for this module + * * @return array */ public static function generate() { - return [ + $aRoutes = [ 'admin(/(.+))?' => 'admin/adminRouter/index$1', ]; + + $oHandbookModel = Factory::model('Handbook', 'nails/module-admin'); + $aHandbookPages = $oHandbookModel->getAll(); + foreach ($aHandbookPages as $oPage) { + $aRoutes[$oHandbookModel->generateUrl($oPage)] = 'admin/handbookFrontEnd/render/' . $oPage->id; + } + + return $aRoutes; } }