ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilExportTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 {
27  protected ilObject $obj;
28  protected array $custom_columns = array();
29  protected array $formats = array();
30 
34  public function __construct(object $a_parent_obj, string $a_parent_cmd, ilObject $a_exp_obj)
35  {
36  global $DIC;
37 
38  $this->obj = $a_exp_obj;
39 
40  parent::__construct($a_parent_obj, $a_parent_cmd);
41  $this->setData($this->getExportFiles());
42  $this->setTitle($this->lng->txt('exp_export_files'));
43 
44  $this->initColumns();
45 
46  $this->setDefaultOrderField('timestamp');
47  $this->setDefaultOrderDirection('desc');
48 
49  $this->setEnableHeader(true);
50  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
51  $this->setRowTemplate('tpl.export_table_row.html', 'Services/Export');
52  $this->initMultiCommands();
53  }
54 
55  protected function initColumns(): void
56  {
57  $this->addColumn($this->lng->txt(''), '', '1', true);
58  $this->addColumn($this->lng->txt('type'), 'type');
59  $this->addColumn($this->lng->txt('file'), 'file');
60  $this->addColumn($this->lng->txt('size'), 'size');
61  $this->addColumn($this->lng->txt('date'), 'timestamp');
62  }
63 
64  protected function prepareOutput(): void
65  {
66  // append at last position (after custom columns)
67  $this->addColumn($this->lng->txt('actions'));
68  }
69 
73  protected function initMultiCommands(): void
74  {
75  $this->addMultiCommand('confirmDeletion', $this->lng->txt('delete'));
76  }
77 
78  public function addCustomColumn(string $a_txt, object $a_obj, string $a_func): void
79  {
80  $this->addColumn($a_txt);
81  $this->custom_columns[] = array('txt' => $a_txt,
82  'obj' => $a_obj,
83  'func' => $a_func
84  );
85  }
86 
87  public function addCustomMultiCommand(string $a_txt, string $a_cmd)
88  {
89  $this->addMultiCommand($a_cmd, $a_txt);
90  }
91 
92  public function getCustomColumns(): array
93  {
94  return $this->custom_columns;
95  }
96 
97  public function getExportFiles(): array
98  {
99  $types = array();
100  foreach ($this->parent_obj->getFormats() as $f) {
101  $types[] = $f['key'];
102  $this->formats[$f['key']] = $f['txt'];
103  }
105  $this->obj->getId(),
106  $types,
107  $this->obj->getType()
108  );
109  }
110 
111  protected function fillRow(array $a_set): void
112  {
113  foreach ($this->getCustomColumns() as $c) {
114  $this->tpl->setCurrentBlock('custom');
115  $f = $c['func'];
116  $this->tpl->setVariable('VAL_CUSTOM', $c['obj']->$f($a_set['type'], $a_set['file']) . ' ');
117  $this->tpl->parseCurrentBlock();
118  }
119 
120  $file_id = $this->getRowId($a_set);
121  $this->tpl->setVariable('VAL_ID', $file_id);
122 
123  $type = (isset($this->formats[$a_set['type']]) && $this->formats[$a_set['type']] != "")
124  ? $this->formats[$a_set['type']]
125  : $a_set['type'];
126  $this->tpl->setVariable('VAL_TYPE', $type);
127  $this->tpl->setVariable('VAL_FILE', $a_set['file']);
128  $this->tpl->setVariable('VAL_SIZE', ilUtil::formatSize($a_set['size']));
129  $this->tpl->setVariable(
130  'VAL_DATE',
131  ilDatePresentation::formatDate(new ilDateTime($a_set['timestamp'], IL_CAL_UNIX))
132  );
133 
134  $this->tpl->setVariable('TXT_DOWNLOAD', $this->lng->txt('download'));
135 
136  $this->ctrl->setParameter($this->getParentObject(), "file", $file_id);
137  $url = $this->ctrl->getLinkTarget($this->getParentObject(), "download");
138  $this->ctrl->setParameter($this->getParentObject(), "file", "");
139  $this->tpl->setVariable('URL_DOWNLOAD', $url);
140  }
141 
142  protected function getRowId(array $row): string
143  {
144  return $row['type'] . ':' . $row['file'];
145  }
146 }
setData(array $a_data)
$c
Definition: cli.php:38
setFormAction(string $a_form_action, bool $a_multipart=false)
$type
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
addCustomMultiCommand(string $a_txt, string $a_cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
setDefaultOrderField(string $a_defaultorderfield)
static formatSize(int $size, string $a_mode='short', ?ilLanguage $a_lng=null)
Returns the specified file size value in a human friendly form.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
static _getExportFiles(int $a_obj_id, $a_export_types="", string $a_obj_type="")
setDefaultOrderDirection(string $a_defaultorderdirection)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addCustomColumn(string $a_txt, object $a_obj, string $a_func)
__construct(Container $dic, ilPlugin $plugin)
__construct(object $a_parent_obj, string $a_parent_cmd, ilObject $a_exp_obj)
Constructor.
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
$url
addMultiCommand(string $a_cmd, string $a_text)
setEnableHeader(bool $a_enableheader)