Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions admin/controllers/Handbook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* This class renders the admin handbook
*
* @package Nails
* @subpackage module-admin
* @category AdminController
* @author Nails Dev Team
* @link
*/

namespace Nails\Admin\Admin;

use Nails\Admin\Controller\DefaultController;

class Handbook extends DefaultController
{
const CONFIG_MODEL_NAME = 'Handbook';
const CONFIG_MODEL_PROVIDER = 'nails/module-admin';
const CONFIG_SIDEBAR_GROUP = 'Handbook';
const CONFIG_TITLE_SINGLE = 'Page';
}
52 changes: 52 additions & 0 deletions admin/controllers/HandbookFrontEnd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* This class renders the admin handbook frontend
*
* @note THIS IS NOT AN ADMIN CONTROLLER
*
* @package Nails
* @subpackage module-admin
* @category AdminController
* @author Nails Dev Team
* @link
*/

use App\Controller\Base;
use Nails\Factory;

class HandbookFrontEnd extends Base
{
public function render()
{
$oUri = Factory::service('Uri');
$oModel = Factory::model('Handbook', 'nails/module-admin');
$iPageId = $oUri->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
}
}
1 change: 1 addition & 0 deletions admin/views/HandbookFrontEnd/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php dump($oPage);
7 changes: 7 additions & 0 deletions services/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
return new Model\Export();
}
},
'Handbook' => 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();
Expand Down
22 changes: 22 additions & 0 deletions src/Api/Controller/Handbook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Admin API end points: Handbook
*
* @package Nails
* @subpackage module-admin
* @category Controller
* @author Nails Dev Team
* @link
*/

namespace Nails\Admin\Api\Controller;

use Nails\Api\Controller\CrudController;

class Handbook extends CrudController
{
const REQUIRE_AUTH = true;
const CONFIG_MODEL_NAME = 'Handbook';
const CONFIG_MODEL_PROVIDER = 'nails/module-admin';
}
50 changes: 50 additions & 0 deletions src/Database/Migration/10.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* Migration: 10
* Started: 7/11/2018
*
* @package Nails
* @subpackage module-admin
* @category Database Migration
* @author Nails Dev Team
* @link
*/

namespace Nails\Database\Migration\Nails\ModuleAdmin;

use Nails\Common\Console\Migrate\Base;

class Migration10 extends Base
{
/**
* Execute the migration
* @return Void
*/
public function execute()
{
$this->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
");
}
}
67 changes: 67 additions & 0 deletions src/Model/Handbook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/**
* Admin handbook model
*
* @package Nails
* @subpackage module-admin
* @category Model
* @author Nails Dev Team
* @link
*/

namespace Nails\Admin\Model;

use Nails\Common\Model\Base;
use Nails\Common\Traits\Model\Nestable;
use Nails\Common\Traits\Model\Sortable;

class Handbook extends Base
{
use Nestable;
use Sortable;

const NESTED_URL_NAMESPACE = 'handbook';

/**
* Handbook constructor.
*/
public function __construct()
{
parent::__construct();
$this->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));
}
}
12 changes: 11 additions & 1 deletion src/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}