ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilSessionIStorage Class Reference

Session based immediate storage. More...

+ Collaboration diagram for ilSessionIStorage:

Public Member Functions

 __construct ($a_component_id, $a_sess_id="")
 Constructor. More...
 
 set ($a_key, $a_val)
 Set a value. More...
 
 get ($a_key)
 Get a value for a key. More...
 

Static Public Member Functions

static destroySession ($a_session_id)
 Destroy session(s). More...
 

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

◆ __construct()

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.

40  {
41  $this->component_id = $a_component_id;
42  if ($a_sess_id != "") {
43  $this->session_id = $a_sess_id;
44  } else {
45  $this->session_id = session_id();
46  }
47  }

Member Function Documentation

◆ destroySession()

static ilSessionIStorage::destroySession (   $a_session_id)
static

Destroy session(s).

This is called by ilSession->destroy

Parameters

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

References $DIC, and $ilDB.

Referenced by ilSession\_destroy().

110  {
111  global $DIC;
112 
113  $ilDB = $DIC['ilDB'];
114 
115  if (!is_array($a_session_id)) {
116  $q = "DELETE FROM usr_sess_istorage WHERE session_id = " .
117  $ilDB->quote($a_session_id, "text");
118  } else {
119  $q = "DELETE FROM usr_sess_istorage WHERE " .
120  $ilDB->in("session_id", $a_session_id, "", "text");
121  }
122 
123  $ilDB->manipulate($q);
124  }
global $DIC
Definition: saml.php:7
global $ilDB
+ Here is the caller graph for this function:

◆ get()

ilSessionIStorage::get (   $a_key)

Get a value for a key.

Returns
string $a_key key

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

References $component_id, $DIC, $ilDB, and $values.

81  {
82  global $DIC;
83 
84  $ilDB = $DIC['ilDB'];
85 
86  if (is_array(self::$values[$this->component_id]) &&
87  isset(self::$values[$this->component_id][$a_key])) {
88  return self::$values[$this->component_id][$a_key];
89  }
90 
91  $set = $ilDB->query(
92  "SELECT value FROM usr_sess_istorage " .
93  " WHERE session_id = " . $ilDB->quote($this->session_id, "text") .
94  " AND component_id = " . $ilDB->quote($this->component_id, "text") .
95  " AND vkey = " . $ilDB->quote($a_key, "text")
96  );
97  $rec = $ilDB->fetchAssoc($set);
98  self::$values[$this->component_id][$a_key] = $rec["value"];
99 
100  return $rec["value"];
101  }
global $DIC
Definition: saml.php:7
$values
global $ilDB

◆ set()

ilSessionIStorage::set (   $a_key,
  $a_val 
)

Set a value.

Parameters
string$a_valvalue

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

References $component_id, $DIC, $ilDB, and $values.

55  {
56  global $DIC;
57 
58  $ilDB = $DIC['ilDB'];
59 
60  if (!is_array(self::$values[$this->component_id])) {
62  }
63  self::$values[$this->component_id][$a_key] = $a_val;
64  $ilDB->replace(
65  "usr_sess_istorage",
66  array(
67  "session_id" => array("text", $this->session_id),
68  "component_id" => array("text", $this->component_id),
69  "vkey" => array("text", $a_key)
70  ),
71  array("value" => array("text", $a_val))
72  );
73  }
global $DIC
Definition: saml.php:7
$values
global $ilDB

Field Documentation

◆ $component_id

ilSessionIStorage::$component_id = ""
protected

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

Referenced by get(), and set().

◆ $session_id

ilSessionIStorage::$session_id = ""
protected

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

◆ $values

ilSessionIStorage::$values = array()
staticprotected

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


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