ILIAS  release_7 Revision v7.30-3-g800a261c036
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 ($ref_id, $table_id=null, $filter=array())
 
 sanitizeFilename ($filename)
 Sanitize the given filename The ilUtil::_sanitizeFilemame() does not clean enough. More...
 
 getExportContentPath ($format)
 Return export path. More...
 
 export ($format=self::EXPORT_EXCEL, $filepath=null, $send=false)
 Creates an export of a specific datacollection table. More...
 
 exportAsync ($format=self::EXPORT_EXCEL, $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, $row)
 Fill a excel row. More...
 
 fillHeaderExcel (ilDclTable $table, ilExcel $worksheet, $row)
 Fill Excel header. More...
 
 fillMetaExcel ($table, $worksheet, $row)
 Fill Excel meta-data. More...
 

Protected Attributes

 $ref_id
 
 $table_id
 
 $filter
 
 $dcl
 
 $lng
 
 $table
 

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.

Author
Michael Herren mh@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

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

Constructor & Destructor Documentation

◆ __construct()

ilDclContentExporter::__construct (   $ref_id,
  $table_id = null,
  $filter = array() 
)

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

44 {
45 global $DIC;
46 $lng = $DIC['lng'];
47
48 $this->ref_id = $ref_id;
49 $this->table_id = $table_id;
50 $this->filter = $filter;
51
52 $this->dcl = new ilObjDataCollection($ref_id);
53 $this->tables = ($table_id) ? array($this->dcl->getTableById($table_id)) : $this->dcl->getTables();
54
55 $lng->loadLanguageModule('dcl');
56 $this->lng = $lng;
57 }
Class ilObjDataCollection.
filter()
Definition: filter.php:2
global $DIC
Definition: goto.php:24

References $DIC, $filter, $lng, $ref_id, $table_id, and filter().

+ Here is the call graph for this function:

Member Function Documentation

◆ export()

int $table_id Table Id for ilDclContentExporter::export (   $format = self::EXPORT_EXCEL,
  $filepath = null,
  $send = false 
)

Creates an export of a specific datacollection table.

Parameters
string$format
null$filepath
bool | false$send
Returns
null|string|void

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

149 {
150 if (count($this->tables) == 0) {
151 return;
152 }
153
154 if (empty($filepath)) {
155 $filepath = $this->getExportContentPath($format);
156 ilUtil::makeDirParents($filepath);
157
158 $basename = (isset($this->table_id)) ? $this->tables[0]->getTitle() : 'complete';
159 $filename = time() . '__' . $basename . "_" . date("Y-m-d_H-i");
160
161 $filepath .= $this->sanitizeFilename($filename);
162 } else {
163 $filename = pathinfo($filepath, PATHINFO_FILENAME);
164 }
165
166 $in_progress_file = $filepath . self::IN_PROGRESS_POSTFIX;
167 file_put_contents($in_progress_file, "");
168
169 $data_available = false;
170 $fields_available = false;
171 switch ($format) {
173 $adapter = new ilExcel();
174 foreach ($this->tables as $table) {
176
177 $list = $table->getPartialRecords(null, null, null, 0, $this->filter);
178 $data_available = $data_available || ($list['total'] > 0);
179 $fields_available = $fields_available || (count($table->getExportableFields()) > 0);
180 if ($list['total'] > 0 && count($table->getExportableFields()) > 0) {
181 // only 31 character-long table-titles are allowed
182 $title = substr($table->getTitle(), 0, 31);
183 $adapter->addSheet($title);
184 $row = 1;
185
186 $this->fillMetaExcel($table, $adapter, $row);
187
188 // #14813
189 $pre = $row;
190 $this->fillHeaderExcel($table, $adapter, $row);
191 if ($pre == $row) {
192 $row++;
193 }
194
195 foreach ($list['records'] as $set) {
196 $this->fillRowExcel($table, $adapter, $set, $row);
197 $row++; // #14760
198 }
199
200 $data_available = true;
201 }
202 }
203 break;
204 }
205
206 if (file_exists($in_progress_file)) {
207 unlink($in_progress_file);
208 }
209
210 if (!$data_available) {
211 ilUtil::sendInfo($this->lng->txt('dcl_no_export_content_available'));
212
213 return false;
214 }
215
216 if (!$fields_available) {
217 global $ilCtrl;
219 sprintf(
220 $this->lng->txt('dcl_no_export_fields_available'),
221 $ilCtrl->getLinkTargetByClass(array('ilDclTableListGUI', 'ilDclTableEditGUI', 'ilDclFieldListGUI'), 'listFields')
222 )
223 );
224
225 return false;
226 }
227
228 if ($send) {
229 $adapter->sendToClient($filename);
230 exit;
231 } else {
232 $adapter->writeToFile($filepath);
233 }
234 }
$filename
Definition: buildRTE.php:89
static resetCache()
Resets all the cache fields.
getExportContentPath($format)
Return export path.
fillHeaderExcel(ilDclTable $table, ilExcel $worksheet, $row)
Fill Excel header.
fillMetaExcel($table, $worksheet, $row)
Fill Excel meta-data.
sanitizeFilename($filename)
Sanitize the given filename The ilUtil::_sanitizeFilemame() does not clean enough.
fillRowExcel(ilDclTable $table, ilExcel $worksheet, ilDclBaseRecordModel $record, $row)
Fill a excel row.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
exit
Definition: login.php:29
$format
Definition: metadata.php:218

