meta/old/Meta/Controller/Section.php

79 lines
1.5 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
*/
// --------------------------------------------------------------------------
namespace Meta\Controller;
/**
* Section Controller
*
* @package meta
*/
class Section extends \Meta\Base\Controller {
2012-07-12 10:31:08 -04:00
/**
* Default controller method
*/
2015-06-04 14:30:42 -04:00
public function detail($id=0)
2012-07-12 10:31:08 -04:00
{
2012-08-31 16:18:23 -04:00
if ($id === 0)
{
$id = (int) miniMVC\get_last_segment();
}
$data = array(
2012-09-12 10:36:43 -04:00
'section' => $this->data_model->get_section_by_id($id),
'sdata' => $this->data_model->get_data($id),
'p' => $this->data_model->get_path_by_section($id),
2012-08-31 16:18:23 -04:00
'section_id' => $id
);
2015-06-04 16:25:47 -04:00
if (empty($data['section']))
{
$this->page->render_message('error', "Section doesn't exist.");
return;
}
2015-06-04 14:30:42 -04:00
$this->render('section_detail', $data);
2012-07-12 10:31:08 -04:00
}
/**
2012-09-05 11:46:51 -04:00
* Adds a data item to the current section
2012-07-12 10:31:08 -04:00
*/
2012-09-05 11:46:51 -04:00
public function add_data()
{
2012-09-05 11:46:51 -04:00
$section_id = (int) $_POST['section_id'];
2012-09-05 11:46:51 -04:00
$keys = filter_var_array($_POST['name'], FILTER_SANITIZE_STRING);
// Raw to allow use of HTML formatting
// Prepared statements keep the database safe here.
$vals = $_POST['val'];
2012-09-05 11:46:51 -04:00
$data = array_combine($keys, $vals);
2012-09-12 10:36:43 -04:00
$res = $this->data_model->add_data($section_id, $data);
2012-09-05 11:46:51 -04:00
($res)
? $this->page->set_message('success', 'Added data')
: $this->page->set_message('error', 'Data already exists');
2015-06-04 14:30:42 -04:00
$this->detail($section_id);
}
}
// End of section.php