ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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.

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

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  }
$DIC
Definition: xapitoken.php:46
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 148 of file class.ilDclContentExporter.php.

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

Referenced by ilDclRecordListTableGUI\exportData().

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) {
172  case self::EXPORT_EXCEL:
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  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
exit
Definition: login.php:29
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.
$format
Definition: metadata.php:218
sanitizeFilename($filename)
Sanitize the given filename The ilUtil::_sanitizeFilemame() does not clean enough.
$filename
Definition: buildRTE.php:89
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 246 of file class.ilDclContentExporter.php.

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

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  }
foreach($_POST as $key=> $value) $res
$format
Definition: metadata.php:218
static _duplicate($a_session_id)
Duplicate session.
$DIC
Definition: xapitoken.php:46
Class ilDclException.
$client_id
$_COOKIE[session_name()]
Definition: xapitoken.php:39
+ 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.

References ilDclTable\getFields().

Referenced by export().

116  {
117  $col = 0;
118 
119  foreach ($table->getFields() as $field) {
120  if ($field->getExportable()) {
121  $field->fillHeaderExcel($worksheet, $row, $col);
122  }
123  }
124  }
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 134 of file class.ilDclContentExporter.php.

Referenced by export().

135  {
136  }
+ 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.

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

Referenced by export().

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

References $format, and ilExport\_getExportDirectory().

Referenced by export().

84  {
85  return ilExport::_getExportDirectory($this->dcl->getId(), $format, 'dcl') . '/';
86  }
$format
Definition: metadata.php:218
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 68 of file class.ilDclContentExporter.php.

References $filename.

Referenced by export().

69  {
70  $dangerous_filename_characters = array(" ", '"', "'", "&", "/", "\\", "?", "#", "`");
71 
72  return str_replace($dangerous_filename_characters, "_", iconv("utf-8", "ascii//TRANSLIT", $filename));
73  }
$filename
Definition: buildRTE.php:89
+ 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().

◆ $table_id

ilDclContentExporter::$table_id
protected

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

Referenced by __construct(), and exportAsync().

◆ EXPORT_EXCEL

const ilDclContentExporter::EXPORT_EXCEL = 'xlsx'

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


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