ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilSessionIStorage Class Reference

Session based immediate storage. More...

+ Collaboration diagram for ilSessionIStorage:

Public Member Functions

 __construct ($a_component_id, $a_sess_id="")
 Constructor.
 set ($a_key, $a_val)
 Set a value.
 get ($a_key)
 Get a value for a key.
 destroySession ($a_session_id)
 Destroy session(s).

Protected Attributes

 $session_id = ""
 $component_id = ""

Static Protected Attributes

static $values = array()

Detailed Description

Session based immediate storage.

This class stores session based user data in the database. The difference to ilSession is that data is written immediately when the set() function is called and that this data is written "per key".

Please note that the values are limited to TEXT(1000)!

This class is needed for cases, where ajax calls should write session based data.

Since more concurrent ajax calls can be initiated by a page request, these calls may run into race conditions, if ilSession is used, since it always reads all key/value pairs at the beginning of a request and writes all of them at the end. Similar issues can appear if a page initiates additional requests by (i)frames.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 27 of file class.ilSessionIStorage.php.

Constructor & Destructor Documentation

ilSessionIStorage::__construct (   $a_component_id,
  $a_sess_id = "" 
)

Constructor.

Parameters
string$a_component_idcomponent id (e.g. "crs", "lm", ...)
string$a_sess_idsession id

Definition at line 39 of file class.ilSessionIStorage.php.

{
$this->component_id = $a_component_id;
if ($a_sess_id != "")
{
$this->session_id = $a_sess_id;
}
else
{
$this->session_id = session_id();
}
}

Member Function Documentation

ilSessionIStorage::destroySession (   $a_session_id)

Destroy session(s).

This is called by ilSession->destroy

Parameters
@return

Definition at line 108 of file class.ilSessionIStorage.php.

References $ilDB.

Referenced by ilSession\_destroy().

{
global $ilDB;
if(!is_array($a_session_id))
{
$q = "DELETE FROM usr_sess_istorage WHERE session_id = ".
$ilDB->quote($a_session_id, "text");
}
else
{
$q = "DELETE FROM usr_sess_istorage WHERE ".
$ilDB->in("session_id", $a_session_id, "", "text");
}
$ilDB->manipulate($q);
}

+ Here is the caller graph for this function:

ilSessionIStorage::get (   $a_key)

Get a value for a key.

Returns
string $a_key key

Definition at line 81 of file class.ilSessionIStorage.php.

References $component_id, and $ilDB.

{
global $ilDB;
if (is_array(self::$values[$this->component_id]) &&
isset(self::$values[$this->component_id][$a_key]))
{
return self::$values[$this->component_id][$a_key];
}
$set = $ilDB->query("SELECT value FROM usr_sess_istorage ".
" WHERE session_id = ".$ilDB->quote($this->session_id, "text").
" AND component_id = ".$ilDB->quote($this->component_id, "text").
" AND vkey = ".$ilDB->quote($a_key, "text")
);
$rec = $ilDB->fetchAssoc($set);
self::$values[$this->component_id][$a_key] = $rec["value"];
return $rec["value"];
}
ilSessionIStorage::set (   $a_key,
  $a_val 
)

Set a value.

Parameters
string$a_valvalue

Definition at line 57 of file class.ilSessionIStorage.php.

References $component_id, and $ilDB.

{
global $ilDB;
if (!is_array(self::$values[$this->component_id]))
{
self::$values[$this->component_id] = array();
}
self::$values[$this->component_id][$a_key] = $a_val;
$ilDB->replace("usr_sess_istorage",
array(
"session_id" => array("text", $this->session_id),
"component_id" => array("text", $this->component_id),
"vkey" => array("text", $a_key)
),
array("value" => array("text", $a_val))
);
}

Field Documentation

ilSessionIStorage::$component_id = ""
protected

Definition at line 30 of file class.ilSessionIStorage.php.

Referenced by get(), and set().

ilSessionIStorage::$session_id = ""
protected

Definition at line 29 of file class.ilSessionIStorage.php.

ilSessionIStorage::$values = array()
staticprotected

Definition at line 31 of file class.ilSessionIStorage.php.


The documentation for this class was generated from the following file: