phplibrary/core/widgets/listtable.php
2016-06-29 18:51:32 +03:00

71 lines
No EOL
1.6 KiB
PHP

<?php
require_once 'core/widgets/widget.php';
require_once 'core/functions.php';
/**
* Êëàññ äëÿ ãåíåðàöèè òàáëèöû
*/
class ListTable extends Widget // MenuTable
{
private $visible = null;
private $menu;
function setUp()
{
$this->menu = array();
$this->template = "table";
}
/**
* Óñòàíàâëèâàåò ôîðìàò òàáëèöû, ñòðóêòóðó $header ñì. table.js
*/
function setHeader($header)
{
$this->setData('table', $header);
}
function setView($visible)
{
$this->visible = $visible;
}
function setAction($action)
{
$this->setData('list', forceUrl($action));
}
function addMenuItem($href, $name, $to = 'item')
{
if ($href) {
if ($to === true) $to = 'all';
if (! isset($this->menu[$to])) {
$this->menu[$to] = array('group' => $to, 'all' => ($to == 'all'), 'items' => array());
}
$this->menu[$to]['items'][] = array('href' => $href, 'name' => $name);
}
}
function make(Controller $parent)
{
$view = $this->visible;
if (is_null($view)) {
$view = array('left' => key_values('key', $this->data['table']), 'right' => array());
}
$this->setData('setup', $view);
foreach ($this->menu as &$menu) {
foreach ($menu['items'] as &$item) {
$item['href'] = forceUrl($item['href']);
}
}
$this->setData('menu', array_keys($this->menu));
parent::make($parent);
$this->view->menus = $this->menu;
}
}
?>