From 6295cf0f3f1de83e65d12943be40b2fd0536249c Mon Sep 17 00:00:00 2001 From: dp Date: Fri, 27 Mar 2015 19:49:35 +0300 Subject: [PATCH] Quick Reports complete --- .../Ice/Ui/Data/Table/Column/Link.tpl.php | 6 +- Source/Ice/Action/Data.php | 20 +++++- Source/Ice/App.php | 2 +- Source/Ice/Core/Action.php | 33 ++++++--- Source/Ice/Core/Environment.php | 6 +- Source/Ice/Core/Ui/Data.php | 68 +++++++++++++++---- Source/Ice/Core/View.php | 25 ++----- Source/Ice/Data/Provider/Cacher.php | 17 +++-- Source/Ice/Data/Provider/Repository.php | 17 +++-- Source/Ice/Ui/Data/{Simple.php => Table.php} | 2 +- 10 files changed, 126 insertions(+), 70 deletions(-) rename Source/Ice/Ui/Data/{Simple.php => Table.php} (64%) diff --git a/Resource/Ice/Ui/Data/Table/Column/Link.tpl.php b/Resource/Ice/Ui/Data/Table/Column/Link.tpl.php index b1366158..058cbfb5 100644 --- a/Resource/Ice/Ui/Data/Table/Column/Link.tpl.php +++ b/Resource/Ice/Ui/Data/Table/Column/Link.tpl.php @@ -1,2 +1,4 @@ -Изменить \ No newline at end of file +onclick="" + class="" + style=""> diff --git a/Source/Ice/Action/Data.php b/Source/Ice/Action/Data.php index 0f081097..2edf524b 100644 --- a/Source/Ice/Action/Data.php +++ b/Source/Ice/Action/Data.php @@ -84,13 +84,16 @@ public function run(array $input) /** @var Ui_Data $data */ $data = $input['data']; + /** @var Ui_Data $dataClass */ + $dataClass = get_class($data); + $rows = []; $columns = $data->getColumns(); $filterFields = $data->getFilterFields(); - $rows[] = Php::getInstance()->fetch(Ui_Data::getClass('Ice:Table_Row_Header'), ['columns' => empty($filterFields) ? array_intersect_key($columns, Arrays::column($columns, 'name')) : array_intersect_key($columns, array_intersect(Arrays::column($columns, 'name'), $filterFields))]); + $rows[] = Php::getInstance()->fetch(Ui_Data::getClass($dataClass . '_' . $data->getRowHeaderTemplate()), ['columns' => empty($filterFields) ? array_intersect_key($columns, Arrays::column($columns, 'name')) : array_intersect_key($columns, array_intersect(Arrays::column($columns, 'name'), $filterFields))]); foreach ($data->getRows() as $row) { $rowResult = []; @@ -99,10 +102,21 @@ public function run(array $input) if (!empty($filterFields) && !in_array($column['name'], $filterFields)) { continue; } - $rowResult[] = Php::getInstance()->fetch(Ui_Data::getClass($column['template']), ['value' => $row[$column['name']], 'scheme' => $column]); + + if (isset($column['options']['href']) && isset($column['options']['href_ext'])) { + $column['options']['href'] .= implode('/', array_intersect_key($row, array_flip((array) $column['options']['href_ext']))); + } + + $rowResult[] = Php::getInstance()->fetch( + Ui_Data::getClass($dataClass . '_' . $column['template']), + [ + 'value' => array_key_exists($column['name'], $row) ? $row[$column['name']] : $column['name'], + 'options' => $column['options'] + ] + ); } - $rows[] = Php::getInstance()->fetch(Ui_Data::getClass('Ice:Table_Row_Data'), ['columns' => $rowResult]); + $rows[] = Php::getInstance()->fetch(Ui_Data::getClass($dataClass . '_' . $data->getRowDataTemplate()), ['columns' => $rowResult]); } return ['title' => $data->getTitle(), 'rows' => $rows]; diff --git a/Source/Ice/App.php b/Source/Ice/App.php index b00cd65e..f3435026 100644 --- a/Source/Ice/App.php +++ b/Source/Ice/App.php @@ -86,7 +86,7 @@ public static function run() App::getResponse()->send(); Profiler::setPoint(__CLASS__, $startTime, $startMemory); - Logger::fb('running finished - ' . Profiler::getReport(__CLASS__), 'application', 'LOG'); + Logger::fb('running finished - ' . Profiler::getReport(__CLASS__), 'ice application', 'LOG'); Logger::renderLog(); diff --git a/Source/Ice/Core/Action.php b/Source/Ice/Core/Action.php index b9f8e6a7..30361f1c 100644 --- a/Source/Ice/Core/Action.php +++ b/Source/Ice/Core/Action.php @@ -231,7 +231,7 @@ public static function getInput(array $data = []) 'cli' => Data_Provider_Cli::DEFAULT_DATA_PROVIDER_KEY, ]; - $params = array_merge(self::getConfig()->gets('input', false), ['actions', 'template']); + $params = array_merge(self::getConfig()->gets('input', false), ['actions', 'template', 'layout']); $input = []; foreach ($params as $name => $param) { @@ -253,12 +253,20 @@ public static function getInput(array $data = []) $dataProviderKey = $dataProviderKeyMap[$dataProviderKey]; } - $input[$name] = $dataProviderKey == 'default' - ? (isset($data[$name]) ? $data[$name] : null) - : Data_Provider::getInstance($dataProviderKey)->get($name); + if ($dataProviderKey == 'default') { + if (array_key_exists($name, $data)) { + $input[$name] = $data[$name]; + } + + continue; + } + + $input[$name] = Data_Provider::getInstance($dataProviderKey)->get($name); } - $input[$name] = Action::getInputParam($name, $input[$name], $param); + if (array_key_exists($name, $input)) { + $input[$name] = Action::getInputParam($name, $input[$name], $param); + } } if (isset($input['redirectUrl'])) { @@ -454,27 +462,30 @@ protected function addAction(array $action) private function initView(&$input) { + /** @var Action $actionClass */ + $actionClass = get_class($this); + $view = $this->getView(); - if (isset($input['template'])) { + if (array_key_exists('template', $input)) { $view->setTemplate($input['template']); unset($input['template']); } else { - $view->setTemplate(null); + $view->setTemplate($actionClass::getConfig()->get('view/template', false)); } - if (isset($input['viewRenderClass'])) { + if (array_key_exists('viewRenderClass', $input)) { $view->setViewRenderClass($input['viewRenderClass']); unset($input['viewRenderClass']); } else { - $view->setViewRenderClass(null); + $view->setViewRenderClass($actionClass::getConfig()->get('view/viewRenderClass', false)); } - if (isset($input['layout'])) { + if (array_key_exists('layout', $input)) { $view->setLayout($input['layout']); unset($input['layout']); } else { - $view->setLayout(null); + $view->setLayout($actionClass::getConfig()->get('view/layout', false)); } } diff --git a/Source/Ice/Core/Environment.php b/Source/Ice/Core/Environment.php index 3eae79f3..a28919be 100644 --- a/Source/Ice/Core/Environment.php +++ b/Source/Ice/Core/Environment.php @@ -76,11 +76,15 @@ public static function getInstance($environmentName = Environment::PRODUCTION, $ } } - Logger::fb('init environment - ' . $environmentName, 'bootstrap', 'LOG'); + Logger::fb('init environment - ' . $environmentName, 'ice bootstrap', 'LOG'); return Environment::$_instance = Environment::create($environmentName, $environment); } + public static function isLoaded() { + return Environment::$_instance; + } + /** * Check to current environment is development * diff --git a/Source/Ice/Core/Ui/Data.php b/Source/Ice/Core/Ui/Data.php index 2d17d530..ddd46d84 100644 --- a/Source/Ice/Core/Ui/Data.php +++ b/Source/Ice/Core/Ui/Data.php @@ -18,6 +18,8 @@ abstract class Ui_Data extends Container private $_title = 'Title'; private $columns = []; private $rows = []; + private $_rowHeaderTemplate = 'Row_Header'; + private $_rowDataTemplate = 'Row_Data'; private $key = null; @@ -69,7 +71,7 @@ protected static function create($key) protected static function getDefaultClassKey() { - return 'Ice:Simple'; + return 'Ice:Table'; } protected static function getDefaultKey() @@ -112,22 +114,22 @@ public function getKey() * * @param $columnName * @param $columnTitle - * @param null $option + * @param null $options * @param string $template * @return Ui_Data */ - public function text($columnName, $columnTitle, $option = null, $template = 'Ice:Table_Column_Column') + public function text($columnName, $columnTitle, $options = null, $template = 'Column_Column') { - return $this->addColumn($columnName, 'column', $columnTitle, $option, $template); + return $this->addColumn($columnName, 'column', $columnTitle, $options, $template); } - protected function addColumn($columnName, $columnType, $columnTitle, $option, $template) + protected function addColumn($columnName, $columnType, $columnTitle, $options, $template) { $this->columns[] = [ 'name' => $columnName, 'type' => $columnType, 'title' => $columnTitle, - 'option' => $option, + 'options' => $options, 'template' => $template ]; @@ -160,13 +162,13 @@ public function addFilterFields(array $filterFields) * * @param $columnName * @param $columnTitle - * @param null $option + * @param null $options * @param string $template - * @return Data + * @return Ui_Data */ - public function link($columnName, $columnTitle, $option = null, $template = 'Ice:Table_Column_Link') + public function link($columnName, $columnTitle, $options = null, $template = 'Column_Link') { - return $this->addColumn($columnName, 'link', $columnTitle, $option, $template); + return $this->addColumn($columnName, 'link', $columnTitle, $options, $template); } /** @@ -174,13 +176,13 @@ public function link($columnName, $columnTitle, $option = null, $template = 'Ice * * @param $columnName * @param $columnTitle - * @param null $option + * @param null $options * @param string $template - * @return Data + * @return Ui_Data */ - public function button($columnName, $columnTitle, $option = null, $template = 'Ice:Table_Column_Button') + public function button($columnName, $columnTitle, $options = null, $template = 'Column_Button') { - return $this->addColumn($columnName, 'button', $columnTitle, $option, $template); + return $this->addColumn($columnName, 'button', $columnTitle, $options, $template); } /** @@ -208,4 +210,42 @@ public function getTitle() { return $this->_title; } + + /** + * @return string + */ + public function getRowHeaderTemplate() + { + return $this->_rowHeaderTemplate; + } + + /** + * @param string $rowHeaderTemplate + * @return Ui_Data + */ + public function setRowHeaderTemplate($rowHeaderTemplate) + { + $this->_rowHeaderTemplate = $rowHeaderTemplate; + return $this; + } + + /** + * @return string + */ + public function getRowDataTemplate() + { + return $this->_rowDataTemplate; + } + + /** + * @param string $rowDataTemplate + * @return Ui_Data + */ + public function setRowDataTemplate($rowDataTemplate) + { + $this->_rowDataTemplate = $rowDataTemplate; + return $this; + } + + } \ No newline at end of file diff --git a/Source/Ice/Core/View.php b/Source/Ice/Core/View.php index 16a336bc..e825d1c6 100644 --- a/Source/Ice/Core/View.php +++ b/Source/Ice/Core/View.php @@ -231,12 +231,8 @@ public function setTemplate($template) $actionClass = $this->_actionClass; if ($template === null) { - $template = $actionClass::getConfig()->get('view/template', false); - - if ($template === null) { - $this->_template = $actionClass; - return; - } + $this->_template = $actionClass; + return; } if ($template === '') { @@ -257,11 +253,6 @@ public function setTemplate($template) */ public function setViewRenderClass($viewRenderClass) { - if (!$viewRenderClass) { - $actionClass = $this->_actionClass; - $viewRenderClass = $actionClass::getConfig()->get('view/viewRenderClass', false); - } - $this->_viewRenderClass = View_Render::getClass($viewRenderClass); } @@ -270,15 +261,10 @@ public function setViewRenderClass($viewRenderClass) */ public function setLayout($layout) { - $actionClass = $this->_actionClass; - if ($layout === null) { - $layout = $actionClass::getConfig()->get('view/layout', false); + $this->_layout = 'div.' . $this->getActionName(); - if ($layout === null) { - $this->_layout = 'div.' . $this->getActionName(); - return; - } + return; } if ($layout === '') { @@ -304,7 +290,8 @@ public function getData() return $this->getResult()['data']; } - public function getActionName() { + public function getActionName() + { return $this->getResult()['actionName']; } } \ No newline at end of file diff --git a/Source/Ice/Data/Provider/Cacher.php b/Source/Ice/Data/Provider/Cacher.php index fb298344..2abc7fc6 100644 --- a/Source/Ice/Data/Provider/Cacher.php +++ b/Source/Ice/Data/Provider/Cacher.php @@ -12,6 +12,7 @@ use Ice\Core\Cache; use Ice\Core\Cacheable; use Ice\Core\Data_Provider; +use Ice\Core\Environment; use Ice\Core\Exception; /** @@ -228,15 +229,13 @@ public function getKeys($pattern = null) */ protected function connect(&$connection) { -// $environment = Environment::getInstance(); -// -// if (!$environment || $environment->isDevelopment()) { -// return $connection = Registry::getInstance($this->getKey(), $this->getIndex()); -// } -// -// if (!$environment->isProduction()) { -// return $connection = File::getInstance($this->getKey(), $this->getIndex()); -// } + if (!Environment::isLoaded() || Environment::getInstance()->isDevelopment()) { + return $connection = Registry::getInstance($this->getKey(), $this->getIndex()); + } + + if (!Environment::getInstance()->isProduction()) { + return $connection = File::getInstance($this->getKey(), $this->getIndex()); + } /** @var Data_Provider $dataProviderClass */ $dataProviderClass = class_exists('Redis', false) diff --git a/Source/Ice/Data/Provider/Repository.php b/Source/Ice/Data/Provider/Repository.php index 1808f5e3..7f9f7288 100644 --- a/Source/Ice/Data/Provider/Repository.php +++ b/Source/Ice/Data/Provider/Repository.php @@ -10,6 +10,7 @@ namespace Ice\Data\Provider; use Ice\Core\Data_Provider; +use Ice\Core\Environment; use Ice\Core\Exception; /** @@ -202,15 +203,13 @@ public function getKeys($pattern = null) */ protected function connect(&$connection) { -// $environment = Environment::getInstance(); -// -// if (!$environment || $environment->isDevelopment()) { -// return $connection = Registry::getInstance($this->getKey(), $this->getIndex()); -// } -// -// if (!$environment->isProduction()) { -// return $connection = File::getInstance($this->getKey(), $this->getIndex()); -// } + if (!Environment::isLoaded() || Environment::getInstance()->isDevelopment()) { + return $connection = Registry::getInstance($this->getKey(), $this->getIndex()); + } + + if (!Environment::getInstance()->isProduction()) { + return $connection = File::getInstance($this->getKey(), $this->getIndex()); + } /** @var Data_Provider $dataProviderClass */ $dataProviderClass = function_exists('apc_store') diff --git a/Source/Ice/Ui/Data/Simple.php b/Source/Ice/Ui/Data/Table.php similarity index 64% rename from Source/Ice/Ui/Data/Simple.php rename to Source/Ice/Ui/Data/Table.php index 539fb7bb..36162331 100644 --- a/Source/Ice/Ui/Data/Simple.php +++ b/Source/Ice/Ui/Data/Table.php @@ -4,6 +4,6 @@ use Ice\Core\Ui_Data; -class Simple extends Ui_Data { +class Table extends Ui_Data { } \ No newline at end of file