ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilDclContentExporter Class Reference

Hook-Class for exporting data-collections (used in SOAP-Class) This Class avoids duplicated code by routing the request to the right place. More...

+ Collaboration diagram for ilDclContentExporter:

Public Member Functions

 __construct (int $ref_id, ?int $table_id, array $filter=[])
 
 sanitizeFilename (string $filename)
 Sanitize the given filename The ilUtil::_sanitizeFilename() does not clean enough. More...
 
 getExportContentPath (string $format)
 Return export path. More...
 
 export (string $format=self::EXPORT_EXCEL, string $filepath=null, bool $send=false)
 Creates an export of a specific data collection table. More...
 
 exportAsync (string $format=self::EXPORT_EXCEL, string $filepath=null)
 

Data Fields

const SOAP_FUNCTION_NAME = 'exportDataCollectionContent'
 
const EXPORT_EXCEL = 'xlsx'
 
const IN_PROGRESS_POSTFIX = '.prog'
 

Protected Member Functions

 fillRowExcel (ilDclTable $table, ilExcel $worksheet, ilDclBaseRecordModel $record, int $row)
 Fill a excel row. More...
 
 fillHeaderExcel (ilDclTable $table, ilExcel $worksheet, int $row)
 Fill Excel header. More...
 
 fillMetaExcel (ilDclTable $table, ilExcel $worksheet, int $row)
 Fill Excel meta-data. More...
 

Protected Attributes

int $ref_id
 Ref-ID of DataCollection. More...
 
int $table_id
 Table-Id for export. More...
 
array $filter
 Array with filters. More...
 
ilObjDataCollection $dcl
 
ilLanguage $lng
 
ilDclTable $table
 
array $tables
 

Private Attributes

ilGlobalTemplateInterface $main_tpl
 

Detailed Description

Hook-Class for exporting data-collections (used in SOAP-Class) This Class avoids duplicated code by routing the request to the right place.

Definition at line 26 of file class.ilDclContentExporter.php.

Constructor & Destructor Documentation

◆ __construct()

ilDclContentExporter::__construct ( int  $ref_id,
?int  $table_id,
array  $filter = [] 
)

Definition at line 52 of file class.ilDclContentExporter.php.

References $DIC, $filter, $lng, $ref_id, $table_id, ILIAS\Repository\filter(), ILIAS\Repository\lng(), and ilLanguage\loadLanguageModule().

53  {
54  global $DIC;
55  $this->main_tpl = $DIC->ui()->mainTemplate();
56  $lng = $DIC['lng'];
57 
58  $this->ref_id = $ref_id;
59  $this->table_id = $table_id;
60  $this->filter = $filter;
61 
62  $this->dcl = new ilObjDataCollection($ref_id);
63  $this->tables = ($table_id) ? [$this->dcl->getTableById($table_id)] : $this->dcl->getTables();
64 
65  $lng->loadLanguageModule('dcl');
66  $this->lng = $lng;
67  }
loadLanguageModule(string $a_module)
Load language module.
array $filter
Array with filters.
int $table_id
Table-Id for export.
global $DIC
Definition: feed.php:28
int $ref_id
Ref-ID of DataCollection.
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
+ Here is the call graph for this function:

Member Function Documentation

◆ export()

ilDclContentExporter::export ( string  $format = self::EXPORT_EXCEL,
string  $filepath = null,
bool  $send = false 
)

Creates an export of a specific data collection table.

Returns
bool|void
Exceptions

Definition at line 131 of file class.ilDclContentExporter.php.

References $filename, $filter, fillHeaderExcel(), fillMetaExcel(), fillRowExcel(), getExportContentPath(), ILIAS\Repository\lng(), ilFileUtils\makeDirParents(), ilDclCache\resetCache(), and sanitizeFilename().

Referenced by ilDclRecordListTableGUI\exportData().

