153 lines
No EOL
3.8 KiB
PHP
153 lines
No EOL
3.8 KiB
PHP
<?php
|
||
|
||
namespace ctiso\View;
|
||
|
||
use ctiso\View\Composite;
|
||
|
||
class Top extends Composite
|
||
{
|
||
/**
|
||
* Общая строка заголовка
|
||
* @var int
|
||
*/
|
||
public $mid = 0;
|
||
/** @var array */
|
||
public $require = [];
|
||
/** @var array */
|
||
public $deps = [];
|
||
/** @var \ctiso\Registry */
|
||
public $config;
|
||
|
||
/**
|
||
* Заголовок страницы
|
||
*
|
||
* @return string
|
||
*/
|
||
public function getTitle()
|
||
{
|
||
return implode(" - ", array_filter($this->doTree('_title', false), [$this, 'isNotNull']));
|
||
}
|
||
|
||
/**
|
||
* Идентификатор
|
||
*
|
||
* @param string $pref
|
||
* @return string
|
||
*/
|
||
function getId($pref)
|
||
{
|
||
$this->mid++;
|
||
return $pref . $this->mid;
|
||
}
|
||
|
||
/**
|
||
* Обработка шаблона
|
||
*
|
||
* @return string
|
||
*/
|
||
#[\Override]
|
||
public function execute(): string
|
||
{
|
||
|
||
$this->doTree('alias');
|
||
|
||
// Скрипты и стили
|
||
$this->set('scriptstring', $this->getScriptRaw());
|
||
$this->set('scripts', array_unique($this->getScripts()));
|
||
$this->set('stylesheet', array_unique($this->getStyleSheet()));
|
||
|
||
$this->require = ['admin' => 'ma'];
|
||
$this->deps = [];
|
||
|
||
$startup = [];
|
||
foreach ($this->_section as $s) {
|
||
if (is_string($s)) {
|
||
continue;
|
||
}
|
||
$moduleName = explode('_', $s->active_module ?: '', 2);
|
||
if (count($moduleName) < 2) {
|
||
continue;
|
||
}
|
||
|
||
$module = $moduleName[1];
|
||
|
||
$name = mb_strtolower($module);
|
||
$fname = $name . '/' . $name;
|
||
|
||
$current = $this->getId('m');
|
||
$this->require[$fname] = $current;
|
||
|
||
$value = $this->getId('v');
|
||
|
||
$script = "var " . $value . " = new " . $current . '.' . $module . "();\n";
|
||
foreach ($s->_values as $key => $v) {
|
||
$script .= $value . "." . $key . " = " . json_encode($v /*, JSON_PRETTY_PRINT*/) . ";\n";
|
||
}
|
||
|
||
$init = [];
|
||
/** @var View $item */
|
||
|
||
foreach ($s->_section as $key => $item) {
|
||
if ($item->codeGenerator !== null) {
|
||
// функцию которая вычисляет а не результат
|
||
$part = call_user_func($item->codeGenerator, $this, $key, $value);
|
||
$init[] = $part;
|
||
}
|
||
}
|
||
|
||
$script .= $value . ".execute('" . $s->module_action . "', " . json_encode($init) . ");\n";
|
||
$startup[] = $script;
|
||
}
|
||
|
||
|
||
$this->set('startup', implode("", $startup) . $this->getScriptStartup());
|
||
$this->set('require', implode(",", array_map(function ($x) {
|
||
return "'$x'"; }, array_keys($this->require))));
|
||
$this->set('deps', implode(",", array_values($this->require)));
|
||
|
||
$this->set('title', $this->getTitle());
|
||
$this->set('jspath', $this->config->get('system', 'web'));
|
||
//
|
||
return parent::execute(); // execute+phptal ??
|
||
}
|
||
|
||
/**
|
||
* Массив имен файлов скриптов
|
||
*
|
||
* @return array
|
||
*/
|
||
public function getScripts()
|
||
{
|
||
return $this->doTree('_script');
|
||
}
|
||
|
||
/**
|
||
* Строка со скриптом
|
||
*
|
||
* @return string
|
||
*/
|
||
public function getScriptRaw()
|
||
{
|
||
return implode("\n", $this->doTree('_scriptstring'));
|
||
}
|
||
|
||
/**
|
||
* Строка со скриптом
|
||
*
|
||
* @return string
|
||
*/
|
||
public function getScriptStartup()
|
||
{
|
||
return implode("\n", $this->doTree('_startup'));
|
||
}
|
||
|
||
/**
|
||
* Массив имен файлов стилей
|
||
*
|
||
* @return array
|
||
*/
|
||
public function getStyleSheet()
|
||
{
|
||
return $this->doTree('_stylesheet');
|
||
}
|
||
} |