Merge branch 'master' of http://gitlab.edu.yar.ru/composer/PHP_Library
This commit is contained in:
commit
513cbfafdd
8 changed files with 142 additions and 13 deletions
|
|
@ -372,4 +372,9 @@ class Controller_Action
|
||||||
{
|
{
|
||||||
$this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction());
|
$this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function redirect($action) {
|
||||||
|
header('location: ' . $this->fUrl($action));
|
||||||
|
exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,13 @@ class Controller_Component
|
||||||
|
|
||||||
function execute(HttpRequest $request, $has_id = true) {
|
function execute(HttpRequest $request, $has_id = true) {
|
||||||
$crequest = new ComponentRequest($this->component_id, $request);
|
$crequest = new ComponentRequest($this->component_id, $request);
|
||||||
$action = 'action' . ucfirst($request->get('action', 'index'));
|
|
||||||
|
$_action = $request->get('action', 'index');
|
||||||
|
if (is_array($_action)) {
|
||||||
|
$action = 'action' . ucfirst(Arr::get($_action, $this->component_id, 'index'));
|
||||||
|
} else {
|
||||||
|
$action = 'action' . ucfirst($_action);
|
||||||
|
}
|
||||||
|
|
||||||
$this->before();
|
$this->before();
|
||||||
if (method_exists($this, $action)) {
|
if (method_exists($this, $action)) {
|
||||||
|
|
@ -312,11 +318,7 @@ class Controller_Component
|
||||||
}
|
}
|
||||||
|
|
||||||
function addRequireJsPath($name, $path, $shim = null) {
|
function addRequireJsPath($name, $path, $shim = null) {
|
||||||
global $requireJsConfig;
|
Controller_Site::addRequireJsPath($name, $path, $shim);
|
||||||
$requireJsConfig['paths'][$name] = $path;
|
|
||||||
if ($shim) {
|
|
||||||
$requireJsConfig['shim'][$name] = $shim;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function actionIndex(/*.ComponentRequest.*/ $request) {
|
function actionIndex(/*.ComponentRequest.*/ $request) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class TField
|
||||||
public $error = false;
|
public $error = false;
|
||||||
public $require = false;
|
public $require = false;
|
||||||
public $hint = null;
|
public $hint = null;
|
||||||
|
public $fieldset = null;
|
||||||
// Блоки (Убрать в отдельный класс!!!)
|
// Блоки (Убрать в отдельный класс!!!)
|
||||||
public $_title = array();
|
public $_title = array();
|
||||||
public $description = "";
|
public $description = "";
|
||||||
|
|
@ -27,6 +28,9 @@ class TField
|
||||||
if (isset($input['validate'])) {
|
if (isset($input['validate'])) {
|
||||||
$this->require = strpos($input['validate'], 'require') !== false;
|
$this->require = strpos($input['validate'], 'require') !== false;
|
||||||
}
|
}
|
||||||
|
if (isset($input['fieldset'])) {
|
||||||
|
$this->fieldset = $input['fieldset'];
|
||||||
|
}
|
||||||
// Инициализация свойст обьетка
|
// Инициализация свойст обьетка
|
||||||
foreach (array('label', 'name', 'type', 'description') as $name) {
|
foreach (array('label', 'name', 'type', 'description') as $name) {
|
||||||
if (isset($input[$name])) {
|
if (isset($input[$name])) {
|
||||||
|
|
@ -213,8 +217,12 @@ class OptionFactory {
|
||||||
} else if (isset($input['options.db'])) {
|
} else if (isset($input['options.db'])) {
|
||||||
list($table, $keyvalue) = explode(":", $input['options.db']);
|
list($table, $keyvalue) = explode(":", $input['options.db']);
|
||||||
list($key, $value) = explode(",", $keyvalue);
|
list($key, $value) = explode(",", $keyvalue);
|
||||||
|
try{
|
||||||
$field->options = $this->optionsDB($key, $value, $this->db->executeQuery("SELECT * FROM $table"));
|
$query_result = $this->db->executeQuery("SELECT * FROM $table");
|
||||||
|
}catch(Exception $ex){
|
||||||
|
$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']);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -251,7 +259,9 @@ class OptionFactory {
|
||||||
* Форма для ввода
|
* Форма для ввода
|
||||||
*/
|
*/
|
||||||
class Form_Form extends View_View {
|
class Form_Form extends View_View {
|
||||||
public $field = array();
|
public $field = array(); //Поля формы
|
||||||
|
public $fieldsets = array(); //Группы полей (fieldset). Некоторые поля могут не принадлежать никаким группам
|
||||||
|
|
||||||
public $action = "";
|
public $action = "";
|
||||||
public $method = 'post';
|
public $method = 'post';
|
||||||
public $header;
|
public $header;
|
||||||
|
|
@ -313,8 +323,6 @@ class Form_Form extends View_View {
|
||||||
{
|
{
|
||||||
assert(isset($init['type']));
|
assert(isset($init['type']));
|
||||||
assert(isset($init['name']));
|
assert(isset($init['name']));
|
||||||
|
|
||||||
// print_r($init);
|
|
||||||
|
|
||||||
$constructor = $this->constructor[$init['type']];
|
$constructor = $this->constructor[$init['type']];
|
||||||
$el = new $constructor($init, $factory);
|
$el = new $constructor($init, $factory);
|
||||||
|
|
@ -330,6 +338,26 @@ class Form_Form extends View_View {
|
||||||
return $el;
|
return $el;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Добавление fieldset на форму
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function addFieldSet(array $fieldset)
|
||||||
|
{
|
||||||
|
$this->fieldsets[$fieldset['name']] = $fieldset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Добавление массива fieldset на форму
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function addFieldSetList(array $list)
|
||||||
|
{
|
||||||
|
foreach ($list as $fieldset) {
|
||||||
|
$this->addFieldSet($fieldset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Добавляет список полей для формы
|
* Добавляет список полей для формы
|
||||||
* @param array $list
|
* @param array $list
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,10 @@ class Mail
|
||||||
$this->_to = $name;
|
$this->_to = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function replyTo($name) // recipient
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Установка получателей копии
|
* Установка получателей копии
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
33
src/Model/Factory.php
Normal file
33
src/Model/Factory.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Model_Factory
|
||||||
|
{
|
||||||
|
static $shortcut = "model";
|
||||||
|
public $db;
|
||||||
|
public $_registry;
|
||||||
|
public $_shortcut;
|
||||||
|
|
||||||
|
public function __construct (/*.Database.*/ $db, Settings $_registry = null)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
$this->_registry = $_registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Создает модель
|
||||||
|
* @param string $name
|
||||||
|
* @return model
|
||||||
|
*/
|
||||||
|
public function getModel ($name)
|
||||||
|
{
|
||||||
|
require_once (Shortcut::getUrl(self::$shortcut, strtolower($name)));
|
||||||
|
$modelName = $name . "Mapper";
|
||||||
|
$model = new $modelName();
|
||||||
|
$model->db = $this->db;
|
||||||
|
$model->factory = $this;
|
||||||
|
$model->_registry = $this->_registry;
|
||||||
|
$model->setUp();
|
||||||
|
//
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
/**
|
/**
|
||||||
* Проверка формата времени
|
* Проверка формата времени
|
||||||
*/
|
*/
|
||||||
class Validator_Rule_IsFile extends Rule_Abstract
|
class Validator_Rule_IsFile extends Validator_Rule_Abstract
|
||||||
{
|
{
|
||||||
private $type = array();
|
private $type = array();
|
||||||
private $maxsize = 1024;
|
private $maxsize = 1024;
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class Validator_Validator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addRule(/*.any.*/&$rule) {
|
public function addRule(/*.any.*/$rule) {
|
||||||
if (is_array($rule)) {
|
if (is_array($rule)) {
|
||||||
$this->chain = array_merge($this->chain, $rule);
|
$this->chain = array_merge($this->chain, $rule);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
57
src/View/Pages.php
Normal file
57
src/View/Pages.php
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package system.widgets
|
||||||
|
*/
|
||||||
|
|
||||||
|
class View_Pages
|
||||||
|
{
|
||||||
|
static $range = 5;
|
||||||
|
static function getPages($page, $onpage, $count, $prefix = '?')
|
||||||
|
{
|
||||||
|
$n = ceil($count / $onpage);
|
||||||
|
if ($page > $n) $page = $n;
|
||||||
|
if ($page < 1) $page = 1;
|
||||||
|
$url = 'page=';
|
||||||
|
$result = array();
|
||||||
|
for ($i = max($page - self::$range, 1); $i <= min($n, $page + self::$range); $i++) {
|
||||||
|
$result [] = array('page' => $i, 'href' => ($i != $page) ? self::href($prefix, $url . $i) : false);
|
||||||
|
}
|
||||||
|
return array(
|
||||||
|
'all' => ($n > 1),
|
||||||
|
'list' => $result,
|
||||||
|
'first' => self::href($prefix, $url . 1),
|
||||||
|
'last' => self::href($prefix, $url . $n),
|
||||||
|
'next' => ($page == $n)? false : self::href($prefix, $url . ($page + 1)) ,
|
||||||
|
'prev' => ($page == 1)? false : self::href($prefix, $url . ($page - 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* @param $page int номер страницы
|
||||||
|
* @param $onpage int количество элем на странице
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static function getLimit(/*.number.*/$page, /*.number.*/$onpage) {
|
||||||
|
if ($page <= 0) { $page = 1; }
|
||||||
|
return "LIMIT $onpage OFFSET " . ($page - 1) * $onpage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $page int номер страницы
|
||||||
|
* @param $onpage int количество элем на странице
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
static function _getLimit($page, $onpage) {
|
||||||
|
if ($page <= 0) { $page = 1; }
|
||||||
|
return array(
|
||||||
|
'count' => $onpage,
|
||||||
|
'start' => ($page - 1) * $onpage,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function href($prefix, $x) {
|
||||||
|
return $prefix . $x;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue