19 declare(strict_types=1);
51 public function __construct(
int $ref_id, ?
int $table_id, array $filter = [])
54 $this->main_tpl = $DIC->ui()->mainTemplate();
62 $this->tables = (
$table_id) ? [$this->dcl->getTableById($table_id)] : $this->dcl->getTables();
74 $dangerous_filename_characters = [
" ",
'"',
"'",
"&",
"/",
"\\",
"?",
"#",
"`"];
76 return str_replace($dangerous_filename_characters,
"_", iconv(
"utf-8",
"ascii//TRANSLIT", $filename));
98 if ($field->getExportable()) {
111 foreach ($table->
getFields() as $field) {
112 if ($field->getExportable()) {
113 $field->fillHeaderExcel($worksheet, $row, $col);
130 public function export(
string $format = self::EXPORT_EXCEL, ?
string $filepath =
null,
bool $send =
false)
132 if (count($this->tables) == 0) {
136 if (empty($filepath)) {
140 $basename = (isset($this->table_id)) ? $this->tables[0]->
getTitle() :
'complete';
141 $filename = time() .
'__' . $basename .
"_" . date(
"Y-m-d_H-i");
145 $filename = pathinfo($filepath, PATHINFO_FILENAME);
148 $in_progress_file = $filepath . self::IN_PROGRESS_POSTFIX;
149 file_put_contents($in_progress_file,
"");
151 $data_available =
false;
152 $fields_available =
false;
154 if ($format == self::EXPORT_EXCEL) {
155 foreach ($this->tables as $table) {
158 $list = $table->getPartialRecords((
string) $this->dcl->getRefId(),
'id',
'asc',
null, 0,
$this->filter);
159 $data_available = $data_available || ($list[
'total'] > 0);
160 $fields_available = $fields_available || (count($table->getExportableFields()) > 0);
161 if ($list[
'total'] > 0 && count($table->getExportableFields()) > 0) {
163 $title = substr($table->getTitle(), 0, 31);
164 $adapter->addSheet($title);
173 foreach ($list[
'records'] as $set) {
178 $data_available =
true;
183 if (file_exists($in_progress_file)) {
184 unlink($in_progress_file);
187 if (!$data_available) {
188 $this->main_tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'dcl_no_export_content_available'));
193 if (!$fields_available) {
195 $this->main_tpl->setOnScreenMessage(
'info', sprintf(
196 $this->
lng->txt(
'dcl_no_export_fields_available'),
197 $ilCtrl->getLinkTargetByClass(
198 [
'ilDclTableListGUI',
'ilDclFieldListGUI'],
208 $adapter->writeToFile($filepath);
213 public function exportAsync(
string $format = self::EXPORT_EXCEL, ?
string $filepath =
null): mixed
216 $ilLog = $DIC[
'ilLog'];
218 $method = self::SOAP_FUNCTION_NAME;
220 $soap_params = [$this->dcl->getRefId()];
221 array_push($soap_params, $this->table_id, $format, $filepath);
228 $soap_client->setResponseTimeout(5);
229 $soap_client->enableWSDL(
true);
231 $ilLog->write(__METHOD__ .
': Trying to call Soap client...');
233 array_unshift($soap_params, $new_session_id .
'::' .
$client_id);
235 if ($soap_client->init()) {
236 $ilLog->info(
'Calling soap ' . $method .
' method with params ' . print_r($soap_params,
true));
237 $res = $soap_client->call($method, $soap_params);
239 $ilLog->warning(
'SOAP clone call failed. Calling clone method manually');
240 if (method_exists(
'ilSoapFunctions', $method)) {
241 $res = ilSoapFunctions::$method(
242 $new_session_id .
'::' . $client_id,
243 $this->dcl->getRefId(),
249 throw new ilDclException(
"SOAP call " . $method .
" does not exists!");
static _duplicate(string $a_session_id)
Duplicate session.
getExportContentPath(string $format)
Return export path.
ilGlobalTemplateInterface $main_tpl
getFields()
Returns all fields of this table including the standard fields.
loadLanguageModule(string $a_module)
Load language module.
array $filter
Array with filters.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object
fillMetaExcel(ilDclTable $table, ilExcel $worksheet, int $row)
Fill Excel meta-data.
__construct(int $ref_id, ?int $table_id, array $filter=[])
static resetCache()
Resets all the cache fields.
int $table_id
Table-Id for export.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
fillRowExcel(ilDclTable $table, ilExcel $worksheet, ilDclBaseRecordModel $record, int $row)
Fill a excel row.
fillHeaderExcel(ilDclTable $table, ilExcel $worksheet, int $row)
Fill Excel header.
exportAsync(string $format=self::EXPORT_EXCEL, ?string $filepath=null)
sanitizeFilename(string $filename)
Sanitize the given filename The ilUtil::_sanitizeFilename() does not clean enough.
export(string $format=self::EXPORT_EXCEL, ?string $filepath=null, bool $send=false)
Creates an export of a specific data collection table.
fillRecordFieldExcelExport(ilExcel $worksheet, int &$row, int &$col, $field_id)
int $ref_id
Ref-ID of DataCollection.
Hook-Class for exporting data-collections (used in SOAP-Class) This Class avoids duplicated code by r...
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
const IN_PROGRESS_POSTFIX