References $filename, $format, $table, exit, EXPORT_EXCEL, fillHeaderExcel(), fillMetaExcel(), fillRowExcel(), filter(), getExportContentPath(), IN_PROGRESS_POSTFIX, ilUtil\makeDirParents(), ilDclCache\resetCache(), sanitizeFilename(), and ilUtil\sendInfo().

+ Here is the call graph for this function:

◆ exportAsync()

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

Start Export async.

Parameters
string$format
null$filepath
Returns
mixed
Exceptions
ilDclException

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

247 {
248 global $DIC;
249 $ilLog = $DIC['ilLog'];
250
251 $method = self::SOAP_FUNCTION_NAME;
252
253 $soap_params = array($this->dcl->getRefId());
254 array_push($soap_params, $this->table_id, $format, $filepath);
255
256 $new_session_id = ilSession::_duplicate($_COOKIE[session_name()]);
257 $client_id = $_COOKIE['ilClientId'];
258
259 // Start cloning process using soap call
260 $soap_client = new ilSoapClient();
261 $soap_client->setResponseTimeout(5);
262 $soap_client->enableWSDL(true);
263
264 $ilLog->write(__METHOD__ . ': Trying to call Soap client...');
265
266 array_unshift($soap_params, $new_session_id . '::' . $client_id);
267
268 if ($soap_client->init()) {
269 $ilLog->info('Calling soap ' . $method . ' method with params ' . print_r($soap_params, true));
270 $res = $soap_client->call($method, $soap_params);
271 } else {
272 $ilLog->warning('SOAP clone call failed. Calling clone method manually');
273 require_once('./webservice/soap/include/inc.soap_functions.php');
274 if (method_exists('ilSoapFunctions', $method)) {
275 $res = ilSoapFunctions::$method($new_session_id . '::' . $client_id, $this->dcl->getRefId(), $this->table_id, $format, $filepath);
276 } else {
277 throw new ilDclException("SOAP call " . $method . " does not exists!");
278 }
279 }
280
281 return $res;
282 }
Class ilDclException.
static _duplicate($a_session_id)
Duplicate session.
foreach($_POST as $key=> $value) $res
$client_id
Definition: webdav.php:17
$_COOKIE[session_name()]
Definition: xapitoken.php:37

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

+ Here is the call graph for this function:

◆ fillHeaderExcel()

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

Fill Excel header.

Parameters
ilDclTable$table
ilExcel$worksheet
$row

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

116 {
117 $col = 0;
118
119 foreach ($table->getFields() as $field) {
120 if ($field->getExportable()) {
121 $field->fillHeaderExcel($worksheet, $row, $col);
122 }
123 }
124 }

References $table.

Referenced by export().

+ Here is the caller graph for this function:

◆ fillMetaExcel()

ilDclContentExporter::fillMetaExcel (   $table,
  $worksheet,
  $row 
)
protected

Fill Excel meta-data.

Parameters
$table
$worksheet
$row

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

135 {
136 }

Referenced by export().

+ Here is the caller graph for this function:

◆ fillRowExcel()

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

Fill a excel row.

Parameters
ilDclTable$table
ilExcel$worksheet
ilDclBaseRecordModel$record
$row

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

98 {
99 $col = 0;
100 foreach ($table->getFields() as $field) {
101 if ($field->getExportable()) {
102 $record->fillRecordFieldExcelExport($worksheet, $row, $col, $field->getId());
103 }
104 }
105 }
fillRecordFieldExcelExport(ilExcel $worksheet, &$row, &$col, $field_id)

References $table, and ilDclBaseRecordModel\fillRecordFieldExcelExport().

Referenced by export().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExportContentPath()

ilDclContentExporter::getExportContentPath (   $format)

Return export path.

Parameters
$format
Returns
string

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

84 {
85 return ilExport::_getExportDirectory($this->dcl->getId(), $format, 'dcl') . '/';
86 }
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.

References $format, and ilExport\_getExportDirectory().

Referenced by export().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sanitizeFilename()

ilDclContentExporter::sanitizeFilename (   $filename)

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

Parameters
$filename
Returns
string

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

69 {
70 $dangerous_filename_characters = array(" ", '"', "'", "&", "/", "\\", "?", "#", "`");
71
72 return str_replace($dangerous_filename_characters, "_", iconv("utf-8", "ascii//TRANSLIT", $filename));
73 }

References $filename.

Referenced by export().

+ Here is the caller graph for this function:

Field Documentation

◆ $dcl

ilDclContentExporter::$dcl
protected

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

◆ $filter

ilDclContentExporter::$filter
protected

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

Referenced by __construct().

◆ $lng

ilDclContentExporter::$lng
protected

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

Referenced by __construct().

◆ $ref_id

ilDclContentExporter::$ref_id
protected

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

Referenced by __construct().

◆ $table

ilDclContentExporter::$table
protected

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

Referenced by export(), fillHeaderExcel(), and fillRowExcel().

◆ $table_id

ilDclContentExporter::$table_id
protected

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

Referenced by __construct().

◆ EXPORT_EXCEL

const ilDclContentExporter::EXPORT_EXCEL = 'xlsx'

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

Referenced by export(), and ilDclRecordListTableGUI\exportData().

◆ IN_PROGRESS_POSTFIX

const ilDclContentExporter::IN_PROGRESS_POSTFIX = '.prog'

◆ SOAP_FUNCTION_NAME

const ilDclContentExporter::SOAP_FUNCTION_NAME = 'exportDataCollectionContent'

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

Referenced by exportAsync().


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