ILIAS  release_8 Revision v8.24
ilDclContentExporter Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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)
 Start Export async. More...
 

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

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

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

Constructor & Destructor Documentation

◆ __construct()

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

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

46 {
47 global $DIC;
48 $this->main_tpl = $DIC->ui()->mainTemplate();
49 $lng = $DIC['lng'];
50
51 $this->ref_id = $ref_id;
52 $this->table_id = $table_id;
53 $this->filter = $filter;
54
55 $this->dcl = new ilObjDataCollection($ref_id);
56 $this->tables = ($table_id) ? [$this->dcl->getTableById($table_id)] : $this->dcl->getTables();
57
59 $this->lng = $lng;
60 }
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28

References $DIC, $filter, $lng, $ref_id, $table_id, ILIAS\UI\examples\Symbol\Glyph\Filter\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 124 of file class.ilDclContentExporter.php.

125 {
126 if (count($this->tables) == 0) {
127 return;
128 }
129
130 if (empty($filepath)) {
131 $filepath = $this->getExportContentPath($format);
133
134 $basename = (isset($this->table_id)) ? $this->tables[0]->getTitle() : 'complete';
135 $filename = time() . '__' . $basename . "_" . date("Y-m-d_H-i");
136
137 $filepath .= $this->sanitizeFilename($filename);
138 } else {
139 $filename = pathinfo($filepath, PATHINFO_FILENAME);
140 }
141
142 $in_progress_file = $filepath . self::IN_PROGRESS_POSTFIX;
143 file_put_contents($in_progress_file, "");
144
145 $data_available = false;
146 $fields_available = false;
147 if ($format == self::EXPORT_EXCEL) {
148 $adapter = new ilExcel();
149 foreach ($this->tables as $table) {
151
152 $list = $table->getPartialRecords($this->dcl->getRefId(), 'id', 'asc', null, 0, $this->filter);
153 $data_available = $data_available || ($list['total'] > 0);
154 $fields_available = $fields_available || (count($table->getExportableFields()) > 0);
155 if ($list['total'] > 0 && count($table->getExportableFields()) > 0) {
156 // only 31 character-long table-titles are allowed
157 $title = substr($table->getTitle(), 0, 31);
158 $adapter->addSheet($title);
159 $row = 1;
160
161 $this->fillMetaExcel($table, $adapter, $row);
162
163 // #14813
164 $pre = $row;
165 $this->fillHeaderExcel($table, $adapter, $row);
166 if ($pre == $row) {
167 $row++;
168 }
169
170 foreach ($list['records'] as $set) {
171 $this->fillRowExcel($table, $adapter, $set, $row);
172 $row++; // #14760
173 }
174
175 $data_available = true;
176 }
177 }
178 }
179
180 if (file_exists($in_progress_file)) {
181 unlink($in_progress_file);
182 }
183
184 if (!$data_available) {
185 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('dcl_no_export_content_available'));
186
187 return false;
188 }
189
190 if (!$fields_available) {
191 global $ilCtrl;
192 $this->main_tpl->setOnScreenMessage('info', sprintf(
193 $this->lng->txt('dcl_no_export_fields_available'),
194 $ilCtrl->getLinkTargetByClass(
195 ['ilDclTableListGUI', 'ilDclFieldListGUI'],
196 'listFields'
197 )
198 ));
199 return false;
200 }
201
202 if ($send) {
203 $adapter->sendToClient($filename);
204 } else {
205 $adapter->writeToFile($filepath);
206 }
207 return true;
208 }
$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.
$format
Definition: metadata.php:235

References $filename, $format, 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 
)

Start Export async.

Returns
mixed
Exceptions
ilDclException

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

216 {
217 global $DIC;
218 $ilLog = $DIC['ilLog'];
219
220 $method = self::SOAP_FUNCTION_NAME;
221
222 $soap_params = [$this->dcl->getRefId()];
223 array_push($soap_params, $this->table_id, $format, $filepath);
224
225 $new_session_id = ilSession::_duplicate($_COOKIE[session_name()]);
226 $client_id = $_COOKIE['ilClientId'];
227
228 // Start cloning process using soap call
229 $soap_client = new ilSoapClient();
230 $soap_client->setResponseTimeout(5);
231 $soap_client->enableWSDL(true);
232
233 $ilLog->write(__METHOD__ . ': Trying to call Soap client...');
234
235 array_unshift($soap_params, $new_session_id . '::' . $client_id);
236
237 if ($soap_client->init()) {
238 $ilLog->info('Calling soap ' . $method . ' method with params ' . print_r($soap_params, true));
239 $res = $soap_client->call($method, $soap_params);
240 } else {
241 $ilLog->warning('SOAP clone call failed. Calling clone method manually');
242 if (method_exists('ilSoapFunctions', $method)) {
243 $res = ilSoapFunctions::$method(
244 $new_session_id . '::' . $client_id,
245 $this->dcl->getRefId(),
246 $this->table_id,
247 $format,
248 $filepath
249 );
250 } else {
251 throw new ilDclException("SOAP call " . $method . " does not exists!");
252 }
253 }
254
255 return $res;
256 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _duplicate(string $a_session_id)
Duplicate session.
$client_id
Definition: ltiauth.php:68
$res
Definition: ltiservices.php:69
$_COOKIE[session_name()]
Definition: xapitoken.php:54

References $_COOKIE, $client_id, $DIC, $format, $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 101 of file class.ilDclContentExporter.php.

101 : void
102 {
103 $col = 0;
104
105 foreach ($table->getFields() as $field) {
106 if ($field->getExportable()) {
107 $field->fillHeaderExcel($worksheet, $row, $col);
108 }
109 }
110 }
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 115 of file class.ilDclContentExporter.php.

115 : void
116 {
117 }

◆ fillRowExcel()

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

Fill a excel row.

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

89 : void {
90 $col = 0;
91 foreach ($table->getFields() as $field) {
92 if ($field->getExportable()) {
93 $record->fillRecordFieldExcelExport($worksheet, $row, $col, $field->getId());
94 }
95 }
96 }
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 76 of file class.ilDclContentExporter.php.

76 : string
77 {
78 return ilExport::_getExportDirectory($this->dcl->getId(), $format, 'dcl') . '/';
79 }
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object.

References $format, and 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 66 of file class.ilDclContentExporter.php.

66 : string
67 {
68 $dangerous_filename_characters = [" ", '"', "'", "&", "/", "\\", "?", "#", "`"];
69
70 return str_replace($dangerous_filename_characters, "_", iconv("utf-8", "ascii//TRANSLIT", $filename));
71 }

References $filename.

Field Documentation

◆ $dcl

ilObjDataCollection ilDclContentExporter::$dcl
protected

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

◆ $filter

array ilDclContentExporter::$filter
protected

Array with filters.

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

Referenced by __construct().

◆ $lng

ilLanguage ilDclContentExporter::$lng
protected

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

Referenced by __construct().

◆ $main_tpl

ilGlobalTemplateInterface ilDclContentExporter::$main_tpl
private

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

◆ $ref_id

int ilDclContentExporter::$ref_id
protected

Ref-ID of DataCollection.

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

Referenced by __construct().

◆ $table

ilDclTable ilDclContentExporter::$table
protected

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

◆ $table_id

int ilDclContentExporter::$table_id
protected

Table-Id for export.

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

Referenced by __construct().

◆ $tables

array ilDclContentExporter::$tables
protected

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

◆ EXPORT_EXCEL

const ilDclContentExporter::EXPORT_EXCEL = 'xlsx'

Definition at line 22 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 21 of file class.ilDclContentExporter.php.


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