19declare(strict_types=1);
44 bool $a_call_by_reference =
true
49 $this->
profile = LocalDIC::dic()[Profile::class];
53 public function delete():
bool
59 string $a_mode = self::FILE_TYPE_EXCEL
68 $filename = $date .
"__" . $inst_id .
"__xls_usrf";
71 $filename = $date .
"__" . $inst_id .
"__csv_usrf.csv";
74 $filename = $date .
"__" . $inst_id .
"__xml_usrf.xml";
93 $dir = $this->getExportDirectory();
108 while ($entry = $dir->read()) {
109 if ($entry !=
"." and
111 preg_match(
"/^[0-9]{10}_{2}[0-9]+_{2}([a-z0-9]{3})_usrf\.[a-z]{1,4}\$/", $entry, $matches)) {
112 $filearray[
"filename"] = $entry;
113 $filearray[
"filesize"] = filesize($this->getExportDirectory() .
"/" . $entry);
114 $file[] = $filearray;
129 return str_replace([
'&',
'<',
'>'], [
'&',
'<',
'>'], $value);
139 $xml_writer->setSettings($settings);
140 $xml_writer->setAttachRoles(
true);
142 if ($xml_writer->start()) {
143 fwrite(fopen(
$filename,
'wb'), $xml_writer->getXML());
150 fn(Field $v): array => [
151 'name' => $v->getLabel($this->lng),
152 'id' => $v->getIdentifier()
154 $this->profile->getVisibleUserDefinedFields(Context::Export)
164 $udf_ex_fields = $this->getUserDefinedExportFields();
165 foreach ($settings as $value) {
166 $headerrow[] = $this->
lng->txt($value);
168 foreach ($udf_ex_fields as
$f) {
169 $headerrow[] =
$f[
"name"];
174 fwrite($file, $this->processCSVRow($headerrow) .
"\n");
175 foreach (
$data as $row) {
177 foreach ($settings as $header) {
179 if (isset($row[$header]) && is_array($row[$header])) {
180 $row[$header] = implode(
", ", $row[$header]);
183 $csvrow[] = $row[$header] ??
'';
187 reset($udf_ex_fields);
188 if (count($udf_ex_fields) > 0) {
189 $udf =
new ilUserDefinedData($row[
"usr_id"]);
190 foreach ($udf_ex_fields as
$f) {
191 $csvrow[] = $udf->get(
"f_" .
$f[
"id"]);
195 fwrite($file, $this->processCSVRow($csvrow) .
"\n");
211 $udf_ex_fields = $this->getUserDefinedExportFields();
214 foreach ($settings as $value) {
215 if ($value ==
'ext_account') {
216 $value =
'user_ext_account';
218 $worksheet->setCell($row, $col, $this->
lng->txt($value));
221 foreach ($udf_ex_fields as
$f) {
222 $worksheet->setCell($row, $col,
$f[
"name"]);
225 $worksheet->setBold(
"A1:" . $worksheet->getColumnCoord($col - 1) .
"1");
227 $this->
lng->loadLanguageModule(
"meta");
228 foreach ($data as $index => $rowdata) {
233 foreach ($settings as $fieldname) {
234 $value = $rowdata[$fieldname] ??
"";
235 switch ($fieldname) {
237 $worksheet->setCell($row, $col, $this->
lng->txt(
"meta_l_" . $value));
239 case "time_limit_from":
240 case "time_limit_until":
244 $worksheet->setCell($row, $col, $value);
254 $worksheet->setCell($row, $col, $value);
257 case "interests_general":
258 case "interests_help_offered":
259 case "interests_help_looking":
260 if (is_array($value) && count($value)) {
261 $value = implode(
", ", $value);
269 $worksheet->setCell($row, $col, $value);
276 reset($udf_ex_fields);
277 if (count($udf_ex_fields) > 0) {
278 $udf =
new ilUserDefinedData($rowdata[
"usr_id"]);
279 foreach ($udf_ex_fields as
$f) {
280 $worksheet->setCell($row, $col, $udf->get(
"f_" .
$f[
"id"]));
300 $up = LocalDIC::dic()[Profile::class];
301 $profile_fields = $up->getFields([], [Roles::class]);
303 $query =
"SELECT * FROM settings WHERE " .
304 $ilDB->like(
"keyword",
"text",
'%usr_settings_export_%');
305 $result =
$ilDB->query($query);
307 if ($row[
"value"] ==
"1") {
308 if (preg_match(
"/usr_settings_export_(.*)/", $row[
"keyword"], $setting)) {
309 $db_settings[] = $setting[1];
313 $export_settings = [];
314 foreach ($profile_fields as $key => $value) {
315 if (in_array($key, $db_settings)) {
316 if (strcmp($key,
"password") == 0) {
320 $export_settings[] = $key;
324 $export_settings[] =
"usr_id";
325 $export_settings[] =
"login";
326 $export_settings[] =
"last_login";
327 $export_settings[] =
"last_update";
328 $export_settings[] =
"create_date";
329 $export_settings[] =
"time_limit_owner";
330 $export_settings[] =
"time_limit_unlimited";
331 $export_settings[] =
"time_limit_from";
332 $export_settings[] =
"time_limit_until";
333 $export_settings[] =
"time_limit_message";
334 $export_settings[] =
"active";
335 $export_settings[] =
"approve_date";
336 $export_settings[] =
"agree_date";
337 $export_settings[] =
"client_ip";
338 $export_settings[] =
"auth_mode";
339 $export_settings[] =
"ext_account";
340 $export_settings[] =
"feedhash";
341 return $export_settings;
348 string $a_mode = self::FILE_TYPE_EXCEL,
349 ?array $user_data_filter =
null,
350 bool $use_temp_dir =
false
361 $expDir = $this->getExportDirectory();
363 $this->createExportDirectory();
364 $fullname = $expDir .
"/" . $this->getExportFilename($a_mode);
369 $settings = self::getExportSettings();
372 $query =
"SELECT * FROM usr_pref WHERE keyword = " .
$ilDB->quote(
'language',
'text');
376 $languages[$row[
'usr_id']] = $row[
'value'];
381 $set =
$ilDB->query(
"SELECT * FROM usr_profile_data");
382 while ($row =
$ilDB->fetchAssoc($set)) {
383 if (!is_array($user_data_filter) ||
384 in_array($row[
"usr_id"], $user_data_filter)) {
385 $multi[$row[
"usr_id"]][$row[
"field_id"]][] = $row[
"value"];
390 $query =
"SELECT usr_data.* FROM usr_data " .
391 " ORDER BY usr_data.lastname, usr_data.firstname";
392 $result =
$ilDB->query($query);
393 while ($row =
$ilDB->fetchAssoc($result)) {
394 if (isset($languages[$row[
'usr_id']])) {
395 $row[
'language'] = $languages[$row[
'usr_id']];
397 $row[
'language'] =
$lng->getDefaultLanguage();
400 if (isset($multi[$row[
"usr_id"]])) {
401 $row = array_merge($row, $multi[$row[
"usr_id"]]);
404 if (is_array($user_data_filter)) {
405 if (in_array($row[
"usr_id"], $user_data_filter)) {
415 case self::FILE_TYPE_EXCEL:
416 $this->createExcelExport($settings,
$data, $fullname);
418 case self::FILE_TYPE_CSV:
419 $this->createCSVExport($settings,
$data, $fullname);
421 case self::FILE_TYPE_XML:
422 $this->createXMLExport($settings,
$data, $fullname);
431 foreach ($row as $rowindex => $entry) {
432 $resultarray[$rowindex] = iconv(
435 '"' . str_replace(chr(13) . chr(10), chr(10), $entry) .
'"'
438 return implode(
';', $resultarray);
447 if (!is_dir($this->getExportDirectory())) {
450 if (!is_writable($usrf_data_dir)) {
451 $this->
ilias->raiseError(
"Userfolder data directory (" . $usrf_data_dir
452 .
") not writeable.", $this->
ilias->error_obj->MESSAGE);
456 $export_dir = $usrf_data_dir .
"/export";
458 if (!is_dir($export_dir)) {
459 $this->
ilias->raiseError(
"Creation of Userfolder Export Directory failed.", $this->
ilias->error_obj->MESSAGE);
471 return array_key(LocalDIC::dic()[Profile::class]->getFields(
473 [Alias::class, Roles::class]
490 $query =
"UPDATE usr_data SET time_limit_owner = " .
$ilDB->quote($a_new_id,
"integer") .
" " .
491 "WHERE time_limit_owner = " .
$ilDB->quote($a_old_id,
"integer") .
" ";
492 $ilDB->manipulate($query);
@classDescription Date and time handling
addSheet(string $a_name, bool $a_activate=true)
Add sheet.
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 getDataDir()
get data directory (outside webspace)
createExportDirectory()
creates data directory for export files
__construct(int $a_id, bool $a_call_by_reference=true)
getUserDefinedExportFields()
createCSVExport(array $settings, array $data, string $filename)
const ORG_OP_EDIT_USER_ACCOUNTS
createXMLExport(array $settings, array $data, string $filename)
static getProfileFields()
Get profile fields.
static _updateUserFolderAssignment(int $a_old_id, int $a_new_id)
Update user folder assignment Typically called after deleting a category with local user accounts.
createExcelExport(array $settings, array $data, string $filename)
buildExportFile(string $a_mode=self::FILE_TYPE_EXCEL, ?array $user_data_filter=null, bool $use_temp_dir=false)
build xml export file
static getExportSettings()
getExportFilename(string $a_mode=self::FILE_TYPE_EXCEL)
getExportFiles()
Get a list of the already exported files in the export directory.
processCSVRow(array $row)
Class ilObject Basic functions for all objects.
XML writer class Class to simplify manual writing of xml documents.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ilObjForumAdministration.