ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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.

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

58  {
59  global $DIC;
60  $lng = $DIC['lng'];
61 
62  $this->ref_id = $ref_id;
63  $this->table_id = $table_id;
64  $this->filter = $filter;
65 
66  $this->dcl = new ilObjDataCollection($ref_id);
67  $this->tables = ($table_id)? array($this->dcl->getTableById($table_id)) : $this->dcl->getTables();
68 
69  $lng->loadLanguageModule('dcl');
70  $this->lng = $lng;
71  }
global $DIC
Definition: saml.php:7
Create styles array
The data for the language used.
Class ilObjDataCollection.

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

References $adapter, $filename, $format, $ilCtrl, $list, $row, $table, $title, array, date, exit, fillHeaderExcel(), fillMetaExcel(), fillRowExcel(), getExportContentPath(), ilUtil\makeDirParents(), ilDclCache\resetCache(), sanitizeFilename(), ilUtil\sendInfo(), and time.

Referenced by ilDclRecordListTableGUI\exportData().

160  {
161  if (count($this->tables) == 0) {
162  return;
163  }
164 
165  if (empty($filepath)) {
166  $filepath = $this->getExportContentPath($format);
167  ilUtil::makeDirParents($filepath);
168 
169  $basename = (isset($this->table_id))? $this->tables[0]->getTitle() : 'complete';
170  $filename = time() . '__' . $basename . "_" . date("Y-m-d_H-i");
171 
172  $filepath .= $this->sanitizeFilename($filename);
173  } else {
174  $filename = pathinfo($filepath, PATHINFO_FILENAME);
175  }
176 
177  $in_progress_file = $filepath . self::IN_PROGRESS_POSTFIX;
178  file_put_contents($in_progress_file, "");
179 
180  $data_available = false;
181  $fields_available = false;
182  switch ($format) {
183  case self::EXPORT_EXCEL:
184  require_once "./Services/Excel/classes/class.ilExcel.php";
185 
186  $adapter = new ilExcel();
187  foreach ($this->tables as $table) {
189 
190  $list = $table->getPartialRecords(null, null, null, 0, $this->filter);
191  $data_available = $data_available || ($list['total'] > 0);
192  $fields_available = $fields_available || (count($table->getExportableFields()) > 0);
193  if ($list['total'] > 0 && count($table->getExportableFields()) > 0) {
194  // only 31 character-long table-titles are allowed
195  $title = substr($table->getTitle(), 0, 31);
196  $adapter->addSheet($title);
197  $row = 1;
198 
199  $this->fillMetaExcel($table, $adapter, $row);
200 
201  // #14813
202  $pre = $row;
203  $this->fillHeaderExcel($table, $adapter, $row);
204  if ($pre == $row) {
205  $row++;
206  }
207 
208  foreach ($list['records'] as $set) {
209  $this->fillRowExcel($table, $adapter, $set, $row);
210  $row++; // #14760
211  }
212 
213  $data_available = true;
214  }
215  }
216  break;
217  }
218 
219  if (file_exists($in_progress_file)) {
220  unlink($in_progress_file);
221  }
222 
223  if (!$data_available) {
224  ilUtil::sendInfo($this->lng->txt('dcl_no_export_content_available'));
225  return false;
226  }
227 
228  if (!$fields_available) {
229  global $ilCtrl;
230  ilUtil::sendInfo(sprintf(
231  $this->lng->txt('dcl_no_export_fields_available'),
232  $ilCtrl->getLinkTargetByClass(array('ilDclTableListGUI', 'ilDclTableEditGUI', 'ilDclFieldListGUI'), 'listFields')
233  ));
234  return false;
235  }
236 
237  if ($send) {
238  $adapter->sendToClient($filename);
239  exit;
240  } else {
241  $adapter->writeToFile($filepath);
242  }
243  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
$format
Definition: metadata.php:141
fillHeaderExcel(ilDclTable $table, ilExcel $worksheet, $row)
Fill Excel header.
static resetCache()
Resets all the cache fields.
global $ilCtrl
Definition: ilias.php:18
fillRowExcel(ilDclTable $table, ilExcel $worksheet, ilDclBaseRecordModel $record, $row)
Fill a excel row.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
fillMetaExcel($table, $worksheet, $row)
Fill Excel meta-data.
sanitizeFilename($filename)
Sanitize the given filename The ilUtil::_sanitizeFilemame() does not clean enough.
Create styles array
The data for the language used.
getExportContentPath($format)
Return export path.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the call graph for this function:
+ Here is the caller 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 255 of file class.ilDclContentExporter.php.

References $_COOKIE, $client_id, $DIC, $format, $ilLog, $res, $table_id, ilSession\_duplicate(), and array.

256  {
257  global $DIC;
258  $ilLog = $DIC['ilLog'];
259 
260  $method = self::SOAP_FUNCTION_NAME;
261 
262  $soap_params = array($this->dcl->getRefId());
263  array_push($soap_params, $this->table_id, $format, $filepath);
264 
265  $new_session_id = ilSession::_duplicate($_COOKIE['PHPSESSID']);
266  $client_id = $_COOKIE['ilClientId'];
267 
268  // Start cloning process using soap call
269  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
270 
271  $soap_client = new ilSoapClient();
272  $soap_client->setResponseTimeout(5);
273  $soap_client->enableWSDL(true);
274 
275  $ilLog->write(__METHOD__ . ': Trying to call Soap client...');
276 
277  array_unshift($soap_params, $new_session_id . '::' . $client_id);
278 
279  if ($soap_client->init()) {
280  $ilLog->info('Calling soap ' . $method . ' method with params ' . print_r($soap_params, true));
281  $res = $soap_client->call($method, $soap_params);
282  } else {
283  $ilLog->warning('SOAP clone call failed. Calling clone method manually');
284  require_once('./webservice/soap/include/inc.soap_functions.php');
285  if (method_exists('ilSoapFunctions', $method)) {
286  $res = ilSoapFunctions::$method($new_session_id . '::' . $client_id, $this->dcl->getRefId(), $this->table_id, $format, $filepath);
287  } else {
288  throw new ilDclException("SOAP call " . $method . " does not exists!");
289  }
290  }
291 
292  return $res;
293  }
$_COOKIE['client_id']
Definition: server.php:9
$format
Definition: metadata.php:141
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
static _duplicate($a_session_id)
Duplicate session.
Class ilDclException.
$client_id
+ 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 126 of file class.ilDclContentExporter.php.

References $row, and ilDclTable\getFields().

Referenced by export().

127  {
128  $col = 0;
129 
130  foreach ($table->getFields() as $field) {
131  if ($field->getExportable()) {
132  $field->fillHeaderExcel($worksheet, $row, $col);
133  }
134  }
135  }
getFields()
Returns all fields of this table including the standard fields.
+ Here is the call graph for this function:
+ 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 145 of file class.ilDclContentExporter.php.

Referenced by export().

146  {
147  }
+ 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 108 of file class.ilDclContentExporter.php.

References $row, ilDclBaseRecordModel\fillRecordFieldExcelExport(), and ilDclTable\getFields().

Referenced by export().

109  {
110  $col = 0;
111  foreach ($table->getFields() as $field) {
112  if ($field->getExportable()) {
113  $record->fillRecordFieldExcelExport($worksheet, $row, $col, $field->getId());
114  }
115  }
116  }
getFields()
Returns all fields of this table including the standard fields.
fillRecordFieldExcelExport(ilExcel $worksheet, &$row, &$col, $field_id)
+ 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 94 of file class.ilDclContentExporter.php.

References $format, and ilExport\_getExportDirectory().

Referenced by export().

95  {
96  return ilExport::_getExportDirectory($this->dcl->getId(), $format, 'dcl') . '/';
97  }
$format
Definition: metadata.php:141
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
+ 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 81 of file class.ilDclContentExporter.php.

References $filename, and array.

Referenced by export().

82  {
83  $dangerous_filename_characters = array(" ", '"', "'", "&", "/", "\\", "?", "#", "`");
84  return str_replace($dangerous_filename_characters, "_", iconv("utf-8", "ascii//TRANSLIT", $filename));
85  }
Create styles array
The data for the language used.
+ 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().

◆ $table_id

ilDclContentExporter::$table_id
protected

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

Referenced by __construct(), and exportAsync().

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

◆ SOAP_FUNCTION_NAME

const ilDclContentExporter::SOAP_FUNCTION_NAME = 'exportDataCollectionContent'

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


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