mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-25 08:34:29 +00:00
Changes to the FilterWidget III
This commit is contained in:
@@ -12,6 +12,9 @@ class FilterWidget extends Widget
|
||||
const WIDGET_URL_SELECT_FILTERS = 'widgets/filter/selectFilters';
|
||||
const WIDGET_URL_SAVE_FILTER = 'widgets/filter/saveFilter';
|
||||
|
||||
const DEFAULT_DATE_FORMAT = 'd.m.Y H:i:s';
|
||||
const DEFAULT_MARK_ROW_CLASS = 'text-danger';
|
||||
|
||||
// Fitler info from DB
|
||||
private $_app;
|
||||
private $_datasetName;
|
||||
@@ -26,7 +29,7 @@ class FilterWidget extends Widget
|
||||
private $_columnsAliases;
|
||||
|
||||
// To format or mark rows of the dataset
|
||||
private $_formatRaw;
|
||||
private $_formatRow;
|
||||
private $_markRow;
|
||||
|
||||
// To have a column in the GUI with checkboxes to select rows in the table
|
||||
@@ -129,7 +132,7 @@ class FilterWidget extends Widget
|
||||
$this->_query = null;
|
||||
$this->_additionalColumns = null;
|
||||
$this->_columnsAliases = null;
|
||||
$this->_formatRaw = null;
|
||||
$this->_formatRow = null;
|
||||
$this->_markRow = null;
|
||||
$this->_checkboxes = null;
|
||||
$this->_hideHeader = null;
|
||||
@@ -179,9 +182,9 @@ class FilterWidget extends Widget
|
||||
}
|
||||
|
||||
// Parameter that contains a function to format the rows of the dataset
|
||||
if (isset($args[FiltersLib::FORMAT_RAW]) && is_callable($args[FiltersLib::FORMAT_RAW]))
|
||||
if (isset($args[FiltersLib::FORMAT_ROW]) && is_callable($args[FiltersLib::FORMAT_ROW]))
|
||||
{
|
||||
$this->_formatRaw = $args[FiltersLib::FORMAT_RAW];
|
||||
$this->_formatRow = $args[FiltersLib::FORMAT_ROW];
|
||||
}
|
||||
|
||||
// Parameter that contains a function to mark in the GUI the rows of the dataset
|
||||
@@ -259,6 +262,39 @@ class FilterWidget extends Widget
|
||||
$this->filterslib->setSession(null);
|
||||
$session = null;
|
||||
}
|
||||
else // else if the filter loaded in session is the same that is being requested
|
||||
{
|
||||
// Get SESSION_RELOAD_DATASET from the session
|
||||
$reloadDataset = $this->filterslib->getElementSession(FiltersLib::SESSION_RELOAD_DATASET);
|
||||
if ($reloadDataset === true) // if it's value is very true, reload the dataset
|
||||
{
|
||||
// set as false to stop changing the dataset
|
||||
$this->filterslib->setElementSession(FiltersLib::SESSION_RELOAD_DATASET, false);
|
||||
|
||||
// Generate dataset query using filters from the session
|
||||
$datasetQuery = $this->filterslib->generateDatasetQuery(
|
||||
$this->_query,
|
||||
$this->filterslib->getElementSession(FiltersLib::SESSION_FILTERS)
|
||||
);
|
||||
|
||||
// Then retrive dataset from DB
|
||||
$dataset = $this->filterslib->getDataset($datasetQuery);
|
||||
|
||||
// Save changes into session if data are valid
|
||||
if (!isError($dataset))
|
||||
{
|
||||
$formattedDataset = $this->_formatDataset($dataset); // format the dataset using markRow and formatRow
|
||||
|
||||
// Set the new dataset and it's attributes in the session
|
||||
$this->filterslib->setElementSession(
|
||||
FiltersLib::SESSION_DATASET_METADATA,
|
||||
$this->FiltersModel->getExecutedQueryMetaData()
|
||||
);
|
||||
$this->filterslib->setElementSession(FiltersLib::SESSION_ROW_NUMBER, count($dataset->retval));
|
||||
$this->filterslib->setElementSession(FiltersLib::SESSION_DATASET, $formattedDataset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the session is empty
|
||||
@@ -277,7 +313,7 @@ class FilterWidget extends Widget
|
||||
if ($parsedFilterJson != null) // if the json is valid
|
||||
{
|
||||
// Generate dataset query
|
||||
$datasetQuery = $this->filterslib->generateDatasetQuery($this->_query, $parsedFilterJson);
|
||||
$datasetQuery = $this->filterslib->generateDatasetQuery($this->_query, $parsedFilterJson->filters);
|
||||
|
||||
// Then retrive dataset from DB
|
||||
$dataset = $this->filterslib->getDataset($datasetQuery);
|
||||
@@ -288,20 +324,27 @@ class FilterWidget extends Widget
|
||||
// Save changes into session if data are valid
|
||||
if (!isError($dataset))
|
||||
{
|
||||
$formattedDataset = $this->_formatDataset($dataset); // format the dataset using markRow and formatRow
|
||||
|
||||
// Stores an array that contains all the data useful for
|
||||
$this->filterslib->setSession(
|
||||
array(
|
||||
FiltersLib::FILTER_ID => $this->_filterId,
|
||||
FiltersLib::SESSION_FILTER_NAME => $filterName,
|
||||
FiltersLib::SESSION_FIELDS => $this->FiltersModel->getExecutedQueryListFields(),
|
||||
FiltersLib::SESSION_SELECTED_FIELDS => $this->_getColumnsNames($parsedFilterJson->columns),
|
||||
FiltersLib::SESSION_COLUMNS_ALIASES => $this->_columnsAliases,
|
||||
FiltersLib::SESSION_ADDITIONAL_COLUMNS => $this->_additionalColumns,
|
||||
FiltersLib::SESSION_CHECKBOXES => $this->_checkboxes,
|
||||
FiltersLib::SESSION_FILTERS => $parsedFilterJson->filters,
|
||||
FiltersLib::SESSION_DATASET_METADATA => $this->FiltersModel->getExecutedQueryMetaData(),
|
||||
FiltersLib::SESSION_ROW_NUMBER => count($dataset->retval),
|
||||
FiltersLib::SESSION_DATASET => $dataset->retval
|
||||
FiltersLib::FILTER_ID => $this->_filterId, //
|
||||
FiltersLib::APP_PARAMETER => $this->_app, //
|
||||
FiltersLib::DATASET_NAME_PARAMETER => $this->_datasetName, //
|
||||
|
||||
FiltersLib::SESSION_FILTER_NAME => $filterName, //
|
||||
|
||||
FiltersLib::SESSION_FIELDS => $this->FiltersModel->getExecutedQueryListFields(), //
|
||||
FiltersLib::SESSION_SELECTED_FIELDS => $this->_getColumnsNames($parsedFilterJson->columns), //
|
||||
FiltersLib::SESSION_COLUMNS_ALIASES => $this->_columnsAliases, //
|
||||
FiltersLib::SESSION_ADDITIONAL_COLUMNS => $this->_additionalColumns, //
|
||||
FiltersLib::SESSION_CHECKBOXES => $this->_checkboxes, //
|
||||
FiltersLib::SESSION_FILTERS => $parsedFilterJson->filters, //
|
||||
FiltersLib::SESSION_DATASET_METADATA => $this->FiltersModel->getExecutedQueryMetaData(), //
|
||||
FiltersLib::SESSION_ROW_NUMBER => count($dataset->retval), //
|
||||
FiltersLib::SESSION_DATASET => $formattedDataset, //
|
||||
FiltersLib::SESSION_RELOAD_DATASET => false //
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -311,6 +354,75 @@ class FilterWidget extends Widget
|
||||
// var_dump($this->filterslib->getSession());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _formatDataset($rawDataset)
|
||||
{
|
||||
$formattedDataset = null;
|
||||
|
||||
if (hasData($rawDataset) && is_array($rawDataset->retval))
|
||||
{
|
||||
$formattedDataset = array();
|
||||
|
||||
for ($rowCounter = 0; $rowCounter < count($rawDataset->retval); $rowCounter++)
|
||||
{
|
||||
$row = $rawDataset->retval[$rowCounter];
|
||||
|
||||
$formattedRow = $this->_formatRow($row);
|
||||
$formattedRow->MARK_ROW_CLASS = $this->_markRow($row);
|
||||
$formattedDataset[] = $formattedRow;
|
||||
}
|
||||
}
|
||||
|
||||
return $formattedDataset;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _formatRow($datasetRaw)
|
||||
{
|
||||
$tmpDatasetRaw = clone $datasetRaw;
|
||||
|
||||
foreach ($tmpDatasetRaw as $columnName => $columnValue)
|
||||
{
|
||||
if (is_bool($columnValue))
|
||||
{
|
||||
$tmpDatasetRaw->{$columnValue} = $columnValue === true ? 'true' : 'false';
|
||||
}
|
||||
elseif (DateTime::createFromFormat('Y-m-d G:i:s', $columnValue) !== false)
|
||||
{
|
||||
$tmpDatasetRaw->{$columnValue} = date(self::DEFAULT_DATE_FORMAT, strtotime($columnValue));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_formatRow != null)
|
||||
{
|
||||
$formatRow = $this->_formatRow;
|
||||
$tmpDatasetRaw = $formatRow($tmpDatasetRaw);
|
||||
}
|
||||
|
||||
return $tmpDatasetRaw;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _markRow($datasetRaw)
|
||||
{
|
||||
if (is_object($datasetRaw))
|
||||
{
|
||||
if ($this->_markRow != null)
|
||||
{
|
||||
$markRow = $this->_markRow;
|
||||
$class = $markRow($datasetRaw);
|
||||
}
|
||||
}
|
||||
|
||||
return !isset($class) ? '' : $class;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user