Skip to content

Commit

Permalink
Quick Reports complete
Browse files Browse the repository at this point in the history
  • Loading branch information
dp committed Mar 27, 2015
1 parent c3c8877 commit 6295cf0
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 70 deletions.
6 changes: 4 additions & 2 deletions Resource/Ice/Ui/Data/Table/Column/Link.tpl.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<a href="#"
onclick="Ice_Form.modal($(this), 'Bi:Blog', <?= $value ?>, 'Ice:Form_Submit', ['blog_name'], 0, 'Add blog', '_Modal', {reRenderClosest: 'Ice:Data_Model', reRenderActionClassName: [], formFilterFields: ['blog_name'], dataFilterFields: ['blog_pk', 'blog_name']}, 'Ice:Data_Model', []); return false;">Изменить</a>
<a href="<?php if (isset($options['href'])) { ?><?= $options['href'] ?><?php } else { ?>#<?php } ?>"
<?php if (isset($options['onclick'])) { ?>onclick="<?= $options['onclick'] ?>"<?php } ?>
<?php if (!empty($options['classes'])) { ?>class="<?= implode(' ', $options['classes']) ?>"<?php } ?>
<?php if (isset($options['style'])) { ?>style="<?= $options['style'] ?>"<?php } ?>><?= $value ?></a>
20 changes: 17 additions & 3 deletions Source/Ice/Action/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Source/Ice/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
33 changes: 22 additions & 11 deletions Source/Ice/Core/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'])) {
Expand Down Expand Up @@ -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));
}
}

Expand Down
6 changes: 5 additions & 1 deletion Source/Ice/Core/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
68 changes: 54 additions & 14 deletions Source/Ice/Core/Ui/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,7 +71,7 @@ protected static function create($key)

protected static function getDefaultClassKey()
{
return 'Ice:Simple';
return 'Ice:Table';
}

protected static function getDefaultKey()
Expand Down Expand Up @@ -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
];

Expand Down Expand Up @@ -160,27 +162,27 @@ 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);
}

/**
* Build button part
*
* @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);
}

/**
Expand Down Expand Up @@ -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;
}


}
25 changes: 6 additions & 19 deletions Source/Ice/Core/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '') {
Expand All @@ -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);
}

Expand All @@ -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 === '') {
Expand All @@ -304,7 +290,8 @@ public function getData()
return $this->getResult()['data'];
}

public function getActionName() {
public function getActionName()
{
return $this->getResult()['actionName'];
}
}
17 changes: 8 additions & 9 deletions Source/Ice/Data/Provider/Cacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 8 additions & 9 deletions Source/Ice/Data/Provider/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Ice\Data\Provider;

use Ice\Core\Data_Provider;
use Ice\Core\Environment;
use Ice\Core\Exception;

/**
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

use Ice\Core\Ui_Data;

class Simple extends Ui_Data {
class Table extends Ui_Data {

}

0 comments on commit 6295cf0

Please sign in to comment.