71 lines
No EOL
1.7 KiB
PHP
71 lines
No EOL
1.7 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;
|
|
}
|
|
}
|
|
|
|
?>
|