- Placed a timestamp in the filter/table widget session

- Added a constant as fallback timeout for filter/table widget
- Added a parameter to specify the filter/table widget life time
- Filter/table widget on load removes expired filter/table widgets from session
This commit is contained in:
Paolo
2019-11-28 16:51:38 +01:00
parent 819face9f9
commit c2bc48d320
4 changed files with 189 additions and 77 deletions
+54 -23
View File
@@ -7,8 +7,10 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
*/
class FilterWidgetLib
{
// Session parameters names
const SESSION_NAME = 'FHC_FILTER_WIDGET'; // Filter session name
// FilterWidget session name
const SESSION_NAME = 'FHC_FILTER_WIDGET';
// Session elements
const SESSION_FILTER_NAME = 'filterName';
const SESSION_FIELDS = 'fields';
const SESSION_SELECTED_FIELDS = 'selectedFields';
@@ -17,13 +19,19 @@ class FilterWidgetLib
const SESSION_CHECKBOXES = 'checkboxes';
const SESSION_FILTERS = 'filters';
const SESSION_METADATA = 'datasetMetadata';
const SESSION_DATASET = 'dataset';
const SESSION_ROW_NUMBER = 'rowNumber';
const SESSION_RELOAD_DATASET = 'reloadDataset';
const SESSION_TIMEOUT = 'sessionTimeout';
// Session dataset elements
const SESSION_DATASET = 'dataset';
const SESSION_DATASET_RELOAD = 'reloadDataset';
const SESSION_DATASET_REPRESENTATION = 'datasetRepresentation';
const SESSION_DATASET_REP_OPTIONS = 'datasetRepresentationOptions';
const SESSION_DATASET_REP_FIELDS_DEFS = 'datasetRepresentationFieldsDefinitions';
// Default session timeout
const SESSION_DEFAULT_TIMEOUT = 30;
// Alias for the dynamic table used to retrieve the dataset
const DATASET_TABLE_ALIAS = 'datasetFilterTable';
@@ -33,16 +41,16 @@ class FilterWidgetLib
// ...to identify a single filter widget in the DB
const FILTER_ID = 'filter_id';
const APP_PARAMETER = 'app';
const DATASET_NAME_PARAMETER = 'datasetName';
const FILTER_KURZBZ_PARAMETER = 'filterKurzbz';
const DATASET_RELOAD_PARAMETER = 'reloadDataset';
const APP = 'app';
const DATASET_NAME = 'datasetName';
const FILTER_KURZBZ = 'filterKurzbz';
const DATASET_RELOAD = 'reloadDataset';
// ...to specify permissions that are needed to use this FilterWidget
const REQUIRED_PERMISSIONS_PARAMETER = 'requiredPermissions';
const REQUIRED_PERMISSIONS = 'requiredPermissions';
// ...stament to retrieve the dataset
const QUERY_PARAMETER = 'query';
const QUERY = 'query';
// ...to specify more columns or aliases for them
const ADDITIONAL_COLUMNS = 'additionalColumns';
@@ -131,7 +139,7 @@ class FilterWidgetLib
// Gets the required permissions from the session if they are not provided as parameter
$rq = $requiredPermissions;
if ($rq == null) $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS_PARAMETER);
if ($rq == null) $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS);
return $this->_ci->permissionlib->hasAtLeastOne($rq, self::PERMISSION_FILTER_METHOD, self::PERMISSION_TYPE);
}
@@ -179,6 +187,29 @@ class FilterWidgetLib
setSessionElement(self::SESSION_NAME, $this->_filterUniqueId, $session); // stores the single value
}
/**
*
*/
public function dropExpiredFilterWidgets()
{
// Loads the session for all the filter widgets
$filterWidgetsSession = getSession(self::SESSION_NAME);
// If something is present in session
if ($filterWidgetsSession != null)
{
// Loops in the session for all the filter widgets
foreach ($filterWidgetsSession as $filterWidget => $filterWidgetData)
{
// If this filter widget is not the currrent used filter widget and the it is expired...
if ($this->_filterUniqueId != $filterWidget && $filterWidgetData[self::SESSION_TIMEOUT] <= time())
{
cleanSessionElement(self::SESSION_NAME, $filterWidget); // ...remove it
}
}
}
}
/**
* Loads the definition data from DB for a filter widget
*/
@@ -471,7 +502,7 @@ class FilterWidgetLib
// Write changes into the session
$this->setSessionElement(self::SESSION_FILTERS, $filters);
$this->setSessionElement(self::SESSION_RELOAD_DATASET, true); // the dataset must be reloaded
$this->setSessionElement(self::SESSION_DATASET_RELOAD, true); // the dataset must be reloaded
$removeAppliedFilter = true;
}
@@ -523,7 +554,7 @@ class FilterWidgetLib
// Write changes into the session
$this->setSessionElement(self::SESSION_FILTERS, $filters);
$this->setSessionElement(self::SESSION_RELOAD_DATASET, true); // the dataset must be reloaded
$this->setSessionElement(self::SESSION_DATASET_RELOAD, true); // the dataset must be reloaded
$applyFilters = true;
}
@@ -537,7 +568,7 @@ class FilterWidgetLib
*/
public function reloadDataset()
{
$this->setSessionElement(self::SESSION_RELOAD_DATASET, true);
$this->setSessionElement(self::SESSION_DATASET_RELOAD, true);
}
/**
@@ -603,8 +634,8 @@ class FilterWidgetLib
// Loads the definition to check if is already present in the DB
$definition = $this->_ci->FiltersModel->loadWhere(array(
'app' => $this->getSessionElement(self::APP_PARAMETER),
'dataset_name' => $this->getSessionElement(self::DATASET_NAME_PARAMETER),
'app' => $this->getSessionElement(self::APP),
'dataset_name' => $this->getSessionElement(self::DATASET_NAME),
'description' => $descPGArray,
'person_id' => $authPersonId
));
@@ -632,8 +663,8 @@ class FilterWidgetLib
// update it
$this->_ci->FiltersModel->update(
array(
'app' => $this->getSessionElement(self::APP_PARAMETER),
'dataset_name' => $this->getSessionElement(self::DATASET_NAME_PARAMETER),
'app' => $this->getSessionElement(self::APP),
'dataset_name' => $this->getSessionElement(self::DATASET_NAME),
'description' => $descPGArray,
'person_id' => $authPersonId
),
@@ -648,8 +679,8 @@ class FilterWidgetLib
{
$this->_ci->FiltersModel->insert(
array(
'app' => $this->getSessionElement(self::APP_PARAMETER),
'dataset_name' => $this->getSessionElement(self::DATASET_NAME_PARAMETER),
'app' => $this->getSessionElement(self::APP),
'dataset_name' => $this->getSessionElement(self::DATASET_NAME),
'filter_kurzbz' => uniqid($authPersonId, true),
'description' => $descPGArray,
'person_id' => $authPersonId,
@@ -693,7 +724,7 @@ class FilterWidgetLib
public function generateFilterMenu($navigationPage)
{
// Loads the NavigationLib for the current page (given as parameter)
$this->_ci->load->library('NavigationLib', array(FilterWidgetLib::NAVIGATION_PAGE => $navigationPage));
$this->_ci->load->library('NavigationLib', array(self::NAVIGATION_PAGE => $navigationPage));
$filterMenu = null;
$currentMenu = $this->_ci->navigationlib->getSessionMenu(); // The navigation menu currently stored in session
@@ -706,7 +737,7 @@ class FilterWidgetLib
// Loads all the filters related to this page (same dataset_name and same app name)
$filters = $this->_ci->FiltersModel->getFiltersByAppDatasetName(
$session[self::APP_PARAMETER], $session[self::DATASET_NAME_PARAMETER]
$session[self::APP], $session[self::DATASET_NAME]
);
// If filters were loaded
@@ -775,7 +806,7 @@ class FilterWidgetLib
);
// Sets in the session only the element related to the filters menu
$this->_ci->navigationlib->setSessionElementMenu(FilterWidgetLib::NAV_MENU_FILTER_KEY, $filterMenu);
$this->_ci->navigationlib->setSessionElementMenu(self::NAV_MENU_FILTER_KEY, $filterMenu);
}
}
}
+45 -14
View File
@@ -9,33 +9,40 @@ class TableWidgetLib
{
const TABLE_UNIQUE_ID = 'tableUniqueId'; // TableWidget unique id
// Session parameters names
const SESSION_NAME = 'FHC_TABLE_WIDGET'; // Table session name
// TableWidget session name
const SESSION_NAME = 'FHC_TABLE_WIDGET';
// Session elements
const SESSION_FIELDS = 'fields';
const SESSION_COLUMNS_ALIASES = 'columnsAliases';
const SESSION_ADDITIONAL_COLUMNS = 'additionalColumns';
const SESSION_CHECKBOXES = 'checkboxes';
const SESSION_METADATA = 'datasetMetadata';
const SESSION_DATASET = 'dataset';
const SESSION_ROW_NUMBER = 'rowNumber';
const SESSION_RELOAD_DATASET = 'reloadDataset';
// Session dataset elements
const SESSION_DATASET = 'dataset';
const SESSION_DATASET_RELOAD = 'reloadDataset';
const SESSION_DATASET_REPRESENTATION = 'datasetRepresentation';
const SESSION_DATASET_REP_OPTIONS = 'datasetRepresentationOptions';
const SESSION_DATASET_REP_FIELDS_DEFS = 'datasetRepresentationFieldsDefinitions';
// Default session timeout
const SESSION_DEFAULT_TIMEOUT = 30;
// Alias for the dynamic table used to retrieve the dataset
const DATASET_TABLE_ALIAS = 'datasetTableWidget';
// Parameters names...
// ...to reload the dataset
const DATASET_RELOAD_PARAMETER = 'reloadDataset';
const DATASET_RELOAD = 'reloadDataset';
// ...to specify permissions that are needed to use this TableWidget
const REQUIRED_PERMISSIONS_PARAMETER = 'requiredPermissions';
const REQUIRED_PERMISSIONS = 'requiredPermissions';
// ...stament to retrieve the dataset
const QUERY_PARAMETER = 'query';
const QUERY = 'query';
// ...to specify more columns or aliases for them
const ADDITIONAL_COLUMNS = 'additionalColumns';
@@ -50,6 +57,7 @@ class TableWidgetLib
const DATASET_REPRESENTATION = 'datasetRepresentation';
const DATASET_REP_OPTIONS = 'datasetRepOptions';
const DATASET_REP_FIELDS_DEFS = 'datasetRepFieldsDefs';
const DATASET_TIMEOUT = 'datasetTimeout'; // ...and its expiring time
// Different dataset representations
const DATASET_REP_TABLESORTER = 'tablesorter';
@@ -86,13 +94,13 @@ class TableWidgetLib
// Gets the required permissions from the session if they are not provided as parameter
$rq = $requiredPermissions;
if ($rq == null) $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS_PARAMETER);
if ($rq == null) $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS);
return $this->_ci->permissionlib->hasAtLeastOne($rq, self::PERMISSION_TABLE_METHOD, self::PERMISSION_TYPE);
}
/**
* Wrapper method to the session helper funtions to retrieve the whole session for this filter
* Wrapper method to the session helper funtions to retrieve the whole session for this table widget
*/
public function getSession()
{
@@ -100,7 +108,7 @@ class TableWidgetLib
}
/**
* Wrapper method to the session helper funtions to retrieve one element from the session of this filter
* Wrapper method to the session helper funtions to retrieve one element from the session of this table widget
*/
public function getSessionElement($name)
{
@@ -115,7 +123,7 @@ class TableWidgetLib
}
/**
* Wrapper method to the session helper funtions to set the whole session for this filter
* Wrapper method to the session helper funtions to set the whole session for this table widget
*/
public function setSession($data)
{
@@ -123,7 +131,7 @@ class TableWidgetLib
}
/**
* Wrapper method to the session helper funtions to set one element in the session for this filter
* Wrapper method to the session helper funtions to set one element in the session for this table widget
*/
public function setSessionElement($name, $value)
{
@@ -135,7 +143,30 @@ class TableWidgetLib
}
/**
* Generate the query to retrieve the dataset for a filter
*
*/
public function dropExpiredTableWidgets()
{
// Loads the session for all the table widgets
$tableWidgetsSession = getSession(self::SESSION_NAME);
// If something is present in session
if ($tableWidgetsSession != null)
{
// Loops in the session for all the table widgets
foreach ($tableWidgetsSession as $tableWidget => $tableWidgetData)
{
// If this table widget is not the currrent used table widget and the it is expired...
if ($this->_tableUniqueId != $tableWidget && $tableWidgetData[self::SESSION_TIMEOUT] <= time())
{
cleanSessionElement(self::SESSION_NAME, $tableWidget); // ...remove it
}
}
}
}
/**
* Generate the query to retrieve the dataset for a table widget
*/
public function generateDatasetQuery($query)
{
@@ -177,7 +208,7 @@ class TableWidgetLib
}
/**
* Return an unique string that identify this filter widget
* Return an unique string that identify this table widget
* NOTE: The default value is the URI where the FilterWidget is called
* If the fhc_controller_id is present then is also used
*/