Reconfigure base framework, add outline , finish section functionality
This commit is contained in:
parent
9b06f58638
commit
844d37ad58
@ -28,7 +28,8 @@ abstract class Controller extends \miniMVC\Controller {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load_model('meta\Model');
|
||||
$this->load_model('meta\model');
|
||||
$this->load_model('meta\user_model');
|
||||
$this->page->build_header();
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ define('DEFAULT_TITLE', "meta");
|
||||
| Default css group
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Default css group
|
||||
| Default css group to show if none explicity chose
|
||||
|
|
||||
*/
|
||||
define('DEFAULT_CSS_GROUP', "css");
|
||||
@ -117,9 +117,21 @@ define('DEFAULT_CSS_GROUP', "css");
|
||||
| Default js group
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Default js group
|
||||
| Default js group to show if none explicitly chosen
|
||||
|
|
||||
*/
|
||||
define('DEFAULT_JS_GROUP', "js");
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Debug backtrace
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Whether or not to show a backtrace for php errors
|
||||
|
|
||||
| Must be defined as TRUE for the backtrace to display.
|
||||
|
|
||||
*/
|
||||
define('SHOW_DEBUG_BACKTRACE', TRUE);
|
||||
|
||||
// End of config.php
|
@ -38,6 +38,9 @@ return array(
|
||||
'category' => 'meta/category/index',
|
||||
'category/add' => 'meta/category/add',
|
||||
'category/detail' => 'meta/category/detail',
|
||||
'section' => 'meta/section/index',
|
||||
'section/add' => 'meta/section/add',
|
||||
'section/detail' => 'meta/section/detail',
|
||||
'404_route' => '',
|
||||
);
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
/**
|
||||
* Section Controller
|
||||
*
|
||||
* @package meta
|
||||
*/
|
||||
class section extends meta\controller {
|
||||
|
||||
@ -26,18 +28,63 @@ class section extends meta\controller {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default controller method
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
$this->detail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new section to the current category
|
||||
* Adds a new category
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// Strip away tags for the sake of security
|
||||
$name = strip_tags($_POST['section']);
|
||||
$id = (int) $_POST['category_id'];
|
||||
|
||||
// Make sure the name doesn't already exist. If it does, show an error.
|
||||
$res = $this->model->add_section($name, $id);
|
||||
|
||||
if ($res === TRUE)
|
||||
{
|
||||
$this->page->set_message('success', 'Added new section');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->page->set_message('error', 'Section already exists for this category');
|
||||
}
|
||||
|
||||
// Render the basic page
|
||||
$this->detail(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sections / editing options for a category
|
||||
*/
|
||||
public function detail($id = 0)
|
||||
{
|
||||
if ($id === 0)
|
||||
{
|
||||
$id = (int) miniMVC\get_last_segment();
|
||||
}
|
||||
|
||||
if ($id === 0)
|
||||
{
|
||||
miniMVC\show_404();
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'section' => $this->model->get_section_by_id($id),
|
||||
'data' => $this->model->get_data($id),
|
||||
'section_id' => $id
|
||||
);
|
||||
|
||||
$this->load_view('section_detail', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// End of section.php
|
@ -18,7 +18,7 @@
|
||||
*
|
||||
* @package meta
|
||||
*/
|
||||
class welcome extends \miniMVC\Controller {
|
||||
class welcome extends \meta\controller {
|
||||
|
||||
/**
|
||||
* Initialize the constructor
|
||||
@ -28,10 +28,6 @@ class welcome extends \miniMVC\Controller {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load_model('meta\model');
|
||||
$this->load_model('meta\user_model');
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -56,7 +52,18 @@ class welcome extends \miniMVC\Controller {
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
|
||||
$this->page->render('login');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Display an outline of the data for a table of contents
|
||||
*/
|
||||
public function outline()
|
||||
{
|
||||
$outline_data = $this->model->get_outline_data();
|
||||
$this->page->render('outline', array('outline' => $outline_data));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace meta;
|
||||
*
|
||||
* @package meta
|
||||
*/
|
||||
class Model extends \miniMVC\Model {
|
||||
class model extends \miniMVC\Model {
|
||||
|
||||
/**
|
||||
* Reference to database connection
|
||||
@ -43,7 +43,7 @@ class Model extends \miniMVC\Model {
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
//$this->session =& \miniMVC\Session::get_instance();
|
||||
$this->session =& \miniMVC\Session::get_instance();
|
||||
$this->db =& \miniMVC\db::get_instance();
|
||||
}
|
||||
|
||||
@ -405,6 +405,77 @@ class Model extends \miniMVC\Model {
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get data for a full outline
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_outline_data()
|
||||
{
|
||||
// Get the genres
|
||||
$g_query = $this->db->from('genre')
|
||||
->get();
|
||||
|
||||
$genres = array();
|
||||
|
||||
while ($row = $g_query->fetch(\PDO::FETCH_ASSOC))
|
||||
{
|
||||
$genres[$row['id']] = $row['genre'];
|
||||
}
|
||||
|
||||
// Get the categories
|
||||
$c_query = $this->db->from('category')
|
||||
->get();
|
||||
|
||||
$categories = array();
|
||||
|
||||
while($row = $c_query->fetch(\PDO::FETCH_ASSOC))
|
||||
{
|
||||
$categories[$row['genre_id']][$row['id']] = $row['category'];
|
||||
}
|
||||
|
||||
// Get the sections
|
||||
$s_query = $this->db->from('section')
|
||||
->get();
|
||||
|
||||
$sections = array();
|
||||
|
||||
while($row = $s_query->fetch(\PDO::FETCH_ASSOC))
|
||||
{
|
||||
$sections[$row['category_id']][$row['id']] = $row['section'];
|
||||
}
|
||||
|
||||
|
||||
// Organize into a nested array
|
||||
foreach($genres as $genre_id => $genre)
|
||||
{
|
||||
$return[$genre_id][$genre] = array();
|
||||
$g =& $return[$genre_id][$genre];
|
||||
|
||||
// Categories for this genre
|
||||
if (isset($categories[$genre_id]))
|
||||
{
|
||||
$g = $categories[$genre_id];
|
||||
|
||||
foreach($categories[$genre_id] as $category_id => $category)
|
||||
{
|
||||
$g[$category_id] = array($category => array());
|
||||
$c =& $g[$category_id][$category];
|
||||
|
||||
// Sections for this category
|
||||
if (isset($sections[$category_id]))
|
||||
{
|
||||
$c = $sections[$category_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,12 +22,26 @@ namespace meta;
|
||||
*/
|
||||
class user_model extends \miniMVC\Model {
|
||||
|
||||
/**
|
||||
* Reference to database connection
|
||||
*
|
||||
* @var Query_Builder
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Reference to bcrypt object
|
||||
*
|
||||
* @var Bcrypt
|
||||
*/
|
||||
protected $bcrypt;
|
||||
|
||||
/**
|
||||
* Reference to session
|
||||
*
|
||||
* @var Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* Initialize the User model
|
||||
@ -37,8 +51,24 @@ class user_model extends \miniMVC\Model {
|
||||
parent::__construct();
|
||||
|
||||
$this->bcrypt = new \Bcrypt(15);
|
||||
$this->db =& \miniMVC\db::get_instance();
|
||||
$this->session =& \miniMVC\Session::get_instance();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add a user for access
|
||||
*
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
*/
|
||||
public function add_user($username, $pass1, $pass2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,3 @@
|
||||
<h1>meta</h1>
|
||||
<h3><?= $category ?></h3>
|
||||
|
||||
<h4>Category Sections</h4>
|
||||
|
@ -1,4 +1,3 @@
|
||||
<h1>meta</h1>
|
||||
<h3><?= $genre ?></h3>
|
||||
|
||||
<h4>Genre Categories</h4>
|
||||
|
@ -1,4 +1,3 @@
|
||||
<h1>Meta</h1>
|
||||
<h3>Genres</h3>
|
||||
|
||||
<ul class="list">
|
||||
|
@ -1,4 +1,3 @@
|
||||
<h1>meta</h1>
|
||||
<h3>Login</h3>
|
||||
|
||||
<form action="<?= miniMVC\site_url('welcome/login') ?>" method="post">
|
||||
|
39
app/modules/meta/views/outline.php
Normal file
39
app/modules/meta/views/outline.php
Normal file
@ -0,0 +1,39 @@
|
||||
<h3>Data Outline</h3>
|
||||
|
||||
<ul class="outline">
|
||||
<?php if (isset($outline)): ?>
|
||||
|
||||
<?php foreach($outline as $genre_id => $genre_array): ?>
|
||||
<?php foreach($genre_array as $genre => $cat_array): ?>
|
||||
<li>
|
||||
<a href="<?= \miniMVC\site_url("genre/{$genre_id}") ?>"><?= $genre ?></a>
|
||||
|
||||
<?php foreach($cat_array as $cat_id => $cname_array): ?>
|
||||
<ul>
|
||||
<?php foreach($cname_array as $category => $sect_array): ?>
|
||||
<li>
|
||||
<a href="<?= \miniMVC\site_url("category/{$cat_id}") ?>"><?= $category ?></a>
|
||||
|
||||
<?php if ( ! empty($sect_array)): ?>
|
||||
<ul>
|
||||
<?php foreach($sect_array as $section_id => $section): ?>
|
||||
<li>
|
||||
<a href="<?= \miniMVC\site_url("section/{$section_id}") ?>">
|
||||
<?= $section ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<?php endif ?>
|
||||
</ul>
|
@ -0,0 +1,8 @@
|
||||
<h3><?= $section ?></h3>
|
||||
|
||||
<h4>Section Data</h4>
|
||||
<?php /*<ul class="list">
|
||||
<?php foreach($data as $id => $d): ?>
|
||||
<li><a href="<?= miniMVC\site_url("section/detail/{$id}") ?>"><?= $section ?></a></li>
|
||||
<?php endforeach ?>
|
||||
</ul> */ ?>
|
@ -8,4 +8,5 @@
|
||||
<?= $head_tags ?>
|
||||
<?= $head_js ?>
|
||||
</head>
|
||||
<body<?= (!empty($body_class)) ? "class=\"" . $body_class . "\"" : ""; ?><?= (!empty($body_id)) ? " id=\"" . $body_id . "\"" : ""; ?>>
|
||||
<body<?= (!empty($body_class)) ? "class=\"" . $body_class . "\"" : ""; ?><?= (!empty($body_id)) ? " id=\"" . $body_id . "\"" : ""; ?>>
|
||||
<h1>Meta</h1>
|
@ -133,6 +133,11 @@ class Page {
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (headers_sent())
|
||||
{
|
||||
die();
|
||||
}
|
||||
|
||||
if ( ! empty($this->headers))
|
||||
{
|
||||
// Set headers
|
||||
@ -151,7 +156,7 @@ class Page {
|
||||
|
||||
if ( ! empty($this->buffer))
|
||||
{
|
||||
ob_start('ob_gzhandler');
|
||||
//ob_start('ob_gzhandler');
|
||||
|
||||
echo $this->buffer;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user