ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 18 of file class.ilDclContentExporter.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

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

50  {
51  global $DIC;
52  $lng = $DIC['lng'];
53 
54  $this->ref_id = $ref_id;
55  $this->table_id = $table_id;
56  $this->filter = $filter;
57 
58  $this->dcl = new ilObjDataCollection($ref_id);
59  $this->tables = ($table_id) ? array($this->dcl->getTableById($table_id)) : $this->dcl->getTables();
60 
61  $lng->loadLanguageModule('dcl');
62  $this->lng = $lng;
63  }
global $DIC
Definition: saml.php:7
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 154 of file class.ilDclContentExporter.php.

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

Referenced by ilDclRecordListTableGUI\exportData().

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

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

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

References $row, and ilDclTable\getFields().

Referenced by export().

122  {
123  $col = 0;
124 
125  foreach ($table->getFields() as $field) {
126  if ($field->getExportable()) {
127  $field->fillHeaderExcel($worksheet, $row, $col);
128  }
129  }
130  }
getFields()
Returns all fields of this table including the standard fields.
$row
+ 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 140 of file class.ilDclContentExporter.php.

Referenced by export().

141  {
142  }
+ 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 103 of file class.ilDclContentExporter.php.

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

Referenced by export().

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

References $format, and ilExport\_getExportDirectory().

Referenced by export().

90  {
91  return ilExport::_getExportDirectory($this->dcl->getId(), $format, 'dcl') . '/';
92  }
$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 74 of file class.ilDclContentExporter.php.

References $filename.

Referenced by export().

75  {
76  $dangerous_filename_characters = array(" ", '"', "'", "&", "/", "\\", "?", "#", "`");
77 
78  return str_replace($dangerous_filename_characters, "_", iconv("utf-8", "ascii//TRANSLIT", $filename));
79  }
$filename
Definition: buildRTE.php:89
+ Here is the caller graph for this function:

Field Documentation

◆ $dcl

ilDclContentExporter::$dcl
protected

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

◆ $filter

ilDclContentExporter::$filter
protected

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

Referenced by __construct().

◆ $lng

ilDclContentExporter::$lng
protected

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

Referenced by __construct().

◆ $ref_id

ilDclContentExporter::$ref_id
protected

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

Referenced by __construct().

◆ $table

ilDclContentExporter::$table
protected

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

Referenced by export().

◆ $table_id

ilDclContentExporter::$table_id
protected

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

Referenced by __construct(), and exportAsync().

◆ EXPORT_EXCEL

const ilDclContentExporter::EXPORT_EXCEL = 'xlsx'

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


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