ILIAS  release_8 Revision v8.24
class.ilUserDefinedData.php
Go to the documentation of this file.
1<?php
2
24{
25 public ?ilDBInterface $db = null;
26 public array $user_data = array(); // Missing array type.
27 public ?int $usr_id = null;
28
29 public function __construct(int $a_usr_id)
30 {
31 global $DIC;
32
33 $ilDB = $DIC['ilDB'];
34
35 $this->db = $ilDB;
36 $this->usr_id = $a_usr_id;
37
38 $this->__read();
39 }
40
44 public static function lookupData(array $a_user_ids, array $a_field_ids): array // Missing array type.
45 {
46 global $DIC;
47
48 $ilDB = $DIC['ilDB'];
49
50 $query = "SELECT * FROM udf_text " .
51 "WHERE " . $ilDB->in('usr_id', $a_user_ids, false, 'integer') . ' ' .
52 'AND ' . $ilDB->in('field_id', $a_field_ids, false, 'integer');
53 $res = $ilDB->query($query);
54
55 $udfd = array();
56 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
57 $udfd[$row['usr_id']][$row['field_id']] = $row['value'];
58 }
59
61 foreach ($def_helper->getActivePlugins() as $plugin) {
62 foreach ($plugin->lookupUserData($a_user_ids, $a_field_ids) as $user_id => $usr_data) {
63 foreach ($usr_data as $field_id => $value) {
64 $udfd[$user_id][$field_id] = $value;
65 }
66 }
67 }
68
69 return $udfd;
70 }
71
72 public function getUserId(): int
73 {
74 return $this->usr_id;
75 }
76
77 public function set(string $a_field, string $a_value): void
78 {
79 $this->user_data[$a_field] = $a_value;
80 }
81
82 public function get(string $a_field): string
83 {
84 return $this->user_data[$a_field] ?? '';
85 }
86
87 public function getAll(): array // Missing array type.
88 {
89 return $this->user_data;
90 }
91
92 public function update(): void
93 {
94 global $DIC;
95
96 $ilDB = $DIC['ilDB'];
97
99
100 foreach ($udf_obj->getDefinitions() as $definition) {
101 if ($definition["field_type"] == UDF_TYPE_WYSIWYG) {
102 $ilDB->replace(
103 "udf_clob",
104 array(
105 "usr_id" => array("integer", $this->getUserId()),
106 "field_id" => array("integer", $definition['field_id'])),
107 array(
108 "value" => array("clob", $this->get("f_" . $definition['field_id']))
109 )
110 );
111 } else {
112 $ilDB->replace(
113 "udf_text",
114 array(
115 "usr_id" => array("integer", $this->getUserId()),
116 "field_id" => array("integer", $definition['field_id'])),
117 array(
118 "value" => array("text", $this->get("f_" . $definition['field_id']))
119 )
120 );
121 }
122 }
123 }
124
125 public static function deleteEntriesOfUser(int $a_user_id): void
126 {
127 global $DIC;
128
129 $ilDB = $DIC['ilDB'];
130
131 $ilDB->manipulate(
132 "DELETE FROM udf_text WHERE "
133 . " usr_id = " . $ilDB->quote($a_user_id, "integer")
134 );
135 $ilDB->manipulate(
136 "DELETE FROM udf_clob WHERE "
137 . " usr_id = " . $ilDB->quote($a_user_id, "integer")
138 );
139 }
140
144 public static function deleteEntriesOfField(int $a_field_id): void
145 {
146 global $DIC;
147
148 $ilDB = $DIC['ilDB'];
149
150 $ilDB->manipulate(
151 "DELETE FROM udf_text WHERE "
152 . " field_id = " . $ilDB->quote($a_field_id, "integer")
153 );
154 $ilDB->manipulate(
155 "DELETE FROM udf_clob WHERE "
156 . " field_id = " . $ilDB->quote($a_field_id, "integer")
157 );
158 }
159
163 public static function deleteFieldValue(
164 int $a_field_id,
165 string $a_value
166 ): void {
167 global $DIC;
168
169 $ilDB = $DIC['ilDB'];
170
171 $ilDB->manipulate(
172 "UPDATE udf_text SET value = " . $ilDB->quote("", "text") . " WHERE "
173 . " field_id = " . $ilDB->quote($a_field_id, "integer")
174 . " AND value = " . $ilDB->quote($a_value, "text")
175 );
176 }
177
178 public function toXML(): string
179 {
180 $xml_writer = new ilXmlWriter();
181
182 $this->addToXML($xml_writer);
183
184 return $xml_writer->xmlDumpMem(false);
185 }
186
190 public function addToXML(ilXmlWriter $xml_writer): void
191 {
193
194 foreach ($udf_obj->getDefinitions() as $definition) {
195 if ($definition["export"] != false) {
196 $xml_writer->xmlElement(
197 'UserDefinedField',
198 array('Id' => $definition['il_id'],
199 'Name' => $definition['field_name']),
200 (string) ($this->user_data['f_' . (int) $definition['field_id']] ?? '')
201 );
202 }
203 }
204 }
205
206 // Private
207 public function __read(): void
208 {
209 $this->user_data = array();
210 $query = "SELECT * FROM udf_text " .
211 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer');
212 $res = $this->db->query($query);
213 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
214 $this->user_data["f_" . $row["field_id"]] = $row["value"];
215 }
216 $query = "SELECT * FROM udf_clob " .
217 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer');
218 $res = $this->db->query($query);
219 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
220 $this->user_data["f_" . $row["field_id"]] = $row["value"];
221 }
222 }
223}
const UDF_TYPE_WYSIWYG
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addToXML(ilXmlWriter $xml_writer)
add user defined field data to xml (using usr dtd)
static deleteFieldValue(int $a_field_id, string $a_value)
Delete data of particular value of a (selection) field.
static deleteEntriesOfUser(int $a_user_id)
static lookupData(array $a_user_ids, array $a_field_ids)
Lookup data.
static deleteEntriesOfField(int $a_field_id)
Delete data of particular field.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query