ILIAS  trunk Revision v11.0_alpha-1831-g8615d53dadb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 25 of file class.ilDclContentExporter.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

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

52  {
53  global $DIC;
54  $this->main_tpl = $DIC->ui()->mainTemplate();
55  $lng = $DIC['lng'];
56 
57  $this->ref_id = $ref_id;
58  $this->table_id = $table_id;
59  $this->filter = $filter;
60 
61  $this->dcl = new ilObjDataCollection($ref_id);
62  $this->tables = ($table_id) ? [$this->dcl->getTableById($table_id)] : $this->dcl->getTables();
63 
64  $lng->loadLanguageModule('dcl');
65  $this->lng = $lng;
66  }
loadLanguageModule(string $a_module)
Load language module.
array $filter
Array with filters.
int $table_id
Table-Id for export.
global $DIC
Definition: shib_login.php:22
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 130 of file class.ilDclContentExporter.php.

References $filename, $filter, fillHeaderExcel(), fillMetaExcel(), fillRowExcel(), getExportContentPath(), ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), ILIAS\Repository\lng(), ilFileUtils\makeDirParents(), null, ilDclCache\resetCache(), and sanitizeFilename().

Referenced by ilDclRecordListTableGUI\exportData().

131  {
132  if (count($this->tables) == 0) {
133  return;
134  }
135 
136  if (empty($filepath)) {
137  $filepath = $this->getExportContentPath($format);
138  ilFileUtils::makeDirParents($filepath);
139 
140  $basename = (isset($this->table_id)) ? $this->tables[0]->getTitle() : 'complete';
141  $filename = time() . '__' . $basename . "_" . date("Y-m-d_H-i");
142 
143  $filepath .= $this->sanitizeFilename($filename);
144  } else {
145  $filename = pathinfo($filepath, PATHINFO_FILENAME);
146  }
147 
148  $in_progress_file = $filepath . self::IN_PROGRESS_POSTFIX;
149  file_put_contents($in_progress_file, "");
150 
151  $data_available = false;
152  $fields_available = false;
153  $adapter = new ilExcel();
154  if ($format == self::EXPORT_EXCEL) {
155  foreach ($this->tables as $table) {
157 
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) {
162  // only 31 character-long table-titles are allowed
163  $title = substr($table->getTitle(), 0, 31);
164  $adapter->addSheet($title);
165  $row = 1;
166 
167  $this->fillMetaExcel($table, $adapter, $row);
168 
169  // #14813
170  $this->fillHeaderExcel($table, $adapter, $row);
171  $row++;
172 
173  foreach ($list['records'] as $set) {
174  $this->fillRowExcel($table, $adapter, $set, $row);
175  $row++; // #14760
176  }
177 
178  $data_available = true;
179  }
180  }
181  }
182 
183  if (file_exists($in_progress_file)) {
184  unlink($in_progress_file);
185  }
186 
187  if (!$data_available || !$fields_available) {
188  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_no_export_data_available'));
189  return false;
190  }
191 
192  if ($send) {
193  $adapter->sendToClient($filename);
194  } else {
195  $adapter->writeToFile($filepath);
196  }
197  return true;
198  }
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.
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.
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 200 of file class.ilDclContentExporter.php.

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

Referenced by ilObjDataCollectionGUI\handleExportAsync().

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

◆ fillHeaderExcel()

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

Fill Excel header.

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

References ilDclTable\getFields().

Referenced by export().

107  : void
108  {
109  $col = 0;
110 
111  foreach ($table->getFields() as $field) {
112  if ($field->getExportable()) {
113  $field->fillHeaderExcel($worksheet, $row, $col);
114  }
115  }
116  }
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 121 of file class.ilDclContentExporter.php.

Referenced by export().

121  : void
122  {
123  }
+ 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 90 of file class.ilDclContentExporter.php.

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

Referenced by export().

95  : void {
96  $col = 0;
97  foreach ($table->getFields() as $field) {
98  if ($field->getExportable()) {
99  $record->fillRecordFieldExcelExport($worksheet, $row, $col, $field->getId());
100  }
101  }
102  }
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 82 of file class.ilDclContentExporter.php.

References ilExport\_getExportDirectory().

Referenced by export().

82  : string
83  {
84  return ilExport::_getExportDirectory($this->dcl->getId(), $format, 'dcl') . '/';
85  }
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 72 of file class.ilDclContentExporter.php.

Referenced by export().

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

Field Documentation

◆ $dcl

ilObjDataCollection ilDclContentExporter::$dcl
protected

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

◆ $filter

array ilDclContentExporter::$filter
protected

Array with filters.

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

Referenced by __construct(), and export().

◆ $lng

ilLanguage ilDclContentExporter::$lng
protected

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

Referenced by __construct().

◆ $main_tpl

ilGlobalTemplateInterface ilDclContentExporter::$main_tpl
private

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

◆ $ref_id

int ilDclContentExporter::$ref_id
protected

Ref-ID of DataCollection.

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

Referenced by __construct().

◆ $table

ilDclTable ilDclContentExporter::$table
protected

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

◆ $table_id

int ilDclContentExporter::$table_id
protected

Table-Id for export.

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

Referenced by __construct(), and exportAsync().

◆ $tables

array ilDclContentExporter::$tables
protected

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

◆ EXPORT_EXCEL

const ilDclContentExporter::EXPORT_EXCEL = 'xlsx'

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

Referenced by ilDclRecordListTableGUI\exportData().

◆ IN_PROGRESS_POSTFIX

const ilDclContentExporter::IN_PROGRESS_POSTFIX = '.prog'

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

◆ SOAP_FUNCTION_NAME

const ilDclContentExporter::SOAP_FUNCTION_NAME = 'exportDataCollectionContent'

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


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