- Added helper session_helper to add utility functions to manage the php session

- Adapted the library FiltersLib to use the session_helper
This commit is contained in:
Paolo
2018-06-14 16:59:14 +02:00
parent 2cbda912e3
commit 8837083f10
2 changed files with 102 additions and 38 deletions
+14 -38
View File
@@ -68,7 +68,7 @@ class FiltersLib
const FILTER_PHRASES_CATEGORY = 'FilterWidget'; // The category used to store phrases for the FilterWidget
const FILTER_PAGE_PARAM = 'filter_page'; // Filter page parameter used to overwrite the page URI
const FILTER_PAGE_PARAM = 'filter_page'; // Filter page parameter name
private $_ci; // Code igniter instance
private $_filterUniqueId; // unique id for this filter widget
@@ -78,10 +78,12 @@ class FiltersLib
*/
public function __construct($params = null)
{
$this->_ci =& get_instance();
$this->_ci =& get_instance(); // get code igniter instance
// Loads helper message to manage returning messages
$this->_ci->load->helper('message');
// Loads helper session to manage the php session
$this->_ci->load->helper('session');
$this->_filterUniqueId = $this->_getFilterUniqueId($params); // sets the id for the related filter widget
}
@@ -90,27 +92,19 @@ class FiltersLib
// Public methods
/**
* Returns the whole session for this filter widget if found, otherwise null
* Wrapper method to the session helper funtions to retrive the whole session for this filter
*/
public function getSession()
{
$session = null;
// If it is present a session for this filter
if (isset($_SESSION[self::SESSION_NAME]) && isset($_SESSION[self::SESSION_NAME][$this->_filterUniqueId]))
{
$session = $_SESSION[self::SESSION_NAME][$this->_filterUniqueId];
}
return $session;
return getElementSession(self::SESSION_NAME, $this->_filterUniqueId);
}
/**
* Returns one element from the session of this filter widget, otherwise null
* Wrapper method to the session helper funtions to retrive one element from the session of this filter
*/
public function getElementSession($name)
{
$session = $this->getSession(); // get the whole session for this filter
$session = getElementSession(self::SESSION_NAME, $this->_filterUniqueId);
if (isset($session[$name]))
{
@@ -121,41 +115,23 @@ class FiltersLib
}
/**
* Sets the whole session for this filter widget
* Wrapper method to the session helper funtions to set the whole session for this filter
*/
public function setSession($data)
{
// If is NOT already present into the session
if (!isset($_SESSION[self::SESSION_NAME])
|| (isset($_SESSION[self::SESSION_NAME]) && !is_array($_SESSION[self::SESSION_NAME])))
{
$_SESSION[self::SESSION_NAME] = array(); // then create it
}
$_SESSION[self::SESSION_NAME][$this->_filterUniqueId] = $data; // stores data
setElementSession(self::SESSION_NAME, $this->_filterUniqueId, $data);
}
/**
* Sets one element of the session of this filter widget
* Wrapper method to the session helper funtions to set one element in the session for this filter
*/
public function setElementSession($name, $value)
{
// If is NOT already present into the session
if (!isset($_SESSION[self::SESSION_NAME])
|| (isset($_SESSION[self::SESSION_NAME]) && !is_array($_SESSION[self::SESSION_NAME])))
{
$_SESSION[self::SESSION_NAME] = array(); // then create it
}
$session = getElementSession(self::SESSION_NAME, $this->_filterUniqueId);
// If the session for this filter is NOT already present into the session
if (!isset($_SESSION[self::SESSION_NAME][$this->_filterUniqueId])
|| (isset($_SESSION[self::SESSION_NAME][$this->_filterUniqueId])
&& !is_array($_SESSION[self::SESSION_NAME][$this->_filterUniqueId])))
{
$_SESSION[self::SESSION_NAME][$this->_filterUniqueId] = array(); // then create it
}
$session[$name] = $value;
$_SESSION[self::SESSION_NAME][$this->_filterUniqueId][$name] = $value; // stores the single value
setElementSession(self::SESSION_NAME, $this->_filterUniqueId, $session); // stores the single value
}
/**