ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTableTemplatesStorage.php
Go to the documentation of this file.
1 <?php
2 
27 {
28  protected ilDBInterface $db;
29 
30  public function __construct()
31  {
32  global $DIC;
33  $this->db = $DIC->database();
34  }
35 
39  public function store(
40  string $a_context,
41  int $a_user_id,
42  string $a_name,
43  array $a_state
44  ): void {
45  $ilDB = $this->db;
46 
47  if ($a_context == "" || $a_name == "") {
48  return;
49  }
50 
51  $ilDB->replace(
52  "table_templates",
53  array(
54  "name" => array("text", $a_name),
55  "user_id" => array("integer", $a_user_id),
56  "context" => array("text", $a_context)),
57  array(
58  "value" => array("text", serialize($a_state))
59  )
60  );
61  }
62 
66  public function load(
67  string $a_context,
68  int $a_user_id,
69  string $a_name
70  ): ?array {
71  $ilDB = $this->db;
72 
73  if ($a_context == "" || $a_name == "") {
74  return null;
75  }
76 
77  $set = $ilDB->query(
78  "SELECT value FROM table_templates " .
79  " WHERE name = " . $ilDB->quote($a_name, "text") .
80  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
81  " AND context = " . $ilDB->quote($a_context, "text")
82  );
83  $rec = $ilDB->fetchAssoc($set);
84  return unserialize((string) $rec["value"]);
85  }
86 
90  public function delete(
91  string $a_context,
92  int $a_user_id,
93  string $a_name
94  ): void {
95  $ilDB = $this->db;
96 
97  if ($a_context == "" || $a_name == "") {
98  return;
99  }
100 
101  $ilDB->query(
102  "DELETE FROM table_templates " .
103  " WHERE name = " . $ilDB->quote($a_name, "text") .
104  " AND user_id = " . $ilDB->quote($a_user_id, "integer") .
105  " AND context = " . $ilDB->quote($a_context, "text")
106  );
107  }
108 
112  public function getNames(
113  string $a_context,
114  int $a_user_id
115  ): array {
116  $ilDB = $this->db;
117 
118  if ($a_context == "") {
119  return [];
120  }
121 
122  $set = $ilDB->query(
123  "SELECT name FROM table_templates " .
124  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
125  " AND context = " . $ilDB->quote($a_context, "text") .
126  " ORDER BY name"
127  );
128  $result = array();
129  while ($rec = $ilDB->fetchAssoc($set)) {
130  $result[] = $rec["name"];
131  }
132  return $result;
133  }
134 }
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.