ILIAS  trunk Revision v12.0_alpha-1329-g1094ddb0c33
ilUserDataSet Class Reference
+ Inheritance diagram for ilUserDataSet:
+ Collaboration diagram for ilUserDataSet:

Public Member Functions

 __construct ()
 
 getSupportedVersions ()
 
 getXmlRecord (string $a_entity, string $a_version, array $a_set)
 Get xml record for version. More...
 
 afterXmlRecordWriting (string $a_entity, string $a_version, array $a_set)
 
 readData (string $a_entity, string $a_version, array $a_ids)
 Read data from DB. More...
 
 importRecord (string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
 Needs to be overwritten for import use case. More...
 
- Public Member Functions inherited from ilDataSet
 __construct ()
 
 init (string $a_entity, string $a_schema_version)
 Init. More...
 
 getSupportedVersions ()
 
 readData (string $a_entity, string $a_version, array $a_ids)
 Read data from DB. More...
 
 initByExporter (ilXmlExporter $xml_exporter)
 
 setImportDirectory (string $a_val)
 
 getImportDirectory ()
 
 setDSPrefix (string $a_val)
 
 getDSPrefix ()
 
 getDSPrefixString ()
 
 getDirectDataFromQuery (string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
 Get data from query.This is a standard procedure, all db field names are directly mapped to abstract fields. More...
 
 convertToLeadingUpper (string $a_str)
 Make xyz_abc a XyzAbc string. More...
 
 getXmlRepresentation (string $a_entity, string $a_schema_version, ?array $a_ids, string $a_field="", bool $a_omit_header=false, bool $a_omit_types=false)
 Get xml representation <dataset install_id="123" install_url="..."> <types entity="table_name" version="4.0.1"> <ftype name="field_1" type="text" > <ftype name="field_2" type="date" > <ftype name="field_3" type="integer" > </types> <types ...> ... </types> <set entity="table_name"> <rec> <field_1>content</field_1> <field_2>my_date</field_2> <field_3>my_number</field_3> </rec> ... </set> </dataset> More...
 
 addRecordsXml (ilXmlWriter $a_writer, array $a_prefixes, string $a_entity, string $a_schema_version, array $a_ids, ?string $a_field="")
 
 afterXmlRecordWriting (string $a_entity, string $a_version, array $a_set)
 
 getNamespaces (array &$namespaces, string $a_entity, string $a_schema_version)
 
 getXmlRecord (string $a_entity, string $a_version, array $a_set)
 Get xml record for version. More...
 
 getXmlTypes (string $a_entity, string $a_version)
 Get xml types. More...
 
 getXMLEntityName (string $a_entity, string $a_version)
 Get entity name for xml (may be overwritten) More...
 
 getXMLEntityTag (string $a_entity, string $a_schema_version)
 Get entity tag. More...
 
 setImport (ilSurveyImporter $a_val)
 
 getImport ()
 
 setCurrentInstallationId (string $a_val)
 
 getCurrentInstallationId ()
 
 importRecord (string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
 Needs to be overwritten for import use case. More...
 
 getCollection (array $record, string $entity, string $schema_version, string $field, string $value)
 
 getContainerExportConfig (array $record, string $entity, string $schema_version, string $field, string $value)
 

Data Fields

array $multi = []
 
- Data Fields inherited from ilDataSet
const DATASET_NS = 'http://www.ilias.de/Services/DataSet/ds/4_3'
 
const DATASET_NS_PREFIX = 'ds'
 
const EXPORT_NO_INST_ID = 1
 
const EXPORT_ID_ILIAS_LOCAL = 2
 
const EXPORT_ID_ILIAS_LOCAL_INVALID = 3
 
const EXPORT_ID_ILIAS_REMOTE = 4
 
const EXPORT_ID_ILIAS_REMOTE_INVALID = 5
 
const EXPORT_ID = 6
 
const EXPORT_ID_INVALID = 7
 
int $dircnt = 0
 

Protected Member Functions

 getXmlNamespace (string $a_entity, string $a_schema_version)
 
 getTypes (string $a_entity, string $a_version)
 Get (abstract) types for (abstract) field names. More...
 
- Protected Member Functions inherited from ilDataSet
 getTypes (string $a_entity, string $a_version)
 Get (abstract) types for (abstract) field names. More...
 
 getXmlNamespace (string $a_entity, string $a_schema_version)
 
 getExportDirInContainer (string $exp_dir)
 
 getIRSSContainerExportConfig (StorableResource $source_container, string $source_path, string $target_path="")
 
 getDependencies (string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
 
 createObjectExportId (string $a_type, string $a_id)
 Build ilias export id. More...
 
 parseObjectExportId (string $a_id, ?string $a_fallback_id=null)
 Parse export id. More...
 
 stripTags (array $rec, array $omit_keys=[])
 

Protected Attributes

ilUserExportConfig $export_config
 
array $temp_picture_dirs = []
 
array $users
 
- Protected Attributes inherited from ilDataSet
ILIAS ResourceStorage Services $irss
 
string $current_installation_id = ""
 
array $data = []
 
ilDBInterface $db
 
ilLogger $ds_log
 
string $import_directory = ""
 
string $entity = ""
 
string $schema_version = ""
 
string $component_export_dir = ""
 
string $ds_prefix = "ds"
 
string $version = ""
 
ilSurveyImporter $import
 
ilExport $export
 

Private Member Functions

 buildProfileFieldArrayKeyFromIdentifier (string $identifier)
 
 retrieveValueFromImportArray (array $import_array, string $key)
 
 buildFileUploadDir (string $rel_path, string $usr_id)
 

Private Attributes

Profile $user_profile
 
ilObjUser $current_user
 

Detailed Description

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 31 of file class.ilUserDataSet.php.

Constructor & Destructor Documentation

◆ __construct()

ilUserDataSet::__construct ( )

Reimplemented from ilDataSet.

Definition at line 40 of file class.ilUserDataSet.php.

41 {
42 global $DIC;
43 $this->current_user = $DIC['ilUser'];
44
46
47 $this->user_profile = LocalDIC::dic()[Profile::class];
48 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References $DIC, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ afterXmlRecordWriting()

ilUserDataSet::afterXmlRecordWriting ( string  $a_entity,
string  $a_version,
array  $a_set 
)

Reimplemented from ilDataSet.

Definition at line 178 of file class.ilUserDataSet.php.

178 : void // Missing array type.
179 {
180 if ($a_entity == "usr_profile") {
181 // cleanup temp dirs for pictures
182 $tmp_dir = $this->temp_picture_dirs[$a_set["Id"]];
183 if ($tmp_dir != "" && is_dir($tmp_dir)) {
184 ilFileUtils::delDir($tmp_dir);
185 }
186 }
187 }
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

References ilFileUtils\delDir().

+ Here is the call graph for this function:

◆ buildFileUploadDir()

ilUserDataSet::buildFileUploadDir ( string  $rel_path,
string  $usr_id 
)
private

Definition at line 401 of file class.ilUserDataSet.php.

404 : string {
405 $pic_dir = "{$this->getImportDirectory()}/"
406 . str_replace('..', '', $rel_path);
407 if ($pic_dir === '' || !is_dir($pic_dir)) {
408 return '';
409 }
410
411 $upload_file = "{$pic_dir}/usr_{$usr_id}.jpg";
412 if (!is_file($upload_file)) {
413 return '';
414 }
415
416 return $upload_file;
417 }

◆ buildProfileFieldArrayKeyFromIdentifier()

ilUserDataSet::buildProfileFieldArrayKeyFromIdentifier ( string  $identifier)
private

Definition at line 368 of file class.ilUserDataSet.php.

370 : string {
371 return $this->convertToLeadingUpper(
372 match ($identifier) {
373 'avatar' => 'picture',
374 'location' => 'latitude',
375 default => $identifier
376 }
377 );
378 }
convertToLeadingUpper(string $a_str)
Make xyz_abc a XyzAbc string.

Referenced by importRecord().

+ Here is the caller graph for this function:

◆ getSupportedVersions()

ilUserDataSet::getSupportedVersions ( )

Reimplemented from ilDataSet.

Definition at line 58 of file class.ilUserDataSet.php.

58 : array // Missing array type.
59 {
60 return ["4.3.0", "4.5.0", "5.1.0", "5.2.0", "5.3.0"];
61 }

◆ getTypes()

ilUserDataSet::getTypes ( string  $a_entity,
string  $a_version 
)
protected

Get (abstract) types for (abstract) field names.

Please note that the abstract fields/types only depend on the version! Not on a choosen representation!

Returns
array types array, e.g. array("field_1" => "text", "field_2" => "integer", ...)

Reimplemented from ilDataSet.

Definition at line 68 of file class.ilUserDataSet.php.

68 : array // Missing array type.
69 {
70 // user profile type
71 if ($a_entity == "usr_profile") {
72 switch ($a_version) {
73 case "4.3.0":
74 case "4.5.0":
75 case "5.1.0":
76 case "5.2.0":
77 case "5.3.0":
78 return [
79 "Id" => "integer",
80 "Username" => "text",
81 "Firstname" => "text",
82 "Lastname" => "text",
83 "Title" => "text",
84 "Birthday" => "text",
85 "Gender" => "text",
86 "Institution" => "text",
87 "Department" => "text",
88 "Street" => "text",
89 "Zipcode" => "text",
90 "City" => "text",
91 "Country" => "text",
92 "PhoneOffice" => "text",
93 "PhoneHome" => "text",
94 "PhoneMobile" => "text",
95 "Fax" => "text",
96 "Email" => "text",
97 "SecondEmail" => "text",
98 "Hobby" => "text",
99 "ReferralComment" => "text",
100 "Matriculation" => "text",
101 "Latitude" => "text",
102 "Longitude" => "text",
103 "LocZoom" => "text",
104 "Picture" => "directory"
105 ];
106 }
107 }
108
109 if ($a_entity == "usr_setting") {
110 switch ($a_version) {
111 case "4.3.0":
112 case "4.5.0":
113 case "5.1.0":
114 case "5.2.0":
115 case "5.3.0":
116 return [
117 "UserId" => "integer",
118 "Keyword" => "text",
119 "Value" => "text"
120 ];
121 }
122 }
123
124 if ($this->export_config->getExportType() == "personal_data") {
125 switch ($a_version) {
126 case "4.3.0":
127 case "4.5.0":
128 case "5.1.0":
129 case "5.2.0":
130 case "5.3.0":
131 return [
132 "Id" => "integer"
133 ];
134 }
135 }
136
137 if ($a_entity == "usr_multi") {
138 switch ($a_version) {
139 case "4.5.0":
140 case "5.1.0":
141 case "5.2.0":
142 case "5.3.0":
143 return [
144 "UserId" => "integer",
145 "FieldId" => "text",
146 "Value" => "text"
147 ];
148 }
149 }
150 return [];
151 }

◆ getXmlNamespace()

ilUserDataSet::getXmlNamespace ( string  $a_entity,
string  $a_schema_version 
)
protected

Reimplemented from ilDataSet.

Definition at line 63 of file class.ilUserDataSet.php.

63 : string
64 {
65 return "https://www.ilias.de/xml/Services/User/" . $a_entity;
66 }

◆ getXmlRecord()

ilUserDataSet::getXmlRecord ( string  $a_entity,
string  $a_version,
array  $a_set 
)

Get xml record for version.

Parameters
array$a_setabstract data record

Reimplemented from ilDataSet.

Definition at line 153 of file class.ilUserDataSet.php.

153 : array // Missing array type.
154 {
155 if ($a_entity == "usr_profile") {
156 $tmp_dir = ilFileUtils::ilTempnam();
157 ilFileUtils::makeDir($tmp_dir);
158
160 $a_set["Id"],
161 "small",
162 true,
163 true
164 );
165
166 if ($im != "") {
167 ilObjUser::copyProfilePicturesToDirectory($a_set["Id"], $tmp_dir);
168 }
169
170 $this->temp_picture_dirs[$a_set["Id"]] = $tmp_dir;
171
172 $a_set["Picture"] = $tmp_dir;
173 }
174
175 return $a_set;
176 }
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static _getPersonalPicturePath(int $usr_id, string $size='small', bool $force_pic=false)
static copyProfilePicturesToDirectory(int $a_user_id, string $a_dir)

References ilObjUser\_getPersonalPicturePath(), ilObjUser\copyProfilePicturesToDirectory(), ilFileUtils\ilTempnam(), and ilFileUtils\makeDir().

+ Here is the call graph for this function:

◆ importRecord()

ilUserDataSet::importRecord ( string  $a_entity,
array  $a_types,
array  $a_rec,
ilImportMapping  $a_mapping,
string  $a_schema_version 
)

Needs to be overwritten for import use case.

Reimplemented from ilDataSet.

Definition at line 299 of file class.ilUserDataSet.php.

305 : void {
306 switch ($a_entity) {
307 case "usr":
308 // only users themselves import their profiles!
309 // thus we can map the import id of the dataset to the current user
310 $a_mapping->addMapping(
311 'components/ILIAS/User',
312 'usr',
313 $a_rec['Id'],
314 (string) $this->current_user->getId()
315 );
316 break;
317
318 case "usr_profile":
319 $usr_id = (int) $a_mapping->getMapping("components/ILIAS/User", "usr", $a_rec["Id"]);
320 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") {
321 if (!isset($this->users[$usr_id])) {
322 $this->users[$usr_id] = new ilObjUser($usr_id);
323 }
324 $user = array_reduce(
325 $this->user_profile->getFields([], [Alias::class, Roles::class]),
326 function (\ilObjUser $c, ProfileField $v) use ($a_rec): \ilObjUser {
327 $array_key = $this->buildProfileFieldArrayKeyFromIdentifier($v->getIdentifier());
328 if (!$this->user_profile->userFieldEditableByUser($v->getIdentifier())
329 || !isset($a_rec[$array_key])) {
330 return $c;
331 }
332 return $v->addValueToUserObject(
333 $c,
334 Context::UserAdministration,
336 $a_rec,
337 $array_key
338 )
339 );
340 },
341 $this->users[$usr_id]
342 );
343
344 $user->update();
345 }
346 break;
347
348 case "usr_setting":
349 $usr_id = (int) $a_mapping->getMapping("components/ILIAS/User", "usr", $a_rec["UserId"]);
350 if ($usr_id > 0 && ilObject::_lookupType($usr_id) === "usr") {
351 if (!isset($this->users[$usr_id])) {
352 $this->users[$usr_id] = new ilObjUser($usr_id);
353 }
354 $user = $this->users[$usr_id];
355 $user->writePref($a_rec["Keyword"], ilUtil::secureString($a_rec["Value"]));
356 }
357 break;
358
359 case "usr_multi":
360 $usr_id = (int) $a_mapping->getMapping("components/ILIAS/User", "usr", $a_rec["UserId"]);
361 if ($usr_id > 0 && ilObject::_lookupType($usr_id) === "usr") {
362 $this->multi[$usr_id][$a_rec["FieldId"]][] = ilUtil::secureString($a_rec["Value"]);
363 }
364 break;
365 }
366 }
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
User class.
static _lookupType(int $id, bool $reference=false)
retrieveValueFromImportArray(array $import_array, string $key)
buildProfileFieldArrayKeyFromIdentifier(string $identifier)
static secureString(string $a_str, bool $a_strip_html=true, string $a_allow="")
$c
Definition: deliver.php:25

References $c, ilObject\_lookupType(), ilImportMapping\addMapping(), buildProfileFieldArrayKeyFromIdentifier(), ilImportMapping\getMapping(), ILIAS\Repository\int(), retrieveValueFromImportArray(), and ilUtil\secureString().

+ Here is the call graph for this function:

◆ readData()

ilUserDataSet::readData ( string  $a_entity,
string  $a_version,
array  $a_ids 
)

Read data from DB.

This should result in the abstract field structure of the version set in the constructor.

Reimplemented from ilDataSet.

Definition at line 189 of file class.ilUserDataSet.php.

189 : void // Missing array type.
190 {
191 if (!is_array($a_ids)) {
192 $a_ids = [$a_ids];
193 }
194
195 if ($this->export_config->getExportType() == "personal_data") {
196 switch ($a_version) {
197 case "4.3.0":
198 case "4.5.0":
199 case "5.1.0":
200 case "5.2.0":
201 case "5.3.0":
202 $this->data = [];
203 foreach ($a_ids as $id) {
204 $this->data[] = ["Id" => $id];
205 }
206 break;
207 }
208 }
209
210 if ($a_entity == "usr_profile") {
211 switch ($a_version) {
212 case "4.3.0":
213 case "4.5.0":
214 case "5.1.0":
215 $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, " .
216 " title, birthday, gender, institution, department, street, city, zipcode, country, " .
217 " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, " .
218 " delicious, latitude, longitude, loc_zoom" .
219 " FROM usr_data u " .
220 "WHERE " .
221 $this->db->in("u.usr_id", $a_ids, false, "integer"));
222 break;
223
224 case "5.2.0":
225 $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, " .
226 " title, birthday, gender, institution, department, street, city, zipcode, country, " .
227 " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, " .
228 " latitude, longitude, loc_zoom" .
229 " FROM usr_data u " .
230 "WHERE " .
231 $this->db->in("u.usr_id", $a_ids, false, "integer"));
232 break;
233 case "5.3.0":
234 $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, " .
235 " title, birthday, gender, institution, department, street, city, zipcode, country, " .
236 " phone_office, phone_home, phone_mobile, fax, email, second_email, hobby, referral_comment, matriculation, " .
237 " latitude, longitude, loc_zoom" .
238 " FROM usr_data u " .
239 "WHERE " .
240 $this->db->in("u.usr_id", $a_ids, false, "integer"));
241 break;
242 }
243 }
244
245 if ($a_entity == "usr_setting") {
246 switch ($a_version) {
247 case "4.3.0":
248 case "4.5.0":
249 case "5.1.0":
250 case "5.2.0":
251 case "5.3.0":
252 // for all user ids get data from usr_pref and mail options, create records user_id/name/value
253 $prefs = ["date_format", "day_end", "day_start", "bs_allow_to_contact_me", "chat_osc_accept_msg", "hide_own_online_status", "language",
254 "public_birthday", "puplic_city", "public_country", "public_delicious", "public_department", "public_email", "public_second_email",
255 "public_fax", "public_gender", "public_hobby", "public_institution", "public_location",
256 "public_matriculation", "public_phone_home", "public_phone_mobile", "public_phone_office",
257 "public_profile", "public_country", "public_street", "public_title", "public_avatar", "public_zipcode",
258 "screen_reader_optimization", "show_users_online",
259 "store_last_visited", "time_format", "user_tz", "weekstart",
260 "session_reminder_lead_time", "usr_starting_point", "usr_starting_point_ref_id",
261 "chat_broadcast_typing"];
262
263 if (version_compare($a_version, '5.2.0', '>=')) {
264 unset(
265 $prefs['public_im_aim'], $prefs['public_im_icq'], $prefs['public_im_jabber'],
266 $prefs['public_im_msn'], $prefs['public_im_skype'], $prefs['public_im_voip'],
267 $prefs['public_im_yahoo'], $prefs['public_delicious']
268 );
269 }
270
271 $this->data = [];
272 $set = $this->db->query("SELECT * FROM usr_pref " .
273 " WHERE " . $this->db->in("keyword", $prefs, false, "text") .
274 " AND " . $this->db->in("usr_id", $a_ids, false, "integer"));
275 while ($rec = $this->db->fetchAssoc($set)) {
276 $this->data[] = ["UserId" => $rec["usr_id"], "Keyword" => $rec["keyword"], "Value" => $rec["value"]];
277 }
278 break;
279 }
280 }
281
282 if ($a_entity == "usr_multi") {
283 switch ($a_version) {
284 case "4.5.0":
285 case "5.1.0":
286 case "5.2.0":
287 case "5.3.0":
288 $this->data = [];
289 $set = $this->db->query("SELECT * FROM usr_profile_data" .
290 " WHERE " . $this->db->in("usr_id", $a_ids, false, "integer"));
291 while ($rec = $this->db->fetchAssoc($set)) {
292 $this->data[] = ["UserId" => $rec["usr_id"], "FieldId" => $rec["field_id"], "Value" => $rec["value"]];
293 }
294 break;
295 }
296 }
297 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...

