From fd064e963d143569501e7c4ca9361b9e3f0796be Mon Sep 17 00:00:00 2001 From: Anatoly Date: Thu, 13 Apr 2017 16:12:12 +0300 Subject: [PATCH 1/3] fieldset --- src/Form/Form.php | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/Form/Form.php b/src/Form/Form.php index aa68acc..585f06a 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -15,6 +15,7 @@ class TField public $error = false; public $require = false; public $hint = null; + public $fieldset = null; // Блоки (Убрать в отдельный класс!!!) public $_title = array(); public $description = ""; @@ -27,6 +28,9 @@ class TField if (isset($input['validate'])) { $this->require = strpos($input['validate'], 'require') !== false; } + if (isset($input['fieldset'])) { + $this->fieldset = $input['fieldset']; + } // Инициализация свойст обьетка foreach (array('label', 'name', 'type', 'description') as $name) { if (isset($input[$name])) { @@ -213,8 +217,12 @@ class OptionFactory { } else if (isset($input['options.db'])) { list($table, $keyvalue) = explode(":", $input['options.db']); list($key, $value) = explode(",", $keyvalue); - - $field->options = $this->optionsDB($key, $value, $this->db->executeQuery("SELECT * FROM $table")); + try{ + $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'])) { $field->options = $this->optionsPair($input['options.pair']); } else { @@ -251,7 +259,9 @@ class OptionFactory { * Форма для ввода */ class Form_Form extends View_View { - public $field = array(); + public $field = array(); //Поля формы + public $fieldsets = array(); //Группы полей (fieldset). Некоторые поля могут не принадлежать никаким группам + public $action = ""; public $method = 'post'; public $header; @@ -313,8 +323,6 @@ class Form_Form extends View_View { { assert(isset($init['type'])); assert(isset($init['name'])); - -// print_r($init); $constructor = $this->constructor[$init['type']]; $el = new $constructor($init, $factory); @@ -330,6 +338,26 @@ class Form_Form extends View_View { 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 From cc33b8f810efef6666693ac2d9de3325d17c2339 Mon Sep 17 00:00:00 2001 From: origami11 Date: Thu, 4 May 2017 15:51:19 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D1=82=D0=B0=D1=80=D0=BD?= =?UTF-8?q?=D0=B8=D1=87=D0=BD=D0=BE=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Action.php | 5 +++ src/Database.php | 2 +- src/Model/Factory.php | 33 ++++++++++++++++++++ src/Validator/Rule/IsFile.php | 2 +- src/Validator/Validator.php | 2 +- src/View/Pages.php | 57 +++++++++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 src/Model/Factory.php create mode 100644 src/View/Pages.php diff --git a/src/Controller/Action.php b/src/Controller/Action.php index 6e314e2..67b213a 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -372,4 +372,9 @@ class Controller_Action { $this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction()); } + + function redirect($action) { + header('location: ' . $this->fUrl($action)); + exit(); + } } diff --git a/src/Database.php b/src/Database.php index c4cd264..eb87479 100644 --- a/src/Database.php +++ b/src/Database.php @@ -1,6 +1,6 @@ -require_once "database/pdostatement.php"; +require_once "Database/PDOStatement.php"; /** * Класс оболочка для PDO для замены Creole */ diff --git a/src/Model/Factory.php b/src/Model/Factory.php new file mode 100644 index 0000000..82ec890 --- /dev/null +++ b/src/Model/Factory.php @@ -0,0 +1,33 @@ +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; + } +} diff --git a/src/Validator/Rule/IsFile.php b/src/Validator/Rule/IsFile.php index c19cf12..64d5f97 100644 --- a/src/Validator/Rule/IsFile.php +++ b/src/Validator/Rule/IsFile.php @@ -3,7 +3,7 @@ /** * Проверка формата времени */ -class Validator_Rule_IsFile extends Rule_Abstract +class Validator_Rule_IsFile extends Validator_Rule_Abstract { private $type = array(); private $maxsize = 1024; diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index fe3ea2e..06b8213 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -68,7 +68,7 @@ class Validator_Validator } } - public function addRule(/*.any.*/&$rule) { + public function addRule(/*.any.*/$rule) { if (is_array($rule)) { $this->chain = array_merge($this->chain, $rule); } else { diff --git a/src/View/Pages.php b/src/View/Pages.php new file mode 100644 index 0000000..736a861 --- /dev/null +++ b/src/View/Pages.php @@ -0,0 +1,57 @@ + $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; + } + +} + From b3f11fc85f4cd9463a4a59eddae36e3bd1fb4e89 Mon Sep 17 00:00:00 2001 From: origami11 Date: Fri, 12 May 2017 14:13:41 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9E=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20action=20=D1=83=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 8 +++++++- src/Mail.php | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 0a8220c..5d56d24 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -66,7 +66,13 @@ class Controller_Component function execute(HttpRequest $request, $has_id = true) { $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(); if (method_exists($this, $action)) { diff --git a/src/Mail.php b/src/Mail.php index f27a0a8..1f4eda4 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -40,6 +40,10 @@ class Mail $this->_to = $name; } + function replyTo($name) // recipient + { + } + /** * Установка получателей копии */