ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilDclContentExporter Class Reference
+ 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)
 
 export (string $format=self::EXPORT_EXCEL, ?string $filepath=null, bool $send=false)
 
 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)
 
 fillHeaderExcel (ilDclTable $table, ilExcel $worksheet, int $row)
 
 fillMetaExcel (ilDclTable $table, ilExcel $worksheet, int $row)
 

Protected Attributes

int $ref_id
 
int $table_id
 
array $filter
 
ilObjDataCollection $dcl
 
ilLanguage $lng
 
ilDclTable $table
 
array $tables
 

Private Attributes

ilGlobalTemplateInterface $main_tpl
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

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

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

36 {
37 global $DIC;
38 $this->main_tpl = $DIC->ui()->mainTemplate();
39 $lng = $DIC->language();
40
41 $this->ref_id = $ref_id;
42 $this->table_id = $table_id;
43 $this->filter = $filter;
44
45 $this->dcl = new ilObjDataCollection($ref_id);
46 $this->tables = ($table_id) ? [$this->dcl->getTableById($table_id)] : $this->dcl->getTables();
47
49 $this->lng = $lng;
50 }
loadLanguageModule(string $a_module)
Load language module.
filter(string $filter_id, array $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 
)

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

97 : bool
98 {
99 if (empty($filepath)) {
100 $filepath = $this->getExportContentPath($format);
102
103 $basename = (isset($this->table_id)) ? $this->tables[0]->getTitle() : 'complete';
104 $filename = time() . '__' . $basename . "_" . date("Y-m-d_H-i");
105
106 $filepath .= $this->sanitizeFilename($filename);
107 } else {
108 $filename = pathinfo($filepath, PATHINFO_FILENAME);
109 }
110
111 $in_progress_file = $filepath . self::IN_PROGRESS_POSTFIX;
112 file_put_contents($in_progress_file, "");
113
114 $data_available = false;
115 $fields_available = false;
116 $adapter = new ilExcel();
117 if ($format == self::EXPORT_EXCEL) {
118 foreach ($this->tables as $table) {
120
121 $list = $table->getPartialRecords((string) $this->dcl->getRefId(), 'id', 'asc', null, 0, $this->filter);
122 $data_available = $data_available || ($list['total'] > 0);
123 $fields_available = $fields_available || (count($table->getExportableFields()) > 0);
124 if ($list['total'] > 0 && count($table->getExportableFields()) > 0) {
125 $adapter->addSheet($table->getTitle());
126 $row = 1;
127 $this->fillMetaExcel($table, $adapter, $row);
128 $this->fillHeaderExcel($table, $adapter, $row);
129 $row++;
130 foreach ($list['records'] as $set) {
131 $this->fillRowExcel($table, $adapter, $set, $row);
132 $row++;
133 }
134
135 $data_available = true;
136 }
137 }
138 }
139
140 if (file_exists($in_progress_file)) {
141 unlink($in_progress_file);
142 }
143
144 if (!$data_available || !$fields_available) {
145 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_no_export_data_available'));
146 return false;
147 }
148
149 $this->main_tpl->setOnScreenMessage($this->main_tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('exp_file_created'), true);
150 if ($send) {
151 $adapter->sendToClient($filename);
152 } else {
153 $adapter->writeToFile($filepath);
154 }
155 return true;
156 }
$filename
Definition: buildRTE.php:78
static resetCache()
Resets all the cache fields.
fillMetaExcel(ilDclTable $table, ilExcel $worksheet, int $row)
sanitizeFilename(string $filename)
Sanitize the given filename The ilUtil::_sanitizeFilename() does not clean enough.
fillRowExcel(ilDclTable $table, ilExcel $worksheet, ilDclBaseRecordModel $record, int $row)
fillHeaderExcel(ilDclTable $table, ilExcel $worksheet, int $row)
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 158 of file class.ilDclContentExporter.php.

