Вынес еще классы
This commit is contained in:
parent
ca5cf04146
commit
7b3190f96e
6 changed files with 126 additions and 128 deletions
8
src/Form/Color.php
Normal file
8
src/Form/Color.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Поле с цветом
|
||||
*/
|
||||
class Form_Color extends Form_Field
|
||||
{
|
||||
}
|
||||
6
src/Form/Date.php
Normal file
6
src/Form/Date.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Поле с датой
|
||||
*/
|
||||
class Form_Date extends Form_Field {
|
||||
}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* При рендеринге каждому классу соответствует шаблон (см. themes/maxim/templates/macros.html)
|
||||
*/
|
||||
|
||||
class TCheckbox extends Form_Field
|
||||
{
|
||||
public $checked = false;
|
||||
|
|
@ -10,20 +14,6 @@ class TCheckbox extends Form_Field
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
class TSelectMany extends Form_Select
|
||||
{
|
||||
function setValue($value)
|
||||
{
|
||||
// Установить selected у options
|
||||
if (!is_array($value)) { $value = array($value); }
|
||||
$this->value = $value;
|
||||
foreach ($this->options as &$option) {
|
||||
$option['selected'] = (in_array($option['value'], $value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TQuestionType extends Form_Select
|
||||
{
|
||||
function setValue($value)
|
||||
|
|
@ -36,127 +26,23 @@ class TQuestionType extends Form_Select
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Поле с датой
|
||||
*/
|
||||
class TDate extends Form_Field
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Поле с цветом
|
||||
*/
|
||||
class TColor extends Form_Field
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Текстовое поле
|
||||
*/
|
||||
class TTextArea extends Form_Field
|
||||
{
|
||||
function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
class TDateTime extends Form_Input {
|
||||
}
|
||||
|
||||
/**
|
||||
* Поле для ввода пароля
|
||||
*/
|
||||
class TSecret extends Form_Field
|
||||
{
|
||||
class TSecret extends Form_Field {
|
||||
}
|
||||
|
||||
class TUpload extends Form_Field
|
||||
{
|
||||
class TUpload extends Form_Field {
|
||||
}
|
||||
|
||||
class THidden extends Form_Input {
|
||||
public $hidden = true;
|
||||
}
|
||||
|
||||
class TComponentBrowserInput extends Form_Input
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* При рендеринге каждому классу соответствует шаблон (см. themes/maxim/templates/macros.html)
|
||||
*/
|
||||
class TDateTime extends Form_Input {
|
||||
}
|
||||
|
||||
class OptionFactory {
|
||||
public $db;
|
||||
public $registry;
|
||||
function __construct($db, $registry = null) {
|
||||
$this->db = $db;
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
function create(Form_Select $field, $input) {
|
||||
if (isset($input['options.resid'])) {
|
||||
$type = $input['options.resid'];
|
||||
|
||||
$res = new Model_Resources($this->db);
|
||||
$field->options = $this->optionsArray('id_section', 'title', $res->getSubsections('', $type));
|
||||
|
||||
} else if (isset($input['options.res'])) {
|
||||
$type = $input['options.res'];
|
||||
|
||||
$res = new Model_Resources($this->db);
|
||||
$field->options = $this->optionsArray('path', 'title', $res->getSubsections('', $type));
|
||||
|
||||
} else if (isset($input['options.all_res'])) {
|
||||
$type = $input['options.all_res'];
|
||||
|
||||
$res = new Model_Resources($this->db);
|
||||
$field->options = $this->optionsArray('id_resource', 'subtitle', $res->getAllResource($type));
|
||||
|
||||
} else if (isset($input['options.db'])) {
|
||||
list($table, $keyvalue) = explode(":", $input['options.db']);
|
||||
list($key, $value) = explode(",", $keyvalue);
|
||||
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']);
|
||||
} elseif (isset($input['options.model'])) {
|
||||
$factory = new Model_Factory($this->db, $this->registry);
|
||||
$model = $factory->getModel($input['options.model']);
|
||||
$field->options = $model->getAllAsOptions();
|
||||
} else {
|
||||
$field->options = $input['options'];
|
||||
}
|
||||
}
|
||||
|
||||
public function optionsDB($key, $val, $res) {
|
||||
$result = array();
|
||||
while($res->next()) {
|
||||
$result[] = array('value' => $res->getInt($key), 'name' => $res->getString($val));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function optionsArray($key, $val, $res) {
|
||||
$result = array();
|
||||
foreach($res as $item) {
|
||||
$result[] = array('value' => $item->{$key}, 'name' => $item->{$val});
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
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 TComponentBrowserInput extends Form_Input {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -186,14 +72,14 @@ class Form_Form extends View_View {
|
|||
'input' => 'Form_Input',
|
||||
'inputreq' => 'Form_Input', // input с проверкой на заполненность
|
||||
|
||||
'date' => 'TDate',
|
||||
'datereq' => 'TDate',
|
||||
'date' => 'Form_Date',
|
||||
'datereq' => 'Form_Date',
|
||||
'datetime' => 'TDateTime',
|
||||
|
||||
'color' => 'TColor',
|
||||
'textarea' => 'TTextArea',
|
||||
'text' => 'TTextArea',
|
||||
'multiselect' => 'TSelectMany',
|
||||
'color' => 'Form_Color',
|
||||
'textarea' => 'Form_TextArea',
|
||||
'text' => 'Form_TextArea',
|
||||
'multiselect' => 'Form_SelectMany',
|
||||
// 'selectmany' => 'TSelectMany',
|
||||
'select1' => 'Form_SelectOne',
|
||||
'select' => 'Form_SelectOne',
|
||||
|
|
|
|||
73
src/Form/OptionFactory.php
Normal file
73
src/Form/OptionFactory.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
class Form_OptionFactory {
|
||||
public $db;
|
||||
public $registry;
|
||||
function __construct($db, $registry = null) {
|
||||
$this->db = $db;
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
function create(Form_Select $field, $input) {
|
||||
if (isset($input['options.resid'])) {
|
||||
$type = $input['options.resid'];
|
||||
|
||||
$res = new Model_Resources($this->db);
|
||||
$field->options = $this->optionsArray('id_section', 'title', $res->getSubsections('', $type));
|
||||
|
||||
} else if (isset($input['options.res'])) {
|
||||
$type = $input['options.res'];
|
||||
|
||||
$res = new Model_Resources($this->db);
|
||||
$field->options = $this->optionsArray('path', 'title', $res->getSubsections('', $type));
|
||||
|
||||
} else if (isset($input['options.all_res'])) {
|
||||
$type = $input['options.all_res'];
|
||||
|
||||
$res = new Model_Resources($this->db);
|
||||
$field->options = $this->optionsArray('id_resource', 'subtitle', $res->getAllResource($type));
|
||||
|
||||
} else if (isset($input['options.db'])) {
|
||||
list($table, $keyvalue) = explode(":", $input['options.db']);
|
||||
list($key, $value) = explode(",", $keyvalue);
|
||||
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']);
|
||||
} elseif (isset($input['options.model'])) {
|
||||
$factory = new Model_Factory($this->db, $this->registry);
|
||||
$model = $factory->getModel($input['options.model']);
|
||||
$field->options = $model->getAllAsOptions();
|
||||
} else {
|
||||
$field->options = $input['options'];
|
||||
}
|
||||
}
|
||||
|
||||
public function optionsDB($key, $val, $res) {
|
||||
$result = array();
|
||||
while($res->next()) {
|
||||
$result[] = array('value' => $res->getInt($key), 'name' => $res->getString($val));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function optionsArray($key, $val, $res) {
|
||||
$result = array();
|
||||
foreach($res as $item) {
|
||||
$result[] = array('value' => $item->{$key}, 'name' => $item->{$val});
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function optionsPair($list, $selected = false) {
|
||||
$result = array();
|
||||
foreach ($list as $key => $value) {
|
||||
$result [] = array('value' => $key, 'name' => $value, 'selected' => $key == $selected);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
14
src/Form/SelectMany.php
Normal file
14
src/Form/SelectMany.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
class Form_SelectMany extends Form_Select
|
||||
{
|
||||
function setValue($value)
|
||||
{
|
||||
// Установить selected у options
|
||||
if (!is_array($value)) { $value = array($value); }
|
||||
$this->value = $value;
|
||||
foreach ($this->options as &$option) {
|
||||
$option['selected'] = (in_array($option['value'], $value));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/Form/TextArea.php
Normal file
11
src/Form/TextArea.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Текстовое поле
|
||||
*/
|
||||
class Form_TextArea extends Form_Field {
|
||||
function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue