ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTableTemplatesStorage.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
16  protected $db;
17 
18 
22  public function __construct()
23  {
24  global $DIC;
25 
26  $this->db = $DIC->database();
27  }
28 
37  public function store($a_context, $a_user_id, $a_name, array $a_state)
38  {
39  $ilDB = $this->db;
40 
41  if ($a_context == "" || $a_name == "") {
42  return;
43  }
44 
45  $ilDB->replace(
46  "table_templates",
47  array(
48  "name" => array("text", $a_name),
49  "user_id" => array("integer", $a_user_id),
50  "context" => array("text", $a_context)),
51  array(
52  "value" => array("text", serialize($a_state))
53  )
54  );
55  }
56 
65  public function load($a_context, $a_user_id, $a_name)
66  {
67  $ilDB = $this->db;
68 
69  if ($a_context == "" || $a_name == "") {
70  return;
71  }
72 
73  $set = $ilDB->query(
74  "SELECT value FROM table_templates " .
75  " WHERE name = " . $ilDB->quote($a_name, "text") .
76  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
77  " AND context = " . $ilDB->quote($a_context, "text")
78  );
79  $rec = $ilDB->fetchAssoc($set);
80  return unserialize($rec["value"]);
81  }
82 
90  public function delete($a_context, $a_user_id, $a_name)
91  {
92  $ilDB = $this->db;
93 
94  if ($a_context == "" || $a_name == "") {
95  return;
96  }
97 
98  $ilDB->query(
99  "DELETE FROM table_templates " .
100  " WHERE name = " . $ilDB->quote($a_name, "text") .
101  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
102  " AND context = " . $ilDB->quote($a_context, "text")
103  );
104  }
105 
113  public function getNames($a_context, $a_user_id)
114  {
115  $ilDB = $this->db;
116 
117  if ($a_context == "") {
118  return;
119  }
120 
121  $set = $ilDB->query(
122  "SELECT name FROM table_templates " .
123  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
124  " AND context = " . $ilDB->quote($a_context, "text") .
125  " ORDER BY name"
126  );
127  $result = array();
128  while ($rec = $ilDB->fetchAssoc($set)) {
129  $result[] = $rec["name"];
130  }
131  return $result;
132  }
133 }
$result
load($a_context, $a_user_id, $a_name)
Get table template.
store($a_context, $a_user_id, $a_name, array $a_state)
Store table template.
Saves (mostly asynchronously) user properties of tables (e.g.
global $DIC
Definition: goto.php:24
global $ilDB
getNames($a_context, $a_user_id)
List templates.