ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 20 of file class.ilDclContentExporter.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

57 {
58 global $DIC;
59 $lng = $DIC['lng'];
60
61 $this->ref_id = $ref_id;
62 $this->table_id = $table_id;
63 $this->filter = $filter;
64
65 $this->dcl = new ilObjDataCollection($ref_id);
66 $this->tables = ($table_id)? array($this->dcl->getTableById($table_id)) : $this->dcl->getTables();
67
68 $lng->loadLanguageModule('dcl');
69 $this->lng = $lng;
70 }
Class ilObjDataCollection.
global $DIC

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

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 152 of file class.ilDclContentExporter.php.

152 {
153
154 if(count($this->tables) == 0) {
155 return;
156 }
157
158 if(empty($filepath)) {
159 $filepath = $this->getExportContentPath($format);
160 ilUtil::makeDirParents($filepath);
161
162 $basename = (isset($this->table_id))? $this->tables[0]->getTitle() : 'complete';
163 $filename = time() . '__' . $basename . "_".date("Y-m-d_H-i");
164
165 $filepath .= $this->sanitizeFilename($filename);
166 } else {
167 $filename = pathinfo($filepath, PATHINFO_FILENAME);
168 }
169
170 $in_progress_file = $filepath.self::IN_PROGRESS_POSTFIX;
171 file_put_contents($in_progress_file, "");
172
173 $data_available = false;
174 $fields_available = false;
175 switch ($format) {
177 require_once "./Services/Excel/classes/class.ilExcel.php";
178
179 $adapter = new ilExcel();
180 foreach($this->tables as $table) {
182
183 $list = $table->getPartialRecords(null, null, null, 0, $this->filter);
184 $data_available = $data_available || ($list['total'] > 0);
185 $fields_available = $fields_available || (count($table->getExportableFields()) > 0);
186 if ($list['total'] > 0 && count($table->getExportableFields()) > 0) {
187 // only 31 character-long table-titles are allowed
188 $title = substr($table->getTitle(), 0, 31);
189 $adapter->addSheet($title);
190 $row = 1;
191
192 $this->fillMetaExcel($table, $adapter, $row);
193
194 // #14813
195 $pre = $row;
196 $this->fillHeaderExcel($table, $adapter, $row);
197 if ($pre == $row) {
198 $row ++;
199 }
200
201 foreach ($list['records'] as $set) {
202 $this->fillRowExcel($table, $adapter, $set, $row);
203 $row ++; // #14760
204 }
205
206 $data_available = true;
207 }
208 }
209 break;
210 }
211
212 if (file_exists($in_progress_file)) {
213 unlink($in_progress_file);
214 }
215
216 if (!$data_available) {
217 ilUtil::sendInfo($this->lng->txt('dcl_no_export_content_available'));
218 return false;
219 }
220
221 if (!$fields_available) {
222 global $ilCtrl;
223 ilUtil::sendInfo(sprintf($this->lng->txt('dcl_no_export_fields_available'),
224 $ilCtrl->getLinkTargetByClass(array('ilDclTableListGUI', 'ilDclTableEditGUI', 'ilDclFieldListGUI'), 'listFields')));
225 return false;
226 }
227
228 if ($send) {
229 $adapter->sendToClient($filename);
230 exit;
231 } else {
232 $adapter->writeToFile($filepath);
233 }
234 }
sprintf('%.4f', $callTime)
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.
global $ilCtrl
Definition: ilias.php:18

References $adapter, $filename, $ilCtrl, $row, $table, $title, exit, EXPORT_EXCEL, fillHeaderExcel(), fillMetaExcel(), fillRowExcel(), getExportContentPath(), ilUtil\makeDirParents(), ilDclCache\resetCache(), sanitizeFilename(), ilUtil\sendInfo(), and sprintf.

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

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

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

122 {
123 $col = 0;
124
125 foreach ($table->getFields() as $field) {
126 if ($field->getExportable()) {
127 $field->fillHeaderExcel($worksheet, $row, $col);
128 }
129 }
130 }
$worksheet

References $row, $table, and $worksheet.

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 140 of file class.ilDclContentExporter.php.

140{ }

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 105 of file class.ilDclContentExporter.php.

105 {
106 $col = 0;
107 foreach ($table->getFields() as $field) {
108 if ($field->getExportable()) {
109 $record->fillRecordFieldExcelExport($worksheet, $row, $col, $field->getId());
110 }
111 }
112 }
fillRecordFieldExcelExport(ilExcel $worksheet, &$row, &$col, $field_id)

References $row, $table, $worksheet, 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 92 of file class.ilDclContentExporter.php.

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

References 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 80 of file class.ilDclContentExporter.php.

80 {
81 $dangerous_filename_characters = array(" ", '"', "'", "&", "/", "\\", "?", "#", "`");
82 return str_replace($dangerous_filename_characters, "_", iconv("utf-8","ascii//TRANSLIT", $filename));
83 }

References $filename.

Referenced by export().

+ Here is the caller graph for this function:

Field Documentation

◆ $dcl

ilDclContentExporter::$dcl
protected

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

◆ $filter

ilDclContentExporter::$filter
protected

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

Referenced by __construct().

◆ $lng

ilDclContentExporter::$lng
protected

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

Referenced by __construct().

◆ $ref_id

ilDclContentExporter::$ref_id
protected

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

Referenced by __construct().

◆ $table

ilDclContentExporter::$table
protected

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

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

◆ $table_id

ilDclContentExporter::$table_id
protected

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

Referenced by __construct().

◆ EXPORT_EXCEL

const ilDclContentExporter::EXPORT_EXCEL = 'xlsx'

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

Referenced by exportAsync().


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