Синхронизировал частично с CMS2
This commit is contained in:
parent
6b412f5d6f
commit
f2938b1353
30 changed files with 1447 additions and 1099 deletions
|
|
@ -1,423 +1,339 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package Core
|
||||
*/
|
||||
/**
|
||||
* Переименовать контроллер !! (StubController, CrudController, PageController, BaseController) ModelController
|
||||
* Возможно нужен еще класс с мета действиями как для actionIndex <= metaActionIndex либо с классам для этих действий
|
||||
* Есть класс для управлениями действиями а есть сами действия в виде классов или функций !!
|
||||
*/
|
||||
class Controller_Model extends Controller_Action
|
||||
|
||||
require_once __DIR__ . '/../functions.php';
|
||||
|
||||
|
||||
function forceUrl($name)
|
||||
{
|
||||
public $schema = array();
|
||||
public $schemaSearch = array();
|
||||
if (is_callable($name)) {
|
||||
return call_user_func($name);
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: Лучше $this->table->setHeader
|
||||
*/
|
||||
public $tableSchema = null;
|
||||
public $formSchema = array();
|
||||
/**
|
||||
* Контроллер страниц
|
||||
*/
|
||||
class Controller_Action
|
||||
{
|
||||
|
||||
public $menu;
|
||||
const TEMPLATE_EXTENSION = ".html"; // Расширение для шаблонов
|
||||
const ACTION_PREFIX = "action"; // Префикс для функций действий
|
||||
|
||||
public $jsPath; // Глобальный путь к скриптам
|
||||
public $themePath; // Глобальный путь к текущей теме
|
||||
|
||||
// Параметры устанавливаются при создании контроллера
|
||||
public $name; // Имя модуля
|
||||
public $viewPath = null; // Путь к шаблонам контроллера
|
||||
public $db; // Соединение с базой данных
|
||||
|
||||
// Фильтры
|
||||
public $access = null; // Обьект хранит параметры доступа
|
||||
public $logger = null; // Обьект для ведения лога
|
||||
|
||||
private $factory = null; // Ссылка на обьект создания модели
|
||||
private $helpers = array(); // Помошники для действий
|
||||
public $param = array(); // Параметры для ссылки
|
||||
|
||||
public /*.Registry.*/$_registry; // Ссылка на реестр
|
||||
public $_shortcut;
|
||||
public $modulePrefix = '';
|
||||
public $iconPath = '';
|
||||
public $path;
|
||||
public $table;
|
||||
|
||||
public function __construct()
|
||||
public function __construct ()
|
||||
{
|
||||
$this->path = new PathMenu();
|
||||
$this->menu = new PageMenu();
|
||||
$this->table = new ListTable();
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
function setUp()
|
||||
public function setUp ()
|
||||
{
|
||||
$this->table->addMenuItem($this->aUrl('delete'), 'удалить', false, 'all', 'warning');
|
||||
//$this->table->addMenuItem($this->nUrl('form'), 'редактировать', 'edit-24.png');
|
||||
// override this
|
||||
}
|
||||
|
||||
function saveParameters($args, $list)
|
||||
{
|
||||
foreach ($list as $item) {
|
||||
$args->session()->set(array($this, $item), $args->get($item));
|
||||
}
|
||||
}
|
||||
|
||||
protected function getJSONList(/*Mapper*/ $model, Collection $request)
|
||||
{
|
||||
$result = array();
|
||||
$this->saveParameters($request, array('size','page','desc', 'key'));
|
||||
|
||||
$result['list'] = $model->findAll($request, $request->get('ref'));
|
||||
$result['size'] = $model->getCount($request, $request->get('ref'));
|
||||
return json::encode($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаление сторк из таблицы
|
||||
*/
|
||||
public function actionDelete(HttpRequest $request)
|
||||
{
|
||||
$model = $this->getModel($this->useModel);
|
||||
// Почему table_item ???
|
||||
$list = ($request->get('table_item')) ? $request->get('table_item'): $request->get('id');
|
||||
$model->deleteList($list);
|
||||
|
||||
return $this->getJSONList($model, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ответ на запрос по поиску
|
||||
*/
|
||||
public function actionSearch(HttpRequest $request)
|
||||
{
|
||||
$model = $this->getModel($this->useModel);
|
||||
$model->addFilter($model->requestToSQL($request, $this->formSchema));
|
||||
|
||||
return $this->getJSONList($model, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Список элементов
|
||||
*/
|
||||
public function actionList(HttpRequest $request)
|
||||
{
|
||||
$model = $this->getModel($this->useModel);
|
||||
return $this->getJSONList($model, $request);
|
||||
}
|
||||
|
||||
|
||||
private function setFormSchema()
|
||||
{
|
||||
require_once 'core/mapper/uimapper.php';
|
||||
|
||||
$model = $this->getModel($this->useModel);
|
||||
$ui = new UIMapper($model);
|
||||
|
||||
$this->formSchema = $ui->getFormSchema();
|
||||
}
|
||||
|
||||
/**
|
||||
* Сохранение формы
|
||||
*/
|
||||
function beforeSave(/*Model*/ $item, Collection $request)
|
||||
{
|
||||
if (empty($this->formSchema)) {
|
||||
$this->setFormSchema();
|
||||
}
|
||||
// Сделать отображение Формы в обьект и обратно <-- Убрать в beforeSave
|
||||
foreach ($this->formSchema as $key => $conv) {
|
||||
list($value, $type) = $conv;
|
||||
$item->$value = call_user_func(array('Cast', 'to_' . $type), $request->get($key)); // Здесть нужно преобразовывать тип значения
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновление формы
|
||||
*/
|
||||
function formUpdate(TForm $form, Collection $request)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Загрузка формы
|
||||
*/
|
||||
function beforeLoad(/*Model*/ $item, TForm $form)
|
||||
{
|
||||
if (empty($this->formSchema)) {
|
||||
$this->setFormSchema();
|
||||
}
|
||||
// Вставка значений из данных в форму
|
||||
// Отображение обьекта в поля формы
|
||||
$form->fill($item, $this->formSchema);
|
||||
}
|
||||
|
||||
// Проверка ввода
|
||||
protected function validate($validator, $request)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Действие для проверки формы
|
||||
*/
|
||||
public function actionValidate($request)
|
||||
{
|
||||
require_once "core/validator/validator.php";
|
||||
$validator = new Validator();
|
||||
$validator->addRuleList($this->schema);
|
||||
|
||||
// Действия до проверки формы
|
||||
$this->validate($validator, $request); // <--|
|
||||
$validator->validate($request); // --|
|
||||
// Проверка формы
|
||||
if (!$validator->isValid()) {
|
||||
return json::encode($validator->getErrorMsg());
|
||||
}
|
||||
return json::encode(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Инициализация формы
|
||||
*/
|
||||
protected function formSetup($form, $id = null, $ref = null)
|
||||
{
|
||||
if (empty($this->schema)) {
|
||||
$model = $this->getModel($this->useModel);
|
||||
$ui = new UIMapper($model);
|
||||
$schema = $ui->getEditSchema();
|
||||
|
||||
$form->addFieldList($schema);
|
||||
public function loadConfig($name) {
|
||||
$filename = Shortcut::getUrl('config', $name);
|
||||
if (file_exists($filename)) {
|
||||
include($filename);
|
||||
} else {
|
||||
$form->addFieldList($this->schema);
|
||||
throw new Exception('Невозможно загрузить файл настроек ' . $name);
|
||||
}
|
||||
return $settings;
|
||||
}
|
||||
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
public function installPath($name)
|
||||
{
|
||||
return Path::join(CMS_PATH, "modules", $name, "install");
|
||||
}
|
||||
|
||||
public function addSuggest($view, $name)
|
||||
{
|
||||
$suggest = array();
|
||||
$file = Path::join($this->viewPath, 'help', $name . '.suggest');
|
||||
if (file_exists($file) && include($file)) {
|
||||
$view->addScriptRaw("add_suggest(".json::encode($suggest).");\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавление пользователя
|
||||
*/
|
||||
public function actionAdd(HttpRequest $request)
|
||||
function findIcon($icon, $size)
|
||||
{
|
||||
require_once "core/validator/validator.php";
|
||||
// {{{ тоже может быть один ref или несколько
|
||||
$ref = $request->get('ref');
|
||||
$this->addParameter('ref', $ref); // Добавляет параметр в url
|
||||
/// }}}
|
||||
|
||||
if ($this->checkPageId($request, $request->get('page'))) {
|
||||
// Проверка
|
||||
$validator = new Validator();
|
||||
$validator->addRuleList($this->schema);
|
||||
return Path::join($this->iconPath, $size . 'x' . $size, $icon . '.png');
|
||||
}
|
||||
|
||||
// Действия до проверки формы
|
||||
$this->validate($validator, $request); // <--|
|
||||
$validator->validate($request); // --|
|
||||
// Проверка формы
|
||||
if (!$validator->isValid()) {
|
||||
$request->setAction('form');
|
||||
$this->getActionPath($request);
|
||||
|
||||
$form = new TForm();
|
||||
$this->formSetup($form, $request->get('id'), $request->get('ref')); // Инициализация формы
|
||||
|
||||
$form->setValues($request); // <-- Убрать в formUpdate
|
||||
$this->formUpdate($form, $request);
|
||||
|
||||
$form->setError($validator); // Установка ошибок для формы
|
||||
|
||||
$tpl = $this->formPage($form, $request);
|
||||
$id = $request->get('id');
|
||||
if ($id) { // Редактирование
|
||||
$tpl->action = forceUrl($this->nUrl('add', array('id' => $id, 'page' => $this->getPageId($request)))); // action Совйство формы
|
||||
}
|
||||
return $tpl /*->execute()*/;
|
||||
}
|
||||
|
||||
// Нужен тест для формы
|
||||
$model = $this->getModel($this->useModel);
|
||||
$className = $model->className;
|
||||
$item = new $className();
|
||||
|
||||
// Сохраняем значение в базе данных
|
||||
$item->id = $request->get('id');
|
||||
// Если таблица связана с другой таблицей
|
||||
if ($request->get('ref') && $model->reference[1]) {
|
||||
$ref_id = $model->reference[1];
|
||||
$item->$ref_id = $request->get('ref');
|
||||
}
|
||||
|
||||
// Подготовка к сохранению
|
||||
$this->beforeSave($item, $request); // Сюдаже и истрия переходов
|
||||
// nextId ??? или выход или новая форма для создания новости
|
||||
$model->saveDB($item, $request);
|
||||
}
|
||||
|
||||
// Для страницы со списком id -> идентефикатор родительской таблицы !!??
|
||||
// $request->set('id', $request->get('ref'));
|
||||
if ($request->get('apply')) {
|
||||
$request->setAction('form');
|
||||
return $this->forward('actionForm', $request);
|
||||
}
|
||||
return $this->forward('actionIndex', $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Заголовок
|
||||
* Создает представление
|
||||
* @param string $file
|
||||
* @return template
|
||||
*/
|
||||
private function setTitlePath($ref)
|
||||
public function getView($name)
|
||||
{
|
||||
if ($ref) {
|
||||
$model = $this->getModel($this->useModel);
|
||||
if (is_array($model->reference) && $model->reference[0]) {
|
||||
$refmodel = $this->getModel($model->reference[0]);
|
||||
try {
|
||||
$parent = $refmodel->findById($ref);
|
||||
$this->path->addTitle($parent->getTitle()); // Заголовок к подписям путей
|
||||
} catch (Exception $e) {
|
||||
// Не найден заголовок потому что неправильно определен родительский элемент
|
||||
}
|
||||
}
|
||||
$file = $name . self::TEMPLATE_EXTENSION;
|
||||
// Список возможных директорий для поиска файла шаблона
|
||||
$theme = $this->_registry->readKey(array('system', 'theme'));
|
||||
$icon_theme = $this->_registry->readKey(array('system', 'icon_theme'));
|
||||
$list = array(
|
||||
Path::join($this->viewPath, TEMPLATES) => Path::join(WWW_PATH, "modules", $this->name, TEMPLATES),
|
||||
PHPTAL_TEMPLATE_REPOSITORY => "");
|
||||
|
||||
|
||||
// Поиск файла для шаблона
|
||||
foreach($list as $ospath => $path) {
|
||||
$template = Path::join($ospath, $file);
|
||||
if(file_exists($template)) { break; }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Форма для редактирования
|
||||
*/
|
||||
public function actionForm(HttpRequest $request)
|
||||
{
|
||||
$this->getActionPath($request);
|
||||
$ref = $request->get('ref');
|
||||
$this->addParameter('ref', $ref); // Добавляет параметр в url
|
||||
$this->setTitlePath($ref);
|
||||
|
||||
$model = $this->getModel($this->useModel);
|
||||
$form = new TForm(); // Показываем форму
|
||||
$form->header = 'Редактирование записи';
|
||||
$this->formSetup($form, $request->get('id'), $request->get('ref')); // Инициализация формы
|
||||
$tpl = new View_Composite($template);
|
||||
$tpl->icons = $this->iconPath; // Путь к файлам текущей темы
|
||||
$tpl->media = $this->themePath; // Путь к файлам текущей темы
|
||||
$tpl->script = $this->jsPath; // Путь к файлам скриптов
|
||||
$tpl->template = $path; // Путь к файлам текущего шаблона
|
||||
$tpl->setAlias(array(
|
||||
'${icons}' => $this->iconPath,
|
||||
'${media}' => $this->themePath,
|
||||
'${script}' => $this->jsPath,
|
||||
'${template}' => $path));
|
||||
|
||||
$list = $request->get('table_item');
|
||||
$id = ($list[0]) ? $list[0] : $request->get('id');
|
||||
$tpl->loadImports(Path::skipExtension($template) . ".import");
|
||||
|
||||
$tpl = $this->formPage ($form, $request);
|
||||
if ($id) { // Редактирование
|
||||
$form->action = forceUrl($this->nUrl('add', array('id' => $id, 'page' => $this->getPageId($request)))); // action Свойство формы
|
||||
$item = $model->findById($id);
|
||||
// Загрузка формы
|
||||
$this->beforeLoad($item, $form);
|
||||
///
|
||||
}
|
||||
$this->addSuggest($tpl, $name);
|
||||
return $tpl;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
function tableSetup($table, $id = null, $ref = null)
|
||||
public function getModel($name)
|
||||
{
|
||||
// FIXME: После замены везде $tableSchema -> table->setHeader удалить!
|
||||
if ($this->tableSchema) {
|
||||
$table->setHeader($this->tableSchema);
|
||||
} else {
|
||||
// Настройка таблицы отображения по схеме данных
|
||||
require_once 'core/mapper/uimapper.php';
|
||||
$model = $this->getModel($this->useModel);
|
||||
$ui = new UIMapper($model);
|
||||
$schema = $ui->getTableSchema();
|
||||
$schema[0]['action'] = $table->getFirstItem();
|
||||
|
||||
$table->setHeader($schema);
|
||||
if (!$this->factory) {
|
||||
$this->factory = new ModelFactory($this->db, $this->_registry, $this->_shortcut);
|
||||
}
|
||||
return $this->factory->getModel($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Выбор действия
|
||||
* Т.к действия являются методами класса то
|
||||
* 1. Можно переопределить действия
|
||||
* 2. Использовать наследование чтобы добавить к старому обработчику новое поведение
|
||||
* @param $request Обьект запроса
|
||||
*/
|
||||
public function actionIndex(HttpRequest $request)
|
||||
public function execute1(HTTPRequest $request)
|
||||
{
|
||||
$this->getActionPath($request, 'index');
|
||||
// Такое мета действие наверное можно вынести в отдельный класс
|
||||
return $this->metaActionIndex($request, array($this, 'tableSetup'), $this->aUrl('list'));
|
||||
$action = self::ACTION_PREFIX . ucfirst($request->getAction());
|
||||
if (method_exists($this, $action)) {
|
||||
return $this->forward($action, $request);
|
||||
} else {
|
||||
return $this->forward("actionIndex", $request);
|
||||
}
|
||||
}
|
||||
|
||||
public function execute(HTTPRequest $request)
|
||||
{
|
||||
$result = $this->execute1($request);
|
||||
if ($result) {
|
||||
$this->view = $result;
|
||||
}
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
public function forward($action, HTTPRequest $args)
|
||||
{
|
||||
// Действия до вызова основного обработчика
|
||||
/*foreach($this->_aspect as $aspect) {
|
||||
if (isset($aspect->before[$action])) {
|
||||
call_user_func ($aspect->before[$action], $action, $args);
|
||||
}
|
||||
}*/
|
||||
return call_user_func(array($this, $action), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Страница по умолчанию
|
||||
*/
|
||||
public function metaActionIndex(HttpRequest $request, $setup, $list)
|
||||
public function actionIndex(HttpRequest $request)
|
||||
{
|
||||
// может быть одно ref или несколько
|
||||
// {{{ история переходов
|
||||
$ref = null;
|
||||
if ($request->get('ref')) {
|
||||
$ref = $request->get('ref');
|
||||
} else if ($request->session()->get('ref')) {
|
||||
$ref = $request->session()->get('ref');
|
||||
return "";
|
||||
}
|
||||
|
||||
public function postUrl($name, $param)
|
||||
{
|
||||
return "?" . http_build_query(
|
||||
array_merge(array('module' => strtolower(get_class($this)), "action" => $name),
|
||||
$this->param, $param));
|
||||
}
|
||||
|
||||
/**
|
||||
* Генерация ссылки c учетом прав пользователя на ссылки
|
||||
*
|
||||
* @parma string $name Действие
|
||||
* @parma string $param Дополнительные параметры
|
||||
*/
|
||||
public function nUrl($name, array $param = array())
|
||||
{
|
||||
if (!$this->access || $this->access->checkAction($name)) {
|
||||
return lcurry(array($this, 'postUrl'), $name, $param);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
$request->session->set('ref', $ref);
|
||||
$this->addParameter('ref', $ref);
|
||||
// }}}
|
||||
$this->setTitlePath($ref);
|
||||
|
||||
$tpl = $this->getView('list');
|
||||
|
||||
// Помошники действий
|
||||
$this->callHelpers($request);
|
||||
// Таблица
|
||||
if ($request->session()->get(strtolower(get_class($this)))) {
|
||||
$session = $request->session()->get(strtolower(get_class($this)));
|
||||
if (isset($session['view'])) {
|
||||
$this->table->setView($session['view']);
|
||||
}
|
||||
$this->table->setData('state', array(
|
||||
'page' => $session['page'],
|
||||
'size' => $session['size'],
|
||||
'desc' => $session['desc']));
|
||||
|
||||
$this->table->setData('sorter', $session['key']);
|
||||
if (isset($session['desc'])) {
|
||||
$this->table->setData('desc', $session['desc']);
|
||||
}
|
||||
}
|
||||
|
||||
call_user_func($setup, $this->table, $request->get('id'), $ref);// --> Эквивалент formSetup
|
||||
$this->table->setAction($list);
|
||||
//
|
||||
$tpl->menu_path = $this->path->getItems();
|
||||
|
||||
// Поиск
|
||||
$search = new SearchDialog();
|
||||
$search->setTitle('Поиск');
|
||||
$search->setAction($this->aUrl('search'));
|
||||
$search->setFriend($this->table);
|
||||
$search->addFields($this->schemaSearch);
|
||||
|
||||
// Настройки
|
||||
$setup = new SetupDialog();
|
||||
$setup->setTitle('Настройки');
|
||||
$setup->setAction($this->nUrl('setup'));
|
||||
$setup->setFriend($this->table);
|
||||
|
||||
// Меню
|
||||
$this->menu->addMenuItem('?menu=toggle&id=' . $search->getName(), 'поиск', 'actions/system-search'); // Стандартный размер для иконок 22-24px
|
||||
$this->menu->addMenuItem('?menu=toggle&id=' . $setup->getName(), 'настройки', 'categories/applications-system');
|
||||
// Добавление компонентов
|
||||
$this->addChild('menu', $this->menu);
|
||||
$this->addChild('search', $search);
|
||||
$this->addChild('setup', $setup);
|
||||
$this->addChild('table', $this->table);
|
||||
//
|
||||
return $tpl;
|
||||
public function fUrl($name, array $param = array())
|
||||
{
|
||||
return forceUrl($this->nUrl($name, $param));
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет параметр для всех ссылок создаваемых функцией nUrl, aUrl
|
||||
*/
|
||||
public function actionSetup($request)
|
||||
public function addParameter($name, $value)
|
||||
{
|
||||
$left = explode(",", $request->get('left'));
|
||||
$right = explode(",", $request->get('right'));
|
||||
|
||||
$$request->session()->set(strtolower(get_class($this)),
|
||||
array('view' => array('left' => $left, 'right' => $right)));
|
||||
|
||||
return $this->forward('actionIndex', $request);
|
||||
if ($value) {
|
||||
$this->param [$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Генерация ссылки на действие контроллера
|
||||
* Ajax определяется автоматически mode = ajax используется для смены layout
|
||||
*/
|
||||
private function formPage($form, $request)
|
||||
public function aUrl($name, array $param = array())
|
||||
{
|
||||
$view = $this->getView('form');
|
||||
$view->setView('form', $form);
|
||||
$view->action = forceUrl($this->nUrl('add', array('page' => $this->getPageId($request)))); // Действие для формы
|
||||
|
||||
$view->menu_path = $this->path->getItems();
|
||||
$view->back = $this->path->getPrev();
|
||||
return $view;
|
||||
return $this->nUrl($name, array_merge(array('mode' => 'ajax'), $param)); // FIXME
|
||||
}
|
||||
|
||||
// Тоже убрать в метод Controller_Model
|
||||
function getActionPath(HttpRequest $request/*, $action = false*/)
|
||||
/**
|
||||
* Добавление помошника контроллера
|
||||
*/
|
||||
public function addHelper($class)
|
||||
{
|
||||
require_once 'state.php';
|
||||
$this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction());
|
||||
}
|
||||
$this->helpers [] = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Вызов помошников контроллера
|
||||
*/
|
||||
public function callHelpers(HttpRequest $request)
|
||||
{
|
||||
$action = self::ACTION_PREFIX . $request->getAction();
|
||||
foreach ($this->helpers as $helper) {
|
||||
if (method_exists($helper, $action)) {
|
||||
return call_user_func(array($helper, $action), $request, $this);
|
||||
} else {
|
||||
return $helper->actionIndex($request, $this); // Вместо return response ???
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Загрузка файла класса
|
||||
*/
|
||||
public function loadClass($path, $setup = null)
|
||||
{
|
||||
if (file_exists($path)) {
|
||||
require_once ($path);
|
||||
$class = pathinfo($path, PATHINFO_FILENAME);
|
||||
return new $class($setup);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function loadSettings($path)
|
||||
{
|
||||
$result = new Settings($path);
|
||||
$result->read();
|
||||
return $result->export();
|
||||
}
|
||||
|
||||
// Для Widgets
|
||||
public $view = null;
|
||||
public $childNodes = array();
|
||||
public $childViews = array();
|
||||
|
||||
public function setView($name)
|
||||
{
|
||||
$this->view = $this->getView($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка заголовка для отображения
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->view->setTitle($title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавление widget к отображению
|
||||
*/
|
||||
public function addChild(/*Widget*/ $section, $node)
|
||||
{
|
||||
$this->childNodes[$section] = $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавление дочернего отображения к текущему отображению
|
||||
*/
|
||||
public function addView(/*CompositeView*/ $section, $node)
|
||||
{
|
||||
$this->childViews[$section] = $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Генерация содержания
|
||||
* Путаница c execute и render
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
foreach ($this->childNodes as $name => $node) {
|
||||
$node->make($this);
|
||||
$this->view->setView($name, $node->view);
|
||||
}
|
||||
foreach ($this->childViews as $name => $node) {
|
||||
$this->view->setView($name, $node);
|
||||
}
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
function getPageId($request)
|
||||
{
|
||||
$pageId = time();
|
||||
$request->session()->set('page', $pageId);
|
||||
return $pageId;
|
||||
}
|
||||
|
||||
function checkPageId($request, $page)
|
||||
{
|
||||
$_page = $request->session()->get('page');
|
||||
$result = ($_page && $_page == $page);
|
||||
$request->session()->clean('page');
|
||||
return $result;
|
||||
}
|
||||
|
||||
function redirect($action) {
|
||||
header('location: ' . $this->fUrl($action));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue