ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
44  $this->session_id = $a_sess_id;
45  }
46  else
47  {
48  $this->session_id = session_id();
49  }
50  }

Member Function Documentation

◆ destroySession()

static ilSessionIStorage::destroySession (   $a_session_id)
static

Destroy session(s).

This is called by ilSession->destroy

Parameters

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

References $ilDB.

Referenced by ilSession\_destroy().

109  {
110  global $ilDB;
111 
112  if(!is_array($a_session_id))
113  {
114  $q = "DELETE FROM usr_sess_istorage WHERE session_id = ".
115  $ilDB->quote($a_session_id, "text");
116  }
117  else
118  {
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 $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 81 of file class.ilSessionIStorage.php.

References $component_id, and $ilDB.

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

◆ set()

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, $ilDB, and array.

58  {
59  global $ilDB;
60 
61  if (!is_array(self::$values[$this->component_id]))
62  {
63  self::$values[$this->component_id] = array();
64  }
65  self::$values[$this->component_id][$a_key] = $a_val;
66  $ilDB->replace("usr_sess_istorage",
67  array(
68  "session_id" => array("text", $this->session_id),
69  "component_id" => array("text", $this->component_id),
70  "vkey" => array("text", $a_key)
71  ),
72  array("value" => array("text", $a_val))
73  );
74  }
Create styles array
The data for the language used.
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: