Поправил инициализацию модулей

This commit is contained in:
CORP\phedor 2018-03-28 19:06:30 +03:00
parent 0b66a72484
commit bef7165777
4 changed files with 40 additions and 32 deletions

View file

@ -28,15 +28,14 @@ class Action
const TEMPLATE_EXTENSION = ".html"; // Расширение для шаблонов
const ACTION_PREFIX = "action"; // Префикс для функций действий
public $jsPath; // Глобальный путь к скриптам
public $themePath; // Глобальный путь к текущей теме
// Параметры устанавливаются при создании контроллера
public $name = ''; // Имя модуля
public $viewPath = null; // Путь к шаблонам контроллера
public $viewPathPrefix = null; // Путь к шаблонам контроллера
public $moduleTitle = "";
public $modulePath = null; // Путь к модулю
public $moduleTitle = '';
public $modulePrefix = '';
public $viewPathPrefix = null; // Путь к шаблонам контроллера
/**
* Соединение с базой данных
@ -51,9 +50,8 @@ class Action
private $helpers = array(); // Помошники для действий
public $param = array(); // Параметры для ссылки
public /*.Registry.*/$_registry; // Ссылка на реестр
public $modulePrefix = '';
public $iconPath = '';
public /*.Settings.*/$settings; // Ссылка на настройки
public $user; // Обьект пользователя
// Для Widgets
public $view = null;
@ -94,7 +92,7 @@ class Action
public function addSuggest(View $view, $name)
{
$suggest = array();
$file = Path::join($this->viewPath, 'help', $name . '.suggest');
$file = Path::join($this->modulePath, 'help', $name . '.suggest');
if (file_exists($file)) {
include($file);
$view->suggestions = $suggest;
@ -103,7 +101,8 @@ class Action
function findIcon($icon, $size)
{
return Path::join($this->iconPath, $size . 'x' . $size, $icon . '.png');
$webPath = $this->settings['web'];
return Path::join($webPath, 'icons', $size . 'x' . $size, $icon . '.png');
}
/**
@ -120,7 +119,7 @@ class Action
$webPath = $this->settings['web'];
$list = array(
Path::join($this->viewPath, 'templates', $this->viewPathPrefix) => Path::join($webPath, "modules", $this->name, 'templates', $this->viewPathPrefix),
Path::join($this->modulePath, 'templates', $this->viewPathPrefix) => Path::join($webPath, "modules", $this->name, 'templates', $this->viewPathPrefix),
Path::join($basePath, "templates") => Path::join($webPath, "templates")
);
@ -132,17 +131,19 @@ class Action
/*.View_Composite.*/$tpl = new $viewClass($template);
$assets = Path::join($webPath, "assets", "css");
$tpl->set('icons', $this->iconPath); // Путь к файлам текущей темы
$tpl->set('media', $this->themePath); // Путь к файлам текущей темы
$tpl->set('assets', $assets);
$tpl->set('script', $this->jsPath); // Путь к файлам скриптов
$stylePath = Path::join($webPath, "assets", "css");
$iconsPath = Path::join($webPath, 'icons');
$scriptPath = Path::join($webPath, 'assets');
$tpl->set('icons', $iconsPath); // Путь к файлам текущей темы
$tpl->set('assets', $stylePath);
$tpl->set('script', $scriptPath); // Путь к файлам скриптов
$tpl->set('template', $path); // Путь к файлам текущего шаблона
$tpl->setAlias(array(
'assets' => $assets,
'icons' => $this->iconPath,
'script' => $this->jsPath,
'assets' => $stylePath,
'icons' => $iconsPath,
'script' => $scriptPath,
// Для media и template поиск происходит как для файлов шаблонов
'media' => $list,
'template' => $list

View file

@ -53,9 +53,9 @@ class Front extends Action
$system = $this->settings['system'];
$moulesPath = $system->readKey(['path', 'modules']);
$moulesPath = Path::join($this->settings['base'], $system->readKey(['path', 'modules']));
$logPath = Path::join($this->settings['site'], $system->readKey(['path', 'access.log']));
$moduleFile = Path::join($this->settings['base'], $moulesPath, $name, 'classes', $controller ? $controller : $name);
$moduleFile = Path::join($moulesPath, $name, 'classes', $controller ? $controller : $name);
$ucname = ucfirst($name);
$moduleClass = "Modules\\$ucname\\$ucname";
@ -63,11 +63,12 @@ class Front extends Action
if ($module) {
// Инициализация модуля
$modPath = Path::join($moulesPath, $name);
$module->viewPath = $modPath;
$module->modulePath = $modPath;
$module->name = $name;
//
$module->settings = $this->settings;
$module->db = $this->db;
$module->user = $this->user;
// Ведение лога
$logger = new ActionLogger($module, $logPath, $this->user);
$logger->before = $this->loadSettings(Path::join($modPath, 'filter', 'logger.php'));

View file

@ -41,7 +41,6 @@ class Login extends Filter
$login = $request->get('login');
$password = $request->get('password');
$result = $this->role->getUserByLogin($login); // Поиск по логину
if ($result) {
$userPassword = $this->role->getUserPassword($result);

View file

@ -43,31 +43,38 @@ class User
return null;
}
public static function getUserByLogin($login)
function getUserPassword($result) {
return $result->get('password');
}
public function getUserByLogin($login)
{
$stmt = $this->$db->prepareStatement("SELECT * FROM users WHERE login = ?");
$stmt = $this->db->prepareStatement("SELECT * FROM users WHERE login = ?");
$stmt->setString(1, $login);
$result = $this->getUserByQuery($stmt);
if ($result) {
$time = time();
$id = $this->id;
$this->$db->executeQuery("UPDATE users SET lasttime = $time WHERE id_user = $id"); // Время входа
$this->db->executeQuery("UPDATE users SET lasttime = $time WHERE id_user = $id"); // Время входа
}
return $result;
}
public static function getUserById($id)
public function getUserById($id)
{
$stmt = $this->$db->prepareStatement("SELECT * FROM users WHERE id_user = ?");
$stmt = $this->db->prepareStatement("SELECT * FROM users WHERE id_user = ?");
$stmt->setInt(1, $_SESSION ['access']);
$result = $this->getUserByQuery($stmt);
if ($result) {
$lasttime = $result->getInt('lasttime');
$time = time();
if ($time - $lasttime > $this->LIFE_TIME) return null; // Вышло время сессии
$id = $this->$id;
if ($time - $lasttime > self::LIFE_TIME) return null; // Вышло время сессии
$id = $this->id;
$this->db->executeQuery("UPDATE users SET lasttime = $time WHERE id_user = $id"); // Время последнего обращения входа
}
return $result;
}
function setSID() {
}
}