132  {
133  if (count($this->tables) == 0) {
134  return;
135  }
136 
137  if (empty($filepath)) {
138  $filepath = $this->getExportContentPath($format);
139  ilFileUtils::makeDirParents($filepath);
140 
141  $basename = (isset($this->table_id)) ? $this->tables[0]->getTitle() : 'complete';
142  $filename = time() . '__' . $basename . "_" . date("Y-m-d_H-i");
143 
144  $filepath .= $this->sanitizeFilename($filename);
145  } else {
146  $filename = pathinfo($filepath, PATHINFO_FILENAME);
147  }
148 
149  $in_progress_file = $filepath . self::IN_PROGRESS_POSTFIX;
150  file_put_contents($in_progress_file, "");
151 
152  $data_available = false;
153  $fields_available = false;
154  $adapter = new ilExcel();
155  if ($format == self::EXPORT_EXCEL) {
156  foreach ($this->tables as $table) {
158 
159  $list = $table->getPartialRecords((string) $this->dcl->getRefId(), 'id', 'asc', null, 0, $this->filter);
160  $data_available = $data_available || ($list['total'] > 0);
161  $fields_available = $fields_available || (count($table->getExportableFields()) > 0);
162  if ($list['total'] > 0 && count($table->getExportableFields()) > 0) {
163  // only 31 character-long table-titles are allowed
164  $title = substr($table->getTitle(), 0, 31);
165  $adapter->addSheet($title);
166  $row = 1;
167 
168  $this->fillMetaExcel($table, $adapter, $row);
169 
170  // #14813
171  $this->fillHeaderExcel($table, $adapter, $row);
172  $row++;
173 
174  foreach ($list['records'] as $set) {
175  $this->fillRowExcel($table, $adapter, $set, $row);
176  $row++; // #14760
177  }
178 
179  $data_available = true;
180  }
181  }
182  }
183 
184  if (file_exists($in_progress_file)) {
185  unlink($in_progress_file);
186  }
187 
188  if (!$data_available || !$fields_available) {
189  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_no_export_data_available'));
190  return false;
191  }
192 
193  $this->main_tpl->setOnScreenMessage($this->main_tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('exp_file_created'), true);
194  if ($send) {
195  $adapter->sendToClient($filename);
196  } else {
197  $adapter->writeToFile($filepath);
198  }
199  return true;
200  }
getExportContentPath(string $format)
Return export path.
array $filter
Array with filters.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
fillMetaExcel(ilDclTable $table, ilExcel $worksheet, int $row)
Fill Excel meta-data.
static resetCache()
Resets all the cache fields.
fillRowExcel(ilDclTable $table, ilExcel $worksheet, ilDclBaseRecordModel $record, int $row)
Fill a excel row.
fillHeaderExcel(ilDclTable $table, ilExcel $worksheet, int $row)
Fill Excel header.
sanitizeFilename(string $filename)
Sanitize the given filename The ilUtil::_sanitizeFilename() does not clean enough.
$filename
Definition: buildRTE.php:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportAsync()

ilDclContentExporter::exportAsync ( string  $format = self::EXPORT_EXCEL,
string  $filepath = null 
)

Definition at line 202 of file class.ilDclContentExporter.php.

References $_COOKIE, $client_id, $DIC, $res, $table_id, and ilSession\_duplicate().

202  : mixed
203  {
204  global $DIC;
205  $ilLog = $DIC['ilLog'];
206 
207  $method = self::SOAP_FUNCTION_NAME;
208 
209  $soap_params = [$this->dcl->getRefId()];
210  array_push($soap_params, $this->table_id, $format, $filepath);
211 
212  $new_session_id = ilSession::_duplicate($_COOKIE[session_name()]);
213  $client_id = $_COOKIE['ilClientId'];
214 
215  // Start cloning process using soap call
216  $soap_client = new ilSoapClient();
217  $soap_client->setResponseTimeout(5);
218  $soap_client->enableWSDL(true);
219 
220  $ilLog->write(__METHOD__ . ': Trying to call Soap client...');
221 
222  array_unshift($soap_params, $new_session_id . '::' . $client_id);
223 
224  if ($soap_client->init()) {
225  $ilLog->info('Calling soap ' . $method . ' method with params ' . print_r($soap_params, true));
226  $res = $soap_client->call($method, $soap_params);
227  } else {
228  $ilLog->warning('SOAP clone call failed. Calling clone method manually');
229  if (method_exists('ilSoapFunctions', $method)) {
230  $res = ilSoapFunctions::$method(
231  $new_session_id . '::' . $client_id,
232  $this->dcl->getRefId(),
234  $format,
235  $filepath
236  );
237  } else {
238  throw new ilDclException("SOAP call " . $method . " does not exists!");
239  }
240  }
241 
242  return $res;
243  }
$res
Definition: ltiservices.php:69
static _duplicate(string $a_session_id)
Duplicate session.
int $table_id
Table-Id for export.
global $DIC
Definition: feed.php:28
$client_id
Definition: ltiauth.php:68
$_COOKIE[session_name()]
Definition: xapitoken.php:54
+ Here is the call graph for this function:

◆ fillHeaderExcel()

ilDclContentExporter::fillHeaderExcel ( ilDclTable  $table,
ilExcel  $worksheet,
int  $row 
)
protected

