ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDclExportTableGUI.php
Go to the documentation of this file.
1 <?php
2 
20 declare(strict_types=1);
21 
23 {
24  public function __construct(ilDclExportGUI $a_parent_obj, string $a_parent_cmd, ilObject $a_exp_obj)
25  {
26  parent::__construct($a_parent_obj, $a_parent_cmd, $a_exp_obj);
27 
28  $this->addCustomColumn($this->lng->txt('status'), $this, 'parseExportStatus');
29  }
30 
31  public function getExportFiles(): array
32  {
33  $types = [];
34  foreach ($this->parent_obj->getFormats() as $f) {
35  $types[] = $f['key'];
36  $this->formats[$f['key']] = $f['txt'];
37  }
38 
39  $file = [];
40  foreach ($types as $type) {
41  $dir = ilExport::_getExportDirectory($this->obj->getId(), $type, 'dcl');
42 
43  // quit if import dir not available
44  if (!is_dir($dir) || !is_writeable($dir)) {
45  continue;
46  }
47 
48  // open directory
49  $h_dir = dir($dir);
50 
51  // get files and save the in the array
52  while ($entry = $h_dir->read()) {
53  if ($entry != "." && $entry != "..") {
54  $ts = substr($entry, 0, strpos($entry, "__"));
55 
56  $filename = $entry; //($this->isExportInProgress($entry))? substr($entry, 0, - strlen(self::PROGRESS_IDENTIFIER)) : $entry;
57 
58  $file[$entry . $type] = [
59  "type" => $type,
60  "file" => $filename,
61  "size" => ($this->isExportInProgress($entry)) ? '0' : filesize($dir . "/" . $entry),
62  "timestamp" => $ts,
63  ];
64  }
65  }
66 
67  // close import directory
68  $h_dir->close();
69  }
70 
71  // sort files
72  ksort($file);
73 
74  return $file;
75  }
76 
77  protected function fillRow(array $a_set): void
78  {
79  foreach ($this->getCustomColumns() as $c) {
80  $this->tpl->setCurrentBlock('custom');
81  $this->tpl->setVariable('VAL_CUSTOM', $c['obj']->{$c['func']}($a_set['type'], $a_set['file']) . ' ');
82  $this->tpl->parseCurrentBlock();
83  }
84 
85  $file_id = $this->getRowId($a_set);
86  $this->tpl->setVariable('VAL_ID', $file_id);
87 
88  $type = ($this->formats[$a_set['type']] != "")
89  ? $this->formats[$a_set['type']]
90  : $a_set['type'];
91  $this->tpl->setVariable('VAL_TYPE', $type);
92 
93  $filename = ($this->isExportInProgress($a_set['file'])) ? substr(
94  $a_set['file'],
95  0,
97  ) . ".xlsx" : $a_set['file'];
98  $this->tpl->setVariable('VAL_FILE', $filename);
99 
100  $this->tpl->setVariable('VAL_SIZE', ilUtil::formatSize((int) $a_set['size']));
101  $this->tpl->setVariable(
102  'VAL_DATE',
103  ilDatePresentation::formatDate(new ilDateTime($a_set['timestamp'], IL_CAL_UNIX))
104  );
105 
106  if (!$this->isExportInProgress($a_set['file'])) {
107  $this->tpl->setVariable('TXT_DOWNLOAD', $this->lng->txt('download'));
108 
109  $this->ctrl->setParameter($this->getParentObject(), "file", $file_id);
110  $url = $this->ctrl->getLinkTarget($this->getParentObject(), "download");
111  $this->ctrl->setParameter($this->getParentObject(), "file", "");
112  $this->tpl->setVariable('URL_DOWNLOAD', $url);
113  }
114  }
115 
116  public function parseExportStatus(string $type, string $file): string
117  {
118  if ($type == 'xlsx') {
119  if ($this->isExportInProgress($file)) {
120  return $this->lng->txt('dcl_export_started');
121  } else {
122  return $this->lng->txt('dcl_export_finished');
123  }
124  } else {
125  return $this->lng->txt('dcl_export_finished');
126  }
127  }
128 
129  protected function isExportInProgress(string $file): bool
130  {
131  $ending = substr($file, -strlen(ilDclContentExporter::IN_PROGRESS_POSTFIX));
132 
133  return ($ending == ilDclContentExporter::IN_PROGRESS_POSTFIX);
134  }
135 }
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilDclExportGUI $a_parent_obj, string $a_parent_cmd, ilObject $a_exp_obj)
__construct(VocabulariesInterface $vocabularies)
static formatSize(int $size, string $a_mode='short', ?ilLanguage $a_lng=null)
Returns the specified file size value in a human friendly form.
$url
Definition: ltiregstart.php:35
$filename
Definition: buildRTE.php:78
addCustomColumn(string $a_txt, object $a_obj, string $a_func)
parseExportStatus(string $type, string $file)