Вынес классы в отдельные файлы
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
|
||||
|
||||
/**
|
||||
* Поле ввода Input
|
||||
*/
|
||||
class TInput extends Form_Field {
|
||||
}
|
||||
|
||||
class TCheckbox extends Form_Field
|
||||
{
|
||||
public $checked = false;
|
||||
|
|
@ -17,52 +11,7 @@ class TCheckbox extends Form_Field
|
|||
}
|
||||
|
||||
|
||||
class TSelect 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Выбор из одного элемента
|
||||
*/
|
||||
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
|
||||
class TSelectMany extends Form_Select
|
||||
{
|
||||
function setValue($value)
|
||||
{
|
||||
|
|
@ -75,7 +24,7 @@ class TSelectMany extends TSelect
|
|||
}
|
||||
}
|
||||
|
||||
class TQuestionType extends TSelect
|
||||
class TQuestionType extends Form_Select
|
||||
{
|
||||
function setValue($value)
|
||||
{
|
||||
|
|
@ -124,18 +73,18 @@ class TUpload extends Form_Field
|
|||
{
|
||||
}
|
||||
|
||||
class THidden extends TInput {
|
||||
class THidden extends Form_Input {
|
||||
public $hidden = true;
|
||||
}
|
||||
|
||||
class TComponentBrowserInput extends TInput
|
||||
class TComponentBrowserInput extends Form_Input
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* При рендеринге каждому классу соответствует шаблон (см. themes/maxim/templates/macros.html)
|
||||
*/
|
||||
class TDateTime extends TInput {
|
||||
class TDateTime extends Form_Input {
|
||||
}
|
||||
|
||||
class OptionFactory {
|
||||
|
|
@ -146,7 +95,7 @@ class OptionFactory {
|
|||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
function create(TSelect $field, $input) {
|
||||
function create(Form_Select $field, $input) {
|
||||
if (isset($input['options.resid'])) {
|
||||
$type = $input['options.resid'];
|
||||
|
||||
|
|
@ -234,8 +183,8 @@ class Form_Form extends View_View {
|
|||
public function __construct()
|
||||
{
|
||||
$this->constructor = array(
|
||||
'input' => 'TInput',
|
||||
'inputreq' => 'TInput', // input с проверкой на заполненность
|
||||
'input' => 'Form_Input',
|
||||
'inputreq' => 'Form_Input', // input с проверкой на заполненность
|
||||
|
||||
'date' => 'TDate',
|
||||
'datereq' => 'TDate',
|
||||
|
|
@ -246,8 +195,8 @@ class Form_Form extends View_View {
|
|||
'text' => 'TTextArea',
|
||||
'multiselect' => 'TSelectMany',
|
||||
// 'selectmany' => 'TSelectMany',
|
||||
'select1' => 'TSelectOne',
|
||||
'select' => 'TSelectOne',
|
||||
'select1' => 'Form_SelectOne',
|
||||
'select' => 'Form_SelectOne',
|
||||
'questiontype'=> 'TQuestionType',
|
||||
'secret' => 'TSecret',
|
||||
'upload' => 'TUpload',
|
||||
|
|
@ -255,7 +204,7 @@ class Form_Form extends View_View {
|
|||
'checkbox' => 'TCheckbox',
|
||||
'checkmany' => 'TSelectMany',
|
||||
'hidden' => 'THidden',
|
||||
'radio' => 'TSelectOne',
|
||||
'radio' => 'Form_SelectOne',
|
||||
'filebrowser' => '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