19declare(strict_types=1);
22use ILIAS\User\BuildExportFieldArray;
36 use BuildExportFieldArray;
51 bool $a_call_by_reference =
true
56 $this->
profile = LocalDIC::dic()[Profile::class];
57 $this->
settings = LocalDIC::dic()[Settings::class];
61 public function delete():
bool
67 string $a_mode = self::FILE_TYPE_EXCEL
76 $filename = $date .
'__' . $inst_id .
'__xls_usrf';
79 $filename = $date .
'__' . $inst_id .
'__csv_usrf.csv';
82 $filename = $date .
'__' . $inst_id .
'__xml_usrf.xml';
101 $dir = $this->getExportDirectory();
105 || !is_writable($dir)) {
116 while ($entry = $dir->read()) {
119 && preg_match(
'/^[0-9]{10}_{2}[0-9]+_{2}([a-z0-9]{3})_usrf\.[a-z]{1,4}$/', $entry, $matches)) {
120 $filearray[
'filename'] = $entry;
121 $filearray[
'filesize'] = filesize($this->getExportDirectory() .
'/' . $entry);
122 $file[] = $filearray;
137 return str_replace([
'&',
'<',
'>'], [
'&',
'<',
'>'], $value);
141 array $fields_to_export,
147 $xml_writer->setFieldsToExport(
148 array_merge(array_keys($fields_to_export), [
'time_limit_owner'])
150 $xml_writer->setAttachRoles(
true);
152 if ($xml_writer->start()) {
153 fwrite(fopen(
$filename,
'wb'), $xml_writer->getXML());
158 array $fields_to_export,
163 $udf_ex_fields = $this->getUserDefinedExportFields();
164 foreach ($fields_to_export as $value) {
165 $headerrow[] = $this->
lng->txt($value);
167 foreach ($udf_ex_fields as
$f) {
168 $headerrow[] =
$f[
'name'];
172 fwrite($file, $this->processCSVRow($headerrow) .
"\n");
173 foreach (
$data as $row) {
175 foreach ($settings as $header) {
177 if (isset($row[$header]) && is_array($row[$header])) {
178 $row[$header] = implode(
', ', $row[$header]);
181 $csvrow[] = $row[$header] ??
'';
185 reset($udf_ex_fields);
186 if (count($udf_ex_fields) > 0) {
187 $udf = $this->
profile->getDataFor($row[
'usr_id']);
188 foreach ($udf_ex_fields as
$f) {
189 $csvrow[] = $udf->get(
'f_' .
$f[
'id']);
193 fwrite($file, $this->processCSVRow($csvrow) .
"\n");
199 array $fields_to_export,
210 foreach ($fields_to_export as $label) {
211 $worksheet->setCell($row, $col, $label);
214 $worksheet->setBold(
'A1:' . $worksheet->getColumnCoord($col - 1) .
'1');
216 $this->
lng->loadLanguageModule(
'meta');
217 foreach ($data as $rowdata) {
222 foreach (array_keys($fields_to_export) as $fieldname) {
223 $value = $rowdata[$fieldname] ??
'';
224 switch ($fieldname) {
226 $worksheet->setCell($row, $col, $this->
lng->txt(
'meta_l_' . $value));
228 case 'time_limit_from':
229 case 'time_limit_until':
233 $worksheet->setCell($row, $col, $value);
243 $worksheet->setCell($row, $col, $value);
250 is_array($value) && $value !== []
251 ? implode(
', ', $value)
266 string $a_mode = self::FILE_TYPE_EXCEL,
267 ?array $user_data_filter =
null,
268 bool $use_temp_dir =
false
272 $fullname = $export_dir;
274 $export_dir = $this->getExportDirectory();
276 $this->createExportDirectory();
277 $fullname = $export_dir .
'/' . $this->getExportFilename($a_mode);
280 $fields_to_export = $this->getExportFieldArray(
285 $data = $this->retrieveExportDataArray(
286 $this->buildWhereForUserDataFilterArray($user_data_filter ?? [])
290 case self::FILE_TYPE_EXCEL:
291 $this->createExcelExport($fields_to_export,
$data, $fullname);
293 case self::FILE_TYPE_CSV:
294 $this->createCSVExport($fields_to_export,
$data, $fullname);
296 case self::FILE_TYPE_XML:
297 $this->createXMLExport($fields_to_export,
$data, $fullname);
306 foreach ($row as $rowindex => $entry) {
307 $resultarray[$rowindex] = iconv(
310 '"' . str_replace(chr(13) . chr(10), chr(10), $entry) .
'"'
313 return implode(
';', $resultarray);
318 $query =
"SELECT * FROM usr_pref WHERE keyword = {$this->db->quote('language', 'text')}";
319 if ($usr_ids_where !==
'') {
320 $query .=
"AND {$usr_ids_where}";
322 $res = $this->db->query($query);
325 $languages[$row[
'usr_id']] = $row[
'value'];
329 $multi = $this->retrieveMultiRowDataArray($usr_ids_where);
331 $query =
'SELECT usr_data.* FROM usr_data ';
332 if ($usr_ids_where !==
'') {
333 $query .=
"WHERE {$usr_ids_where} ";
335 $set = $this->db->query(
"{$query} ORDER BY usr_data.lastname, usr_data.firstname");
338 while ($row = $this->db->fetchAssoc($set)) {
339 $row[
'language'] = $languages[$row[
'usr_id']] ?? $this->
lng->getDefaultLanguage();
340 $data[] = array_merge($row, $multi[$row[
'usr_id']] ?? []);
348 $query =
'SELECT * FROM usr_profile_data';
349 if ($usr_ids_where !==
'') {
350 $query .=
" WHERE {$usr_ids_where}";
352 $set = $this->db->query($query);
354 while ($row = $this->db->fetchAssoc($set)) {
355 $multi[$row[
'usr_id']][$row[
'field_id']][] = $row[
'value'];
362 if ($user_data_filter === []) {
375 if (!is_dir($this->getExportDirectory())) {
378 if (!is_writable($usrf_data_dir)) {
379 $this->
ilias->raiseError(
'Userfolder data directory (' . $usrf_data_dir
380 .
') not writeable.', $this->
ilias->error_obj->MESSAGE);
384 $export_dir = $usrf_data_dir .
'/export';
386 if (!is_dir($export_dir)) {
387 $this->
ilias->raiseError(
'Creation of Userfolder Export Directory failed.', $this->
ilias->error_obj->MESSAGE);
399 return array_key(LocalDIC::dic()[Profile::class]->getFields(
401 [Alias::class, Roles::class]
420 $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)
createExcelExport(array $fields_to_export, array $data, string $filename)
const ORG_OP_EDIT_USER_ACCOUNTS
buildWhereForUserDataFilterArray(array $user_data_filter)
createCSVExport(array $fields_to_export, array $data, string $filename)
createXMLExport(array $fields_to_export, 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.
SettingsImplementation $settings
retrieveMultiRowDataArray(string $usr_ids_where)
buildExportFile(string $a_mode=self::FILE_TYPE_EXCEL, ?array $user_data_filter=null, bool $use_temp_dir=false)
build xml export file
const string PERM_READ_ALL_AND_WRITE
const string PERM_READ_ALL
retrieveExportDataArray(string $usr_ids_where)
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.
if(!file_exists('../ilias.ini.php'))