19declare(strict_types=1);
38 $this->main_tpl =
$DIC->ui()->mainTemplate();
46 $this->tables = (
$table_id) ? [$this->dcl->getTableById(
$table_id)] : $this->dcl->getTables();
58 $dangerous_filename_characters = [
" ",
'"',
"'",
"&",
"/",
"\\",
"?",
"#",
"`"];
60 return str_replace($dangerous_filename_characters,
"_", iconv(
"utf-8",
"ascii//TRANSLIT",
$filename));
76 if ($field->getExportable()) {
87 if ($field->getExportable()) {
88 $field->fillHeaderExcel($worksheet, $row, $col);
97 public function export(
string $format = self::EXPORT_EXCEL, ?
string $filepath =
null,
bool $send =
false): bool
99 if (empty($filepath)) {
100 $filepath = $this->getExportContentPath($format);
103 $basename = (isset($this->table_id)) ? $this->tables[0]->
getTitle() :
'complete';
104 $filename = time() .
'__' . $basename .
"_" . date(
"Y-m-d_H-i");
106 $filepath .= $this->sanitizeFilename(
$filename);
108 $filename = pathinfo($filepath, PATHINFO_FILENAME);
111 $in_progress_file = $filepath . self::IN_PROGRESS_POSTFIX;
112 file_put_contents($in_progress_file,
"");
114 $data_available =
false;
115 $fields_available =
false;
117 if ($format == self::EXPORT_EXCEL) {
118 foreach ($this->tables as $table) {
121 $list = $table->getPartialRecords((
string) $this->dcl->getRefId(),
'id',
'asc',
null, 0, $this->filter);
122 $data_available = $data_available || ($list[
'total'] > 0);
123 $fields_available = $fields_available || (count($table->getExportableFields()) > 0);
124 if ($list[
'total'] > 0 && count($table->getExportableFields()) > 0) {
125 $adapter->addSheet($table->getTitle());
127 $this->fillMetaExcel($table, $adapter, $row);
128 $this->fillHeaderExcel($table, $adapter, $row);
130 foreach ($list[
'records'] as $set) {
131 $this->fillRowExcel($table, $adapter, $set, $row);
135 $data_available =
true;
140 if (file_exists($in_progress_file)) {
141 unlink($in_progress_file);
144 if (!$data_available || !$fields_available) {
145 $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'dcl_no_export_data_available'));
149 $this->main_tpl->setOnScreenMessage($this->main_tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'exp_file_created'),
true);
153 $adapter->writeToFile($filepath);
158 public function exportAsync(
string $format = self::EXPORT_EXCEL, ?
string $filepath =
null): mixed
162 $method = self::SOAP_FUNCTION_NAME;
164 $soap_params = [$this->dcl->getRefId()];
165 array_push($soap_params, $this->table_id, $format, $filepath);
168 $DIC->http()->wrapper()->cookie()->retrieve(session_name(),
$DIC->refinery()->kindlyTo()->string())
170 $client_id =
$DIC->http()->wrapper()->cookie()->retrieve(
'ilClientId',
$DIC->refinery()->kindlyTo()->string());
173 $soap_client->setResponseTimeout(5);
174 $soap_client->enableWSDL(
true);
176 $DIC->logger()->root()->write(__METHOD__ .
': Trying to call Soap client...');
178 array_unshift($soap_params, $new_session_id .
'::' .
$client_id);
180 if ($soap_client->init()) {
181 $DIC->logger()->root()->info(
'Calling soap ' . $method .
' method with params ' . print_r($soap_params,
true));
182 $res = $soap_client->call($method, $soap_params);
184 $DIC->logger()->root()->warning(
'SOAP clone call failed. Calling clone method manually');
185 if (method_exists(
'ilSoapFunctions', $method)) {
186 $res = ilSoapFunctions::$method(
188 $this->dcl->getRefId(),
194 throw new ilDclException(
"SOAP call " . $method .
" does not exists!");
fillRecordFieldExcelExport(ilExcel $worksheet, int &$row, int &$col, $field_id)
static resetCache()
Resets all the cache fields.
__construct(int $ref_id, ?int $table_id, array $filter=[])
fillMetaExcel(ilDclTable $table, ilExcel $worksheet, int $row)
export(string $format=self::EXPORT_EXCEL, ?string $filepath=null, bool $send=false)
sanitizeFilename(string $filename)
Sanitize the given filename The ilUtil::_sanitizeFilename() does not clean enough.
getExportContentPath(string $format)
fillRowExcel(ilDclTable $table, ilExcel $worksheet, ilDclBaseRecordModel $record, int $row)
ilGlobalTemplateInterface $main_tpl
exportAsync(string $format=self::EXPORT_EXCEL, ?string $filepath=null)
const IN_PROGRESS_POSTFIX
fillHeaderExcel(ilDclTable $table, ilExcel $worksheet, int $row)
getFields()
Returns all fields of this table including the standard fields.
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
@depricated Get export directory for an repository object
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
loadLanguageModule(string $a_module)
Load language module.
static _duplicate(string $a_session_id)
Duplicate session.
filter(string $filter_id, array $class_path, string $cmd, bool $activated=true, bool $expanded=true)