References $id, and ilDataSet\getDirectDataFromQuery().

+ Here is the call graph for this function:

◆ retrieveValueFromImportArray()

ilUserDataSet::retrieveValueFromImportArray ( array  $import_array,
string  $key 
)
private

Definition at line 380 of file class.ilUserDataSet.php.

383 : mixed {
384 return match($key) {
385 'Latitude' => [
386 'latitude' => $import_array['Latitude'],
387 'longitude' => $import_array['Longitude'],
388 'zoom' => (int) $import_array['LocZoom']
389 ],
390 'Picture' => [
391 'tmp_name' => $this->buildFileUploadDir(
392 $import_array[$key],
393 $import_array['Id']
394 ),
395 'alias' => $import_array['Username']
396 ],
397 default => ilUtil::secureString($import_array[$key])
398 };
399 }
buildFileUploadDir(string $rel_path, string $usr_id)

References ILIAS\Repository\int(), and ilUtil\secureString().

Referenced by importRecord().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $current_user

ilObjUser ilUserDataSet::$current_user
private

Definition at line 35 of file class.ilUserDataSet.php.

◆ $export_config

ilUserExportConfig ilUserDataSet::$export_config
protected

Definition at line 33 of file class.ilUserDataSet.php.

◆ $multi

array ilUserDataSet::$multi = []

Definition at line 37 of file class.ilUserDataSet.php.

◆ $temp_picture_dirs

array ilUserDataSet::$temp_picture_dirs = []
protected

Definition at line 36 of file class.ilUserDataSet.php.

◆ $user_profile

Profile ilUserDataSet::$user_profile
private

Definition at line 34 of file class.ilUserDataSet.php.

◆ $users

array ilUserDataSet::$users
protected

Definition at line 38 of file class.ilUserDataSet.php.


The documentation for this class was generated from the following file: