meta/app/controllers/category.php

82 lines
1.6 KiB
PHP
Raw Normal View History

<?php
/**
* meta
*
* Hierarchial data tool
*
* @package meta
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/meta
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Category controller
*
* @package meta
*/
2015-06-04 15:46:30 -04:00
class category extends \miniMVC\Controller {
/**
* Initialize the Controller
*/
public function __construct()
{
parent::__construct();
}
/**
* Returns the sections / editing options for a category
*/
2015-06-04 14:30:42 -04:00
public function detail($id = 0)
{
2012-07-12 10:31:08 -04:00
if ($id === 0)
{
$id = (int) miniMVC\get_last_segment();
}
$data = array(
2012-09-12 10:36:43 -04:00
'category' => $this->data_model->get_category_by_id($id),
'sections' => $this->data_model->get_category_outline_data($id),
'genre' => $this->data_model->get_genre_by_category($id),
'category_id' => $id
);
2015-06-04 16:25:47 -04:00
if (empty($data['category']))
{
$this->page->render_message('error', "Category doesn't exist.");
return;
}
2015-06-04 14:30:42 -04:00
$this->render('category_detail', $data);
}
2012-09-05 11:46:51 -04:00
/**
* Adds a section to the current category
*/
public function add_section()
{
// 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.
2012-09-12 10:36:43 -04:00
$res = $this->data_model->add_section($name, $id);
2012-09-05 11:46:51 -04:00
if ($res === TRUE)
{
$this->page->set_message('success', 'Added new section');
}
else
{
$this->page->set_message('error', 'Section already exists for this category');
}
2015-06-04 14:30:42 -04:00
$this->detail($id);
2012-09-05 11:46:51 -04:00
}
}
// End of genre.php