Вынес классы в отдельные файлы
This commit is contained in:
parent
7bbccea3b0
commit
7e53f07dac
5 changed files with 66 additions and 63 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Элемент формы
|
* Элемент формы
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* Поле ввода Input
|
|
||||||
*/
|
|
||||||
class TInput extends Form_Field {
|
|
||||||
}
|
|
||||||
|
|
||||||
class TCheckbox extends Form_Field
|
class TCheckbox extends Form_Field
|
||||||
{
|
{
|
||||||
public $checked = false;
|
public $checked = false;
|
||||||
|
|
@ -17,52 +11,7 @@ class TCheckbox extends Form_Field
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class TSelect extends Form_Field
|
class TSelectMany extends Form_Select
|
||||||
{
|
|
||||||
public $options = array();
|
|
||||||
|
|
||||||
public function __construct ($input, $factory) {
|
|
||||||
parent::__construct($input, $factory);
|
|
||||||
|
|
||||||
if ($factory != null) {
|
|
||||||
$factory->create($this, $input);
|
|
||||||
} else if (isset($input['options.pair'])) {
|
|
||||||
$this->options = $this->optionsPair($input['options.pair']);
|
|
||||||
} else if (isset($input['options'])) {
|
|
||||||
$this->options = $input['options'];
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->options as &$option) {
|
|
||||||
$option['selected'] = false;
|
|
||||||
$option['class'] = (isset($option['class'])) ? $option['class'] : false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function optionsPair($list, $selected = false) {
|
|
||||||
$result = array();
|
|
||||||
foreach ($list as $key => $value) {
|
|
||||||
$result [] = array('value' => $key, 'name' => $value, 'selected' => $key == $selected);
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Выбор из одного элемента
|
|
||||||
*/
|
|
||||||
class TSelectOne extends TSelect
|
|
||||||
{
|
|
||||||
function setValue($value)
|
|
||||||
{
|
|
||||||
// Установить selected у options
|
|
||||||
$this->value = $value;
|
|
||||||
foreach ($this->options as &$option) {
|
|
||||||
$option['selected'] = ($option['value'] == $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TSelectMany extends TSelect
|
|
||||||
{
|
{
|
||||||
function setValue($value)
|
function setValue($value)
|
||||||
{
|
{
|
||||||
|
|
@ -75,7 +24,7 @@ class TSelectMany extends TSelect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TQuestionType extends TSelect
|
class TQuestionType extends Form_Select
|
||||||
{
|
{
|
||||||
function setValue($value)
|
function setValue($value)
|
||||||
{
|
{
|
||||||
|
|
@ -124,18 +73,18 @@ class TUpload extends Form_Field
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class THidden extends TInput {
|
class THidden extends Form_Input {
|
||||||
public $hidden = true;
|
public $hidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TComponentBrowserInput extends TInput
|
class TComponentBrowserInput extends Form_Input
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* При рендеринге каждому классу соответствует шаблон (см. themes/maxim/templates/macros.html)
|
* При рендеринге каждому классу соответствует шаблон (см. themes/maxim/templates/macros.html)
|
||||||
*/
|
*/
|
||||||
class TDateTime extends TInput {
|
class TDateTime extends Form_Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
class OptionFactory {
|
class OptionFactory {
|
||||||
|
|
@ -146,7 +95,7 @@ class OptionFactory {
|
||||||
$this->registry = $registry;
|
$this->registry = $registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
function create(TSelect $field, $input) {
|
function create(Form_Select $field, $input) {
|
||||||
if (isset($input['options.resid'])) {
|
if (isset($input['options.resid'])) {
|
||||||
$type = $input['options.resid'];
|
$type = $input['options.resid'];
|
||||||
|
|
||||||
|
|
@ -234,8 +183,8 @@ class Form_Form extends View_View {
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->constructor = array(
|
$this->constructor = array(
|
||||||
'input' => 'TInput',
|
'input' => 'Form_Input',
|
||||||
'inputreq' => 'TInput', // input с проверкой на заполненность
|
'inputreq' => 'Form_Input', // input с проверкой на заполненность
|
||||||
|
|
||||||
'date' => 'TDate',
|
'date' => 'TDate',
|
||||||
'datereq' => 'TDate',
|
'datereq' => 'TDate',
|
||||||
|
|
@ -246,8 +195,8 @@ class Form_Form extends View_View {
|
||||||
'text' => 'TTextArea',
|
'text' => 'TTextArea',
|
||||||
'multiselect' => 'TSelectMany',
|
'multiselect' => 'TSelectMany',
|
||||||
// 'selectmany' => 'TSelectMany',
|
// 'selectmany' => 'TSelectMany',
|
||||||
'select1' => 'TSelectOne',
|
'select1' => 'Form_SelectOne',
|
||||||
'select' => 'TSelectOne',
|
'select' => 'Form_SelectOne',
|
||||||
'questiontype'=> 'TQuestionType',
|
'questiontype'=> 'TQuestionType',
|
||||||
'secret' => 'TSecret',
|
'secret' => 'TSecret',
|
||||||
'upload' => 'TUpload',
|
'upload' => 'TUpload',
|
||||||
|
|
@ -255,7 +204,7 @@ class Form_Form extends View_View {
|
||||||
'checkbox' => 'TCheckbox',
|
'checkbox' => 'TCheckbox',
|
||||||
'checkmany' => 'TSelectMany',
|
'checkmany' => 'TSelectMany',
|
||||||
'hidden' => 'THidden',
|
'hidden' => 'THidden',
|
||||||
'radio' => 'TSelectOne',
|
'radio' => 'Form_SelectOne',
|
||||||
'filebrowser' => 'TComponentBrowserInput',
|
'filebrowser' => 'TComponentBrowserInput',
|
||||||
'documents' => 'TComponentBrowserInput',
|
'documents' => 'TComponentBrowserInput',
|
||||||
);
|
);
|
||||||
|
|
|
||||||
7
src/Form/Input.php
Normal file
7
src/Form/Input.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Поле ввода Input
|
||||||
|
*/
|
||||||
|
class Form_Input extends Form_Field {
|
||||||
|
}
|
||||||
31
src/Form/Select.php
Normal file
31
src/Form/Select.php
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Form_Select extends Form_Field
|
||||||
|
{
|
||||||
|
public $options = array();
|
||||||
|
|
||||||
|
public function __construct ($input, $factory) {
|
||||||
|
parent::__construct($input, $factory);
|
||||||
|
|
||||||
|
if ($factory != null) {
|
||||||
|
$factory->create($this, $input);
|
||||||
|
} else if (isset($input['options.pair'])) {
|
||||||
|
$this->options = $this->optionsPair($input['options.pair']);
|
||||||
|
} else if (isset($input['options'])) {
|
||||||
|
$this->options = $input['options'];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->options as &$option) {
|
||||||
|
$option['selected'] = false;
|
||||||
|
$option['class'] = (isset($option['class'])) ? $option['class'] : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function optionsPair($list, $selected = false) {
|
||||||
|
$result = array();
|
||||||
|
foreach ($list as $key => $value) {
|
||||||
|
$result [] = array('value' => $key, 'name' => $value, 'selected' => $key == $selected);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/Form/SelectOne.php
Normal file
16
src/Form/SelectOne.php
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Выбор из одного элемента
|
||||||
|
*/
|
||||||
|
class Form_SelectOne extends Form_Select
|
||||||
|
{
|
||||||
|
function setValue($value)
|
||||||
|
{
|
||||||
|
// Установить selected у options
|
||||||
|
$this->value = $value;
|
||||||
|
foreach ($this->options as &$option) {
|
||||||
|
$option['selected'] = ($option['value'] == $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue