Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,18 @@
*
*********************************************************************/


declare(strict_types=1);

/**
* Hook-Class for exporting data-collections (used in SOAP-Class)
* This Class avoids duplicated code by routing the request to the right place
*/
class ilDclContentExporter
{
public const SOAP_FUNCTION_NAME = 'exportDataCollectionContent';
public const EXPORT_EXCEL = 'xlsx';
public const IN_PROGRESS_POSTFIX = '.prog';
/**
* Ref-ID of DataCollection
*/
protected int $ref_id;
/**
* Table-Id for export
*/
protected ?int $table_id;
/**
* Array with filters
*/
protected array $filter;

protected ilObjDataCollection $dcl;

protected ilLanguage $lng;

protected ilDclTable $table;
private ilGlobalTemplateInterface $main_tpl;
protected array $tables;
Expand All @@ -53,7 +36,7 @@ public function __construct(int $ref_id, ?int $table_id, array $filter = [])
{
global $DIC;
$this->main_tpl = $DIC->ui()->mainTemplate();
$lng = $DIC['lng'];
$lng = $DIC->language();

$this->ref_id = $ref_id;
$this->table_id = $table_id;
Expand All @@ -77,17 +60,11 @@ public function sanitizeFilename(string $filename): string
return str_replace($dangerous_filename_characters, "_", iconv("utf-8", "ascii//TRANSLIT", $filename));
}

/**
* Return export path
*/
public function getExportContentPath(string $format): string
{
return ilExport::_getExportDirectory($this->dcl->getId(), $format, 'dcl') . '/';
}

/**
* Fill a excel row
*/
protected function fillRowExcel(
ilDclTable $table,
ilExcel $worksheet,
Expand All @@ -102,9 +79,6 @@ protected function fillRowExcel(
}
}

/**
* Fill Excel header
*/
protected function fillHeaderExcel(ilDclTable $table, ilExcel $worksheet, int $row): void
{
$col = 0;
Expand All @@ -116,24 +90,12 @@ protected function fillHeaderExcel(ilDclTable $table, ilExcel $worksheet, int $r
}
}

/**
* Fill Excel meta-data
*/
protected function fillMetaExcel(ilDclTable $table, ilExcel $worksheet, int $row): void
{
}

/**
* Creates an export of a specific data collection table
* @return bool|void
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception|\PhpOffice\PhpSpreadsheet\Exception
*/
public function export(string $format = self::EXPORT_EXCEL, string $filepath = null, bool $send = false)
public function export(string $format = self::EXPORT_EXCEL, string $filepath = null, bool $send = false): bool
{
if (count($this->tables) == 0) {
return;
}

if (empty($filepath)) {
$filepath = $this->getExportContentPath($format);
ilFileUtils::makeDirParents($filepath);
Expand All @@ -160,20 +122,14 @@ public function export(string $format = self::EXPORT_EXCEL, string $filepath = n
$data_available = $data_available || ($list['total'] > 0);
$fields_available = $fields_available || (count($table->getExportableFields()) > 0);
if ($list['total'] > 0 && count($table->getExportableFields()) > 0) {
// only 31 character-long table-titles are allowed
$title = substr($table->getTitle(), 0, 31);
$adapter->addSheet($title);
$adapter->addSheet($table->getTitle());
$row = 1;

$this->fillMetaExcel($table, $adapter, $row);

// #14813
$this->fillHeaderExcel($table, $adapter, $row);
$row++;

foreach ($list['records'] as $set) {
$this->fillRowExcel($table, $adapter, $set, $row);
$row++; // #14760
$row++;
}

$data_available = true;
Expand Down Expand Up @@ -202,30 +158,30 @@ public function export(string $format = self::EXPORT_EXCEL, string $filepath = n
public function exportAsync(string $format = self::EXPORT_EXCEL, string $filepath = null): mixed
{
global $DIC;
$ilLog = $DIC['ilLog'];

$method = self::SOAP_FUNCTION_NAME;

$soap_params = [$this->dcl->getRefId()];
array_push($soap_params, $this->table_id, $format, $filepath);

$new_session_id = ilSession::_duplicate($_COOKIE[session_name()]);
$client_id = $_COOKIE['ilClientId'];
$new_session_id = ilSession::_duplicate(
$DIC->http()->wrapper()->cookie()->retrieve(session_name(), $DIC->refinery()->kindlyTo()->string())
);
$client_id = $DIC->http()->wrapper()->cookie()->retrieve('ilClientId', $DIC->refinery()->kindlyTo()->string());

// Start cloning process using soap call
$soap_client = new ilSoapClient();
$soap_client->setResponseTimeout(5);
$soap_client->enableWSDL(true);

$ilLog->write(__METHOD__ . ': Trying to call Soap client...');
$DIC->logger()->root()->write(__METHOD__ . ': Trying to call Soap client...');

array_unshift($soap_params, $new_session_id . '::' . $client_id);

if ($soap_client->init()) {
$ilLog->info('Calling soap ' . $method . ' method with params ' . print_r($soap_params, true));
$DIC->logger()->root()->info('Calling soap ' . $method . ' method with params ' . print_r($soap_params, true));
$res = $soap_client->call($method, $soap_params);
} else {
$ilLog->warning('SOAP clone call failed. Calling clone method manually');
$DIC->logger()->root()->warning('SOAP clone call failed. Calling clone method manually');
if (method_exists('ilSoapFunctions', $method)) {
$res = ilSoapFunctions::$method(
$new_session_id . '::' . $client_id,
Expand Down