Fill Excel header.

Definition at line 108 of file class.ilDclContentExporter.php.

References ilDclTable\getFields().

Referenced by export().

108  : void
109  {
110  $col = 0;
111 
112  foreach ($table->getFields() as $field) {
113  if ($field->getExportable()) {
114  $field->fillHeaderExcel($worksheet, $row, $col);
115  }
116  }
117  }
getFields()
Returns all fields of this table including the standard fields.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fillMetaExcel()

ilDclContentExporter::fillMetaExcel ( ilDclTable  $table,
ilExcel  $worksheet,
int  $row 
)
protected

Fill Excel meta-data.

Definition at line 122 of file class.ilDclContentExporter.php.

Referenced by export().

122  : void
123  {
124  }
+ Here is the caller graph for this function:

◆ fillRowExcel()

ilDclContentExporter::fillRowExcel ( ilDclTable  $table,
ilExcel  $worksheet,
ilDclBaseRecordModel  $record,
int  $row 
)
protected

Fill a excel row.

Definition at line 91 of file class.ilDclContentExporter.php.

References ilDclBaseRecordModel\fillRecordFieldExcelExport(), and ilDclTable\getFields().

Referenced by export().

96  : void {
97  $col = 0;
98  foreach ($table->getFields() as $field) {
99  if ($field->getExportable()) {
100  $record->fillRecordFieldExcelExport($worksheet, $row, $col, $field->getId());
101  }
102  }
103  }
getFields()
Returns all fields of this table including the standard fields.
fillRecordFieldExcelExport(ilExcel $worksheet, int &$row, int &$col, $field_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExportContentPath()

ilDclContentExporter::getExportContentPath ( string  $format)

Return export path.

Definition at line 83 of file class.ilDclContentExporter.php.

References ilExport\_getExportDirectory().

Referenced by export().

83  : string
84  {
85  return ilExport::_getExportDirectory($this->dcl->getId(), $format, 'dcl') . '/';
86  }
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sanitizeFilename()

ilDclContentExporter::sanitizeFilename ( string  $filename)

Sanitize the given filename The ilUtil::_sanitizeFilename() does not clean enough.

Definition at line 73 of file class.ilDclContentExporter.php.

Referenced by export().

73  : string
74  {
75  $dangerous_filename_characters = [" ", '"', "'", "&", "/", "\\", "?", "#", "`"];
76 
77  return str_replace($dangerous_filename_characters, "_", iconv("utf-8", "ascii//TRANSLIT", $filename));
78  }
$filename
Definition: buildRTE.php:78
+ Here is the caller graph for this function:

Field Documentation

◆ $dcl

ilObjDataCollection ilDclContentExporter::$dcl
protected

Definition at line 44 of file class.ilDclContentExporter.php.

◆ $filter

array ilDclContentExporter::$filter
protected

Array with filters.

Definition at line 42 of file class.ilDclContentExporter.php.

Referenced by __construct(), and export().

◆ $lng

ilLanguage ilDclContentExporter::$lng
protected

Definition at line 46 of file class.ilDclContentExporter.php.

Referenced by __construct().

◆ $main_tpl

ilGlobalTemplateInterface ilDclContentExporter::$main_tpl
private

Definition at line 49 of file class.ilDclContentExporter.php.

◆ $ref_id

int ilDclContentExporter::$ref_id
protected

Ref-ID of DataCollection.

Definition at line 34 of file class.ilDclContentExporter.php.

Referenced by __construct().

◆ $table

ilDclTable ilDclContentExporter::$table
protected

Definition at line 48 of file class.ilDclContentExporter.php.

◆ $table_id

int ilDclContentExporter::$table_id
protected

Table-Id for export.

Definition at line 38 of file class.ilDclContentExporter.php.

Referenced by __construct(), and exportAsync().

◆ $tables

array ilDclContentExporter::$tables
protected

Definition at line 50 of file class.ilDclContentExporter.php.

◆ EXPORT_EXCEL

const ilDclContentExporter::EXPORT_EXCEL = 'xlsx'

Definition at line 29 of file class.ilDclContentExporter.php.

Referenced by ilDclRecordListTableGUI\exportData().

◆ IN_PROGRESS_POSTFIX

const ilDclContentExporter::IN_PROGRESS_POSTFIX = '.prog'

◆ SOAP_FUNCTION_NAME

const ilDclContentExporter::SOAP_FUNCTION_NAME = 'exportDataCollectionContent'

Definition at line 28 of file class.ilDclContentExporter.php.


The documentation for this class was generated from the following file: