diff --git a/application/helpers/session_helper.php b/application/helpers/session_helper.php new file mode 100644 index 000000000..e74468896 --- /dev/null +++ b/application/helpers/session_helper.php @@ -0,0 +1,88 @@ +_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 } /**