ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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.

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
65 $this->lng = $lng;
66 }
int $ref_id
Ref-ID of DataCollection.
array $filter
Array with filters.
int $table_id
Table-Id for export.
loadLanguageModule(string $a_module)
Load language module.
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26

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

+ 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

PhpOffice\PhpSpreadsheet\Writer\Exception|\PhpOffice\PhpSpreadsheet\Exception

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

131 {
132 if (count($this->tables) == 0) {
133 return;
134 }
135
136 if (empty($filepath)) {
137 $filepath = $this->getExportContentPath($format);
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 $this->main_tpl->setOnScreenMessage($this->main_tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('exp_file_created'), true);
193 if ($send) {
194 $adapter->sendToClient($filename);
195 } else {
196 $adapter->writeToFile($filepath);
197 }
198 return true;
199 }
$filename
Definition: buildRTE.php:78
static resetCache()
Resets all the cache fields.
fillMetaExcel(ilDclTable $table, ilExcel $worksheet, int $row)
Fill Excel meta-data.
sanitizeFilename(string $filename)
Sanitize the given filename The ilUtil::_sanitizeFilename() does not clean enough.
getExportContentPath(string $format)
Return export path.
fillRowExcel(ilDclTable $table, ilExcel $worksheet, ilDclBaseRecordModel $record, int $row)
Fill a excel row.
fillHeaderExcel(ilDclTable $table, ilExcel $worksheet, int $row)
Fill Excel header.
getExportableFields()
Return all the fields that are marked as exportable.
getPartialRecords(string $ref_id, string $sort, string $direction, ?int $limit, int $offset, array $filter=[])
Return only the needed subset of record objects for the table, according to sorting,...
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.

References $filename, ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), ILIAS\Repository\lng(), ilFileUtils\makeDirParents(), and ilDclCache\resetCache().

+ Here is the call graph for this function:

◆ exportAsync()

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

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

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

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

+ Here is the call 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.

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.

References ilDclTable\getFields().

+ Here is the call 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.

121 : void
122 {
123 }

◆ 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.

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 }
fillRecordFieldExcelExport(ilExcel $worksheet, int &$row, int &$col, $field_id)

References ilDclBaseRecordModel\fillRecordFieldExcelExport().

+ Here is the call graph for this function:

◆ getExportContentPath()

ilDclContentExporter::getExportContentPath ( string  $format)

Return export path.

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

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="")
@depricated Get export directory for an repository object

References ilExport\_getExportDirectory().

+ Here is the call 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.

72 : string
73 {
74 $dangerous_filename_characters = [" ", '"', "'", "&", "/", "\\", "?", "#", "`"];
75
76 return str_replace($dangerous_filename_characters, "_", iconv("utf-8", "ascii//TRANSLIT", $filename));
77 }

References $filename.

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().

◆ $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().

◆ $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: