Reconfigure base framework, add outline , finish section functionality

This commit is contained in:
Timothy Warren 2012-08-23 01:28:54 +00:00
parent 9b06f58638
commit 844d37ad58
15 changed files with 239 additions and 19 deletions

View File

@ -28,7 +28,8 @@ abstract class Controller extends \miniMVC\Controller {
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->load_model('meta\Model'); $this->load_model('meta\model');
$this->load_model('meta\user_model');
$this->page->build_header(); $this->page->build_header();
} }

View File

@ -107,7 +107,7 @@ define('DEFAULT_TITLE', "meta");
| Default css group | Default css group
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| Default css group | Default css group to show if none explicity chose
| |
*/ */
define('DEFAULT_CSS_GROUP', "css"); define('DEFAULT_CSS_GROUP', "css");
@ -117,9 +117,21 @@ define('DEFAULT_CSS_GROUP', "css");
| Default js group | Default js group
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| Default js group | Default js group to show if none explicitly chosen
| |
*/ */
define('DEFAULT_JS_GROUP', "js"); 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 // End of config.php

View File

@ -38,6 +38,9 @@ return array(
'category' => 'meta/category/index', 'category' => 'meta/category/index',
'category/add' => 'meta/category/add', 'category/add' => 'meta/category/add',
'category/detail' => 'meta/category/detail', 'category/detail' => 'meta/category/detail',
'section' => 'meta/section/index',
'section/add' => 'meta/section/add',
'section/detail' => 'meta/section/detail',
'404_route' => '', '404_route' => '',
); );

View File

@ -15,6 +15,8 @@
/** /**
* Section Controller * Section Controller
*
* @package meta
*/ */
class section extends meta\controller { class section extends meta\controller {
@ -26,18 +28,63 @@ class section extends meta\controller {
parent::__construct(); parent::__construct();
} }
/**
* Default controller method
*/
public function index() public function index()
{ {
$this->detail();
} }
/** /**
* Adds a new section to the current category * Adds a new category
*/ */
public function add() 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 // End of section.php

View File

@ -18,7 +18,7 @@
* *
* @package meta * @package meta
*/ */
class welcome extends \miniMVC\Controller { class welcome extends \meta\controller {
/** /**
* Initialize the constructor * Initialize the constructor
@ -28,10 +28,6 @@ class welcome extends \miniMVC\Controller {
public function __construct() public function __construct()
{ {
parent::__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() 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));
} }
} }

View File

@ -20,7 +20,7 @@ namespace meta;
* *
* @package meta * @package meta
*/ */
class Model extends \miniMVC\Model { class model extends \miniMVC\Model {
/** /**
* Reference to database connection * Reference to database connection
@ -43,7 +43,7 @@ class Model extends \miniMVC\Model {
{ {
parent::__construct(); parent::__construct();
//$this->session =& \miniMVC\Session::get_instance(); $this->session =& \miniMVC\Session::get_instance();
$this->db =& \miniMVC\db::get_instance(); $this->db =& \miniMVC\db::get_instance();
} }
@ -406,6 +406,77 @@ class Model extends \miniMVC\Model {
return $data; 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;
}
} }
// End of model.php // End of model.php

View File

@ -22,6 +22,13 @@ namespace meta;
*/ */
class user_model extends \miniMVC\Model { class user_model extends \miniMVC\Model {
/**
* Reference to database connection
*
* @var Query_Builder
*/
protected $db;
/** /**
* Reference to bcrypt object * Reference to bcrypt object
* *
@ -29,6 +36,13 @@ class user_model extends \miniMVC\Model {
*/ */
protected $bcrypt; protected $bcrypt;
/**
* Reference to session
*
* @var Session
*/
protected $session;
/** /**
* Initialize the User model * Initialize the User model
*/ */
@ -37,6 +51,22 @@ class user_model extends \miniMVC\Model {
parent::__construct(); parent::__construct();
$this->bcrypt = new \Bcrypt(15); $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)
{
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -1,4 +1,3 @@
<h1>meta</h1>
<h3><?= $category ?></h3> <h3><?= $category ?></h3>
<h4>Category Sections</h4> <h4>Category Sections</h4>

View File

@ -1,4 +1,3 @@
<h1>meta</h1>
<h3><?= $genre ?></h3> <h3><?= $genre ?></h3>
<h4>Genre Categories</h4> <h4>Genre Categories</h4>

View File

@ -1,4 +1,3 @@
<h1>Meta</h1>
<h3>Genres</h3> <h3>Genres</h3>
<ul class="list"> <ul class="list">

View File

@ -1,4 +1,3 @@
<h1>meta</h1>
<h3>Login</h3> <h3>Login</h3>
<form action="<?= miniMVC\site_url('welcome/login') ?>" method="post"> <form action="<?= miniMVC\site_url('welcome/login') ?>" method="post">

View 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>

View File

@ -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> */ ?>

View File

@ -9,3 +9,4 @@
<?= $head_js ?> <?= $head_js ?>
</head> </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>

View File

@ -133,6 +133,11 @@ class Page {
*/ */
public function __destruct() public function __destruct()
{ {
if (headers_sent())
{
die();
}
if ( ! empty($this->headers)) if ( ! empty($this->headers))
{ {
// Set headers // Set headers
@ -151,7 +156,7 @@ class Page {
if ( ! empty($this->buffer)) if ( ! empty($this->buffer))
{ {
ob_start('ob_gzhandler'); //ob_start('ob_gzhandler');
echo $this->buffer; echo $this->buffer;