ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSessionIStorage.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
28 {
29  protected $session_id = "";
30  protected $component_id = "";
31  static protected $values = array();
32 
39  function __construct($a_component_id, $a_sess_id = "")
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  }
51 
57  function set($a_key, $a_val)
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  }
75 
81  function get($a_key)
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  }
101 
108  function destroySession($a_session_id)
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  }
125 
126 }
127 
128 ?>