From 8065253db0831ce2542fc9ba1e879a93b3e04373 Mon Sep 17 00:00:00 2001 From: "CORP\\phedor" Date: Thu, 26 Apr 2018 12:31:43 +0300 Subject: [PATCH] =?UTF-8?q?OptionFactory=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=20=D0=B2=20cms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 4 +- src/Form/OptionFactory.php | 78 ------------------------------------ 2 files changed, 1 insertion(+), 81 deletions(-) delete mode 100644 src/Form/OptionFactory.php diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 7210d32..b520f09 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -7,7 +7,6 @@ use ctiso\HttpRequest, ctiso\Path, ctiso\File, ctiso\Form\Form, - ctiso\Form\OptionFactory, ctiso\View\Composite, ctiso\Database, ctiso\Database\PDOStatement, @@ -196,10 +195,9 @@ class Component /** * Генерация интерфейса для выбора галлереи фотографии */ - public function setParameters(/*.Composite.*/ $view) + public function setParameters(/*.Composite.*/ $view, $options = null) { $form = new Form(); - $options = new OptionFactory($this->db, $this->config); $settings = $this->getInfo(); $form->addFieldList($settings['parameter'], $options); diff --git a/src/Form/OptionFactory.php b/src/Form/OptionFactory.php deleted file mode 100644 index d0fd9e8..0000000 --- a/src/Form/OptionFactory.php +++ /dev/null @@ -1,78 +0,0 @@ -db = $db; - $this->registry = $registry; - } - - function create(Select $field, $input) { - if (isset($input['options.resid'])) { - $type = $input['options.resid']; - - $res = new 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 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 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"); - $field->options = $this->optionsDB($key, $value, $query_result); - } catch(\Exception $ex) { - $field->options = []; - } - } elseif (isset($input['options.pair'])) { - $field->options = $this->optionsPair($input['options.pair']); - } elseif (isset($input['options.model'])) { - $factory = new 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; - } -}