158 : mixed
159 {
160 global $DIC;
161
162 $method = self::SOAP_FUNCTION_NAME;
163
164 $soap_params = [$this->dcl->getRefId()];
165 array_push($soap_params, $this->table_id, $format, $filepath);
166
167 $new_session_id = ilSession::_duplicate(
168 $DIC->http()->wrapper()->cookie()->retrieve(session_name(), $DIC->refinery()->kindlyTo()->string())
169 );
170 $client_id = $DIC->http()->wrapper()->cookie()->retrieve('ilClientId', $DIC->refinery()->kindlyTo()->string());
171
172 $soap_client = new ilSoapClient();
173 $soap_client->setResponseTimeout(5);
174 $soap_client->enableWSDL(true);
175
176 $DIC->logger()->root()->write(__METHOD__ . ': Trying to call Soap client...');
177
178 array_unshift($soap_params, $new_session_id . '::' . $client_id);
179
180 if ($soap_client->init()) {
181 $DIC->logger()->root()->info('Calling soap ' . $method . ' method with params ' . print_r($soap_params, true));
182 $res = $soap_client->call($method, $soap_params);
183 } else {
184 $DIC->logger()->root()->warning('SOAP clone call failed. Calling clone method manually');
185 if (method_exists('ilSoapFunctions', $method)) {
186 $res = ilSoapFunctions::$method(
187 $new_session_id . '::' . $client_id,
188 $this->dcl->getRefId(),
189 $this->table_id,
190 $format,
191 $filepath
192 );
193 } else {
194 throw new ilDclException("SOAP call " . $method . " does not exists!");
195 }
196 }
197
198 return $res;
199 }
static _duplicate(string $a_session_id)
Duplicate session.
$client_id
Definition: ltiauth.php:67
$res
Definition: ltiservices.php:69

References $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

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

82 : void
83 {
84 $col = 0;
85
86 foreach ($table->getFields() as $field) {
87 if ($field->getExportable()) {
88 $field->fillHeaderExcel($worksheet, $row, $col);
89 }
90 }
91 }
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

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

93 : void
94 {
95 }

◆ fillRowExcel()

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

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

73 : void {
74 $col = 0;
75 foreach ($table->getFields() as $field) {
76 if ($field->getExportable()) {
77 $record->fillRecordFieldExcelExport($worksheet, $row, $col, $field->getId());
78 }
79 }
80 }
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)

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

63 : string
64 {
65 return ilExport::_getExportDirectory($this->dcl->getId(), $format, 'dcl') . '/';
66 }
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 56 of file class.ilDclContentExporter.php.

56 : string
57 {
58 $dangerous_filename_characters = [" ", '"', "'", "&", "/", "\\", "?", "#", "`"];
59
60 return str_replace($dangerous_filename_characters, "_", iconv("utf-8", "ascii//TRANSLIT", $filename));
61 }

References $filename.

Field Documentation

◆ $dcl

ilObjDataCollection ilDclContentExporter::$dcl
protected

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

◆ $filter

array ilDclContentExporter::$filter
protected

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

Referenced by __construct().

◆ $lng

ilLanguage ilDclContentExporter::$lng
protected

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

Referenced by __construct().

◆ $main_tpl

ilGlobalTemplateInterface ilDclContentExporter::$main_tpl
private

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

◆ $ref_id

int ilDclContentExporter::$ref_id
protected

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

Referenced by __construct().

◆ $table

ilDclTable ilDclContentExporter::$table
protected

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

◆ $table_id

int ilDclContentExporter::$table_id
protected

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

Referenced by __construct().

◆ $tables

array ilDclContentExporter::$tables
protected

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

◆ EXPORT_EXCEL

const ilDclContentExporter::EXPORT_EXCEL = 'xlsx'

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

Referenced by ilDclRecordListTableGUI\exportData().

◆ IN_PROGRESS_POSTFIX

const ilDclContentExporter::IN_PROGRESS_POSTFIX = '.prog'

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

◆ SOAP_FUNCTION_NAME

const ilDclContentExporter::SOAP_FUNCTION_NAME = 'exportDataCollectionContent'

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


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