ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilExportSelectionTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 use ILIAS\Export\ExportHandler\I\FactoryInterface as ilExportHandlerFactoryInterface;
24 
30 {
31  protected array $post_data;
32 
35  protected ilTree $tree;
36  protected ilExportHandlerFactoryInterface $export_handler;
37 
38  public function __construct(
39  object $a_parent_class,
40  string $a_parent_cmd,
41  ilExportHandlerFactoryInterface $export_handler
42  ) {
43  global $DIC;
44 
45  $this->post_data = ($DIC->http()->request()->getParsedBody() ?? []);
46 
47  $this->tree = $DIC->repositoryTree();
48  $this->objDefinition = $DIC['objDefinition'];
49  $this->access = $DIC->access();
50 
51  parent::__construct($a_parent_class, $a_parent_cmd);
52  $this->export_handler = $export_handler;
53 
54  $this->lng->loadLanguageModule('export');
55  $this->setTitle($this->lng->txt('export_select_resources'));
56  $this->addColumn($this->lng->txt('title'), '');
57  $this->addColumn($this->lng->txt('export_last_export'), '');
58  $this->addColumn($this->lng->txt('export_last_export_file'), '');
59  $this->addColumn($this->lng->txt('export_create_new_file'), '');
60  $this->addColumn($this->lng->txt('export_omit_resource'), '');
61 
62  $this->setEnableHeader(true);
63  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
64  $this->setRowTemplate("tpl.export_item_selection_row.html", "components/ILIAS/Export");
65  $this->setEnableTitle(true);
66  $this->setEnableNumInfo(true);
67  $this->setLimit(10000);
68 
69  $this->setFormName('cmd');
70 
71  $this->addCommandButton('saveItemSelection', $this->lng->txt('export_save_selection'));
72  $this->addCommandButton($a_parent_cmd, $this->lng->txt('cancel'));
73  }
74 
75  protected function fillRow(array $a_set): void
76  {
77  $a_set['copy'] = $a_set['copy'] ?? false;
78  $a_set['perm_copy'] = $a_set['perm_copy'] ?? false;
79  $a_set['link'] = $a_set['link'] ?? false;
80  $a_set['perm_export'] = $a_set['perm_export'] ?? false;
81 
82  // set selected radio button
83  $selected = '';
84  if ((!$a_set['copy'] or !$a_set['perm_copy']) and (!$a_set['link'])) {
85  $selected = "OMIT";
86  }
87  if ($a_set['perm_export'] and $a_set['last_export']) {
88  $selected = "EXPORT_E";
89  }
90  if (isset($this->post_data["cp_options"])) {
91  if (isset($a_set['ref_id']) && isset($this->post_data["cp_options"][$a_set['ref_id']]["type"])) {
92  switch ($this->post_data["cp_options"][$a_set['ref_id']]["type"]) {
93  case "2":
94  $selected = "EXPORT";
95  break;
96  case "1":
97  $selected = "EXPORT_E";
98  break;
99  }
100  }
101  }
102 
103  if ($a_set['last']) {
104  $this->tpl->setCurrentBlock('footer_export_e');
105  $this->tpl->setVariable('TXT_EXPORT_E_ALL', $this->lng->txt('select_all'));
106  $this->tpl->parseCurrentBlock();
107  $this->tpl->setCurrentBlock('footer_export');
108  $this->tpl->setVariable('TXT_EXPORT_ALL', $this->lng->txt('select_all'));
109  $this->tpl->parseCurrentBlock();
110  $this->tpl->setCurrentBlock('footer_omit');
111  $this->tpl->setVariable('TXT_OMIT_ALL', $this->lng->txt('select_all'));
112  $this->tpl->parseCurrentBlock();
113  return;
114  }
115 
116  for ($i = 0; $i < $a_set['depth']; $i++) {
117  $this->tpl->touchBlock('padding');
118  $this->tpl->touchBlock('end_padding');
119  }
120  $this->tpl->setVariable(
121  'TREE_IMG',
122  ilObject::_getIcon(ilObject::_lookupObjId((int) $a_set['ref_id']), "tiny", $a_set['type'])
123  );
124  $this->tpl->setVariable('TREE_ALT_IMG', $this->lng->txt('obj_' . $a_set['type']));
125  $this->tpl->setVariable('TREE_TITLE', $a_set['title']);
126 
127  if ($a_set['last_export']) {
128  $this->tpl->setVariable(
129  'VAL_LAST_EXPORT',
130  ilDatePresentation::formatDate(new ilDateTime($a_set['last_export'], IL_CAL_UNIX))
131  );
132  } else {
133  $this->tpl->setVariable('VAL_LAST_EXPORT', $this->lng->txt('no_file'));
134  }
135 
136  if ($a_set['source']) {
137  return;
138  }
139 
140  // Export existing
141  if ($a_set['perm_export'] and $a_set['last_export']) {
142  $this->tpl->setCurrentBlock('radio_export_e');
143  $this->tpl->setVariable('TXT_EXPORT_E', $this->lng->txt('export_existing'));
144  $this->tpl->setVariable('NAME_EXPORT_E', 'cp_options[' . ($a_set['ref_id'] ?? 0) . '][type]');
145  $this->tpl->setVariable('VALUE_EXPORT_E', ilExportOptions::EXPORT_EXISTING);
146  $this->tpl->setVariable(
147  'ID_EXPORT_E',
148  $a_set['depth'] . '_' . $a_set['type'] . '_' . ($a_set['ref_id'] ?? 0) . '_export_e'
149  );
150  $this->tpl->setVariable('EXPORT_E_CHECKED', 'checked="checked"');
151  $this->tpl->parseCurrentBlock();
152  } elseif (!$a_set['perm_export']) {
153  $this->tpl->setCurrentBlock('missing_export_perm');
154  $this->tpl->setVariable('TXT_MISSING_EXPORT_PERM', $this->lng->txt('missing_perm'));
155  $this->tpl->parseCurrentBlock();
156  }
157 
158  // Create new
159  if ($a_set['perm_export'] and $a_set['export']) {
160  $this->tpl->setCurrentBlock('radio_export');
161  $this->tpl->setVariable('TXT_EXPORT', $this->lng->txt('export'));
162  $this->tpl->setVariable('NAME_EXPORT', 'cp_options[' . ($a_set['ref_id'] ?? 0) . '][type]');
163  $this->tpl->setVariable('VALUE_EXPORT', ilExportOptions::EXPORT_BUILD);
164  $this->tpl->setVariable(
165  'ID_EXPORT',
166  $a_set['depth'] . '_' . $a_set['type'] . '_' . ($a_set['ref_id'] ?? 0) . '_export'
167  );
168  if ($selected == "EXPORT") {
169  $this->tpl->setVariable('EXPORT_CHECKED', 'checked="checked"');
170  }
171  $this->tpl->parseCurrentBlock();
172  } elseif ($a_set['export']) {
173  $this->tpl->setCurrentBlock('missing_export_perm');
174  $this->tpl->setVariable('TXT_MISSING_EXPORT_PERM', $this->lng->txt('missing_perm'));
175  $this->tpl->parseCurrentBlock();
176  }
177 
178  // Omit
179  $this->tpl->setCurrentBlock('omit_radio');
180  $this->tpl->setVariable('TXT_OMIT', $this->lng->txt('omit'));
181  $this->tpl->setVariable('NAME_OMIT', 'cp_options[' . ($a_set['ref_id'] ?? 0) . '][type]');
182  $this->tpl->setVariable('VALUE_OMIT', ilExportOptions::EXPORT_OMIT);
183  $this->tpl->setVariable('ID_OMIT', $a_set['depth'] . '_' . $a_set['type'] . '_' . ($a_set['ref_id'] ?? 0) . '_omit');
184  if ($selected == "OMIT") {
185  $this->tpl->setVariable($selected . '_CHECKED', 'checked="checked"');
186  }
187  $this->tpl->parseCurrentBlock();
188  }
189 
190  public function parseContainer(int $a_source): void
191  {
192  $first = true;
193  $rows = [];
194  foreach ($this->tree->getSubTree($root = $this->tree->getNodeData($a_source)) as $node) {
195  if ($node['type'] == 'rolf') {
196  continue;
197  }
198  if (!$this->objDefinition->allowExport($node['type'])) {
199  #continue;
200  }
201  if ($node['type'] == "file" &&
202  ilObjFileAccess::_isFileHidden($node['title'])) {
203  continue;
204  }
205  $r = array();
206 
207  $reference_id = new ReferenceId((int) $node['ref_id']);
208  $keys = $this->export_handler->repository()->key()->collection()->withElement(
209  $this->export_handler->repository()->key()->handler()->withObjectId($reference_id->toObjectId())
210  );
211  $elements = $this->export_handler->repository()->handler()->getElements($keys);
212  if ($elements->count() > 0) {
213  $r['last_export'] = $elements->newest()->getValues()->getCreationDate()->getTimestamp();
214  } else {
215  $r['last_export'] = 0;
216  }
217 
218  $r['last'] = false;
219  $r['source'] = $first;
220  $r['ref_id'] = $node['child'];
221  $r['depth'] = $node['depth'] - $root['depth'];
222  $r['type'] = $node['type'];
223  $r['title'] = $node['title'];
224  $r['export'] = $this->objDefinition->allowExport($node['type']);
225  $r['perm_export'] = $this->access->checkAccess('write', '', (int) $node['child']);
226 
227  $rows[] = $r;
228 
229  $first = false;
230  }
231 
232  $rows[] = array('last' => true);
233  $this->setData($rows);
234  }
235 }
setData(array $a_data)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
setFormAction(string $a_form_action, bool $a_multipart=false)
setEnableTitle(bool $a_enabletitle)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
__construct(object $a_parent_class, string $a_parent_cmd, ilExportHandlerFactoryInterface $export_handler)
static _isFileHidden(string $a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
const IL_CAL_UNIX
setFormName(string $a_name="")
static _lookupObjId(int $ref_id)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
global $DIC
Definition: shib_login.php:22
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
ilExportHandlerFactoryInterface $export_handler
setEnableNumInfo(bool $a_val)
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
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)
setEnableHeader(bool $a_enableheader)
$r