ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilExportTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
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  public function numericOrdering(string $a_field): bool
65  {
66  if ($a_field === 'size') {
67  return true;
68  }
69  return false;
70  }
71 
72  protected function prepareOutput(): void
73  {
74  // append at last position (after custom columns)
75  $this->addColumn($this->lng->txt('actions'));
76  }
77 
78  protected function initMultiCommands(): void
79  {
80  $this->addMultiCommand('confirmDeletion', $this->lng->txt('delete'));
81  }
82 
83  public function addCustomColumn(string $a_txt, object $a_obj, string $a_func): void
84  {
85  $this->addColumn($a_txt);
86  $this->custom_columns[] = array('txt' => $a_txt,
87  'obj' => $a_obj,
88  'func' => $a_func
89  );
90  }
91 
92  public function addCustomMultiCommand(string $a_txt, string $a_cmd)
93  {
94  $this->addMultiCommand($a_cmd, $a_txt);
95  }
96 
97  public function getCustomColumns(): array
98  {
99  return $this->custom_columns;
100  }
101 
102  public function getExportFiles(): array
103  {
104  $types = array();
105  foreach ($this->parent_obj->getFormats() as $f) {
106  $types[] = $f['key'];
107  $this->formats[$f['key']] = $f['txt'];
108  }
110  $this->obj->getId(),
111  $types,
112  $this->obj->getType()
113  );
114  }
115 
116  protected function fillRow(array $a_set): void
117  {
118  foreach ($this->getCustomColumns() as $c) {
119  $this->tpl->setCurrentBlock('custom');
120  $f = $c['func'];
121  $this->tpl->setVariable('VAL_CUSTOM', $c['obj']->$f($a_set['type'], $a_set['file']) . ' ');
122  $this->tpl->parseCurrentBlock();
123  }
124 
125  $file_id = $this->getRowId($a_set);
126  $this->tpl->setVariable('VAL_ID', $file_id);
127 
128  $type = (isset($this->formats[$a_set['type']]) && $this->formats[$a_set['type']] != "")
129  ? $this->formats[$a_set['type']]
130  : $a_set['type'];
131  $this->tpl->setVariable('VAL_TYPE', $type);
132  $this->tpl->setVariable('VAL_FILE', $a_set['file']);
133  $this->tpl->setVariable('VAL_SIZE', ilUtil::formatSize($a_set['size']));
134  $this->tpl->setVariable(
135  'VAL_DATE',
136  ilDatePresentation::formatDate(new ilDateTime($a_set['timestamp'], IL_CAL_UNIX))
137  );
138 
139  $this->tpl->setVariable('TXT_DOWNLOAD', $this->lng->txt('download'));
140 
141  $this->ctrl->setParameter($this->getParentObject(), "file", $file_id);
142  $url = $this->ctrl->getLinkTarget($this->getParentObject(), "download");
143  $this->ctrl->setParameter($this->getParentObject(), "file", "");
144  $this->tpl->setVariable('URL_DOWNLOAD', $url);
145  }
146 
147  protected function getRowId(array $row): string
148  {
149  return $row['type'] . ':' . $row['file'];
150  }
151 }
setData(array $a_data)
setFormAction(string $a_form_action, bool $a_multipart=false)
numericOrdering(string $a_field)
$url
Definition: shib_logout.php:68
const IL_CAL_UNIX
$c
Definition: deliver.php:25
addCustomMultiCommand(string $a_txt, string $a_cmd)
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="")
global $DIC
Definition: shib_login.php:26
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.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
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)
addMultiCommand(string $a_cmd, string $a_text)
setEnableHeader(bool $a_enableheader)