Merge remote-tracking branch 'origin/dev'

This commit is contained in:
Фёдор Подлеснов 2018-01-15 16:47:43 +03:00
commit 7187963ac9
8 changed files with 66 additions and 15 deletions

View file

@ -177,7 +177,7 @@ class Controller_Component
public function setParameters(/*.View_Composite.*/$view) public function setParameters(/*.View_Composite.*/$view)
{ {
$form = new Form_Form(); $form = new Form_Form();
$options = new OptionFactory($this->db); $options = new OptionFactory($this->db, $this->registry);
$settings = $this->getInfo(); $settings = $this->getInfo();
$form->addFieldList($settings['parameter'], $options); $form->addFieldList($settings['parameter'], $options);
@ -262,10 +262,16 @@ class Controller_Component
$component->parameter = $params; $component->parameter = $params;
$component->template = $params->get('template', false); $component->template = $params->get('template', false);
global $componentsConfig;
$editor = $component->getEditUrl(); $editor = $component->getEditUrl();
if ($editor) { if ($editor) {
if(class_exists("Controller_Site")){ //Если мы в CMS2
$instance = Controller_Site::getInstance();
$instance->componentsConfig[] = $editor;
}else{
global $componentsConfig;
$componentsConfig[] = $editor; $componentsConfig[] = $editor;
}
} }
return $component; return $component;
@ -310,6 +316,10 @@ class Controller_Component
return '?' . http_build_query($arr); return '?' . http_build_query($arr);
} }
/**
* @deprecated В CMS2 перенесено в контроллер сайта!
*/
function addRequireJsPath($name, $path, $shim = null) { function addRequireJsPath($name, $path, $shim = null) {
Controller_Site::addRequireJsPath($name, $path, $shim); Controller_Site::addRequireJsPath($name, $path, $shim);
} }

View file

@ -101,6 +101,15 @@ class Controller_Front extends Controller_Action
} else { } else {
$controller = false; $controller = false;
} }
try{
return $this->loadModule($name[0], $request, $controller); return $this->loadModule($name[0], $request, $controller);
} catch (UserMessageException $ex) { //Исключение с понятным пользователю сообщением
$mode = $request->get('mode');
if($mode == 'ajax' || $mode == 'json'){
return json_encode(['result'=>'fail', 'message'=> $ex->userMessage]);
} else {
return $ex->userMessage;
}
}
} }
} }

View file

@ -26,6 +26,7 @@ class Filter_ActionAccess
$action = $request->getAction(); $action = $request->getAction();
if(! $this->checkAction($action)) { if(! $this->checkAction($action)) {
$request->set('action', 'index'); $request->set('action', 'index');
$request->setAction('index');
} }
return $this->processor->execute($request); return $this->processor->execute($request);
} }

View file

@ -15,7 +15,8 @@ class Filter_Login extends Filter_Filter
public $mode = 'ajax'; public $mode = 'ajax';
//AJAX-Реквесты для которых не требуется авторизация, потребовалось для сбора статистики //AJAX-Реквесты для которых не требуется авторизация, потребовалось для сбора статистики
public $whiteRequestList = array(array('module' => "requiredcontent", "action" => "getcount")); public $whiteRequestList = [['module' => "requiredcontent", "action" => "getcount"],
['module' => "requiredcontent", "action" => "teststructure"]];
/** /**
* Проверка авторизации * Проверка авторизации
* @return Boolean Авторизовани пользователь или нет * @return Boolean Авторизовани пользователь или нет

View file

@ -190,9 +190,10 @@ class TDateTime extends TInput {
class OptionFactory { class OptionFactory {
public $db; public $db;
public $registry;
function __construct($db) { function __construct($db, $registry = null) {
$this->db = $db; $this->db = $db;
$this->registry = $registry;
} }
function create(TSelect $field, $input) { function create(TSelect $field, $input) {
@ -225,6 +226,10 @@ class OptionFactory {
$field->options = $this->optionsDB($key, $value, $query_result); $field->options = $this->optionsDB($key, $value, $query_result);
} elseif (isset($input['options.pair'])) { } elseif (isset($input['options.pair'])) {
$field->options = $this->optionsPair($input['options.pair']); $field->options = $this->optionsPair($input['options.pair']);
} elseif (isset($input['options.model'])) {
$factory = new Model_Factory($this->db, $this->registry);
$model = $factory->getModel($input['options.model']);
$field->options = $model->getAllAsOptions();
} else { } else {
$field->options = $input['options']; $field->options = $input['options'];
} }

View file

@ -0,0 +1,17 @@
<?php
/**
* UserMessageException.php
*
*/
/**
* Исключение с понятным пользователю сообщением, которое имеет смысл ему показать.
* @see Controller_Front
*/
class UserMessageException extends Exception {
public $userMessage;
public function __construct($message) {
parent::__construct($message);
$this->userMessage = $message;
}
}

View file

@ -49,10 +49,14 @@ class View_Page extends View_View
{ {
//$result = phptal_component($match, $offset); //$result = phptal_component($match, $offset);
//*
global $db, $registry; // Нужно как-то передавать параметры
if(class_exists("Controller_Site")){ //Если мы в CMS2
$component = Controller_Site::loadComponent($match);
}else{
global $db, $registry; //
$component = Controller_Component::loadComponent($match, $db, $registry); $component = Controller_Component::loadComponent($match, $db, $registry);
}
$req = new HttpRequest(); $req = new HttpRequest();
unset($req['active_page']); unset($req['active_page']);

View file

@ -45,10 +45,14 @@ function phptal_time ($e)
* Функция подключения компонента * Функция подключения компонента
*/ */
function phptal_component ($expression) { function phptal_component ($expression) {
global $db, $registry; // Нужно как-то передавать параметры
$begin = microtime(true); $begin = microtime(true);
if(class_exists("Controller_Site")){ //Если мы в CMS2
$component = Controller_Site::loadComponent($expression);
}else{
global $db, $registry; // Иначе обращаемся к глобальным переменным
$component = Controller_Component::loadComponent($expression, $db, $registry); $component = Controller_Component::loadComponent($expression, $db, $registry);
}
$req = new HttpRequest(); $req = new HttpRequest();
$result = $component->execute($req); $result = $component->execute($req);