ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTableTemplatesStorage.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  protected ilDBInterface $db;
26 
27  public function __construct()
28  {
29  global $DIC;
30  $this->db = $DIC->database();
31  }
32 
36  public function store(
37  string $a_context,
38  int $a_user_id,
39  string $a_name,
40  array $a_state
41  ): void {
42  $ilDB = $this->db;
43 
44  if ($a_context == "" || $a_name == "") {
45  return;
46  }
47 
48  $ilDB->replace(
49  "table_templates",
50  array(
51  "name" => array("text", $a_name),
52  "user_id" => array("integer", $a_user_id),
53  "context" => array("text", $a_context)),
54  array(
55  "value" => array("text", serialize($a_state))
56  )
57  );
58  }
59 
63  public function load(
64  string $a_context,
65  int $a_user_id,
66  string $a_name
67  ): ?array {
68  $ilDB = $this->db;
69 
70  if ($a_context == "" || $a_name == "") {
71  return null;
72  }
73 
74  $set = $ilDB->query(
75  "SELECT value FROM table_templates " .
76  " WHERE name = " . $ilDB->quote($a_name, "text") .
77  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
78  " AND context = " . $ilDB->quote($a_context, "text")
79  );
80  $rec = $ilDB->fetchAssoc($set);
81  return unserialize($rec["value"]);
82  }
83 
87  public function delete(
88  string $a_context,
89  int $a_user_id,
90  string $a_name
91  ): void {
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 
109  public function getNames(
110  string $a_context,
111  int $a_user_id
112  ): array {
113  $ilDB = $this->db;
114 
115  if ($a_context == "") {
116  return [];
117  }
118 
119  $set = $ilDB->query(
120  "SELECT name FROM table_templates " .
121  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
122  " AND context = " . $ilDB->quote($a_context, "text") .
123  " ORDER BY name"
124  );
125  $result = array();
126  while ($rec = $ilDB->fetchAssoc($set)) {
127  $result[] = $rec["name"];
128  }
129  return $result;
130  }
131 }
store(string $a_context, int $a_user_id, string $a_name, array $a_state)
Store table template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
getNames(string $a_context, int $a_user_id)
List templates.
load(string $a_context, int $a_user_id, string $a_name)
Get table template.