19declare(strict_types=1);
57 protected \ILIAS\ResourceStorage\Services
$irss;
67 $this->
ctrl = $DIC->ctrl();
68 $this->
toolbar = $DIC->toolbar();
69 $this->
lng = $DIC->language();
70 $this->
tabs = $DIC->tabs();
71 $this->
http = $DIC->http();
73 $this->irss =
$DIC->resourceStorage();
74 $this->
access = $DIC->access();
75 $this->tpl =
$DIC->ui()->mainTemplate();
76 $this->ui_factory =
$DIC->ui()->factory();
77 $this->
renderer = $DIC->ui()->renderer();
82 $this->obj_id = $a_parent_obj->
getObject()->getId();
83 $this->parent_obj = $a_parent_obj;
86 $this->
ctrl->setParameterByClass(ilDclRecordEditGUI::class, self::GET_TABLE_ID, $this->table_id);
87 $this->
ctrl->setParameterByClass(ilDclRecordEditGUI::class, self::GET_TABLEVIEW_ID, $this->tableview_id);
88 $this->
ctrl->setParameterByClass(ilDclDetailedViewGUI::class, self::GET_TABLE_ID, $this->table_id);
89 $this->
ctrl->setParameterByClass(ilDclDetailedViewGUI::class, self::GET_TABLEVIEW_ID, $this->tableview_id);
93 if ($this->
http->wrapper()->query()->has(self::GET_MODE)) {
94 $mode = $this->
http->wrapper()->query()->retrieve(self::GET_MODE, $this->
refinery->kindlyTo()->string());
95 if (in_array(
$mode, self::$available_modes,
true)) {
103 return $this->parent_obj->getRefId();
108 return $this->parent_obj->getObject()->getId();
117 if (!ilObjDataCollectionAccess::hasAccessTo($this->
getRefId(), $this->table_id, $this->tableview_id)) {
118 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'permission_denied'),
true);
122 $this->
ctrl->saveParameter($this, self::GET_MODE);
123 $cmd = $this->
ctrl->getCmd(self::CMD_SHOW);
135 $this->confirmDeleteRecords();
138 $this->deleteRecords();
141 $this->
tabs->setBackTarget($this->
lng->txt(
'back'), $this->ctrl->getLinkTarget($this));
157 $this->
ctrl->setParameter($this,
'table_id', $this->table_id);
158 $this->
ctrl->setParameter($this,
'tableview_id', $this->tableview_id);
161 $this->parent_obj->getRefId(),
163 ) && $this->table_obj->hasCustomFields();
164 if ($permission_to_add_or_import) {
165 $this->
ctrl->setParameterByClass(ilDclRecordEditGUI::class,
"record_id",
null);
167 $add_new = $this->ui_factory->button()->primary(
168 $this->
lng->txt(
"dcl_add_new_record"),
169 $this->ctrl->getFormActionByClass(ilDclRecordEditGUI::class,
"create")
171 $this->
toolbar->addStickyItem($add_new);
174 if ($permission_to_add_or_import && $this->table_obj->getImportEnabled()) {
175 $this->
ctrl->setParameterByClass(ilDclRecordEditGUI::class,
"record_id",
null);
177 $import_button = $this->ui_factory->button()->standard(
178 $this->
lng->txt(
"dcl_import_records .xls"),
179 $this->ctrl->getFormActionByClass(ilDclRecordListGUI::class, self::CMD_SHOW_IMPORT_EXCEL)
181 $this->
toolbar->addComponent($import_button);
184 if (count($this->table_obj->getRecordFields()) == 0) {
185 $message = $this->
lng->txt(
"dcl_no_fields_yet") .
" "
187 $this->parent_obj->getRefId(),
189 ) ? $this->
lng->txt(
"dcl_create_fields") :
"");
190 $this->tpl->setOnScreenMessage(
'info', $message,
true);
194 if ($this->
http->wrapper()->query()->has(
'table_id')) {
195 $target .= $this->
http->wrapper()->query()->retrieve(
'table_id', $this->
refinery->to()->string());
197 if ($this->
http->wrapper()->query()->has(
'tableview_id')) {
198 $target .=
'_' . $this->
http->wrapper()->query()->retrieve(
'tableview_id', $this->
refinery->to()->string());
201 $this->tpl->setPermanentLink(
"dcl", $this->parent_obj->getRefId(), $target);
203 if ($desc = $this->table_obj->getDescription()) {
204 $desc = $this->
refinery->string()->markdown()->toHTML()->transform($desc);
205 $desc =
'<div class="ilDclTableDescription">' . $desc .
'</div>';
207 $this->tpl->setContent($desc . $list->getHTML());
215 $this->tpl->setContent($form->getHTML());
226 $item->setHtml($this->
lng->txt(
'dcl_file_format_description'));
227 $item->setTitle(
"Info");
228 $form->addItem($item);
231 $file->setSuffixes([
'xlsx']);
232 $file->setRequired(
true);
233 $form->addItem($file);
236 $cb->setInfo($this->
lng->txt(
"dcl_simulate_info"));
239 $form->addCommandButton(
"importExcel", $this->
lng->txt(
"import"));
250 $this->parent_obj->getRefId(),
252 )) || !$this->table_obj->getImportEnabled()) {
256 if ($form->checkInput()) {
257 $file = $form->getInput(
"import_file");
258 $file_location = $file[
"tmp_name"];
259 $simulate = $form->getInput(
"simulate");
272 $result = $importer->import($file, $simulate);
274 $this->
endImport($result[
'line'], $result[
'warnings']);
281 public function endImport(
int $i, array $warnings): void
283 $output =
new ilTemplate(
"tpl.dcl_import_terminated.html",
true,
true,
"components/ILIAS/DataCollection");
284 $output->setVariable(
"IMPORT_TERMINATED", $this->
lng->txt(
"dcl_import_terminated") .
": " . $i);
285 foreach ($warnings as $warning) {
286 $output->setCurrentBlock(
"warnings");
287 $output->setVariable(
"WARNING", $warning);
288 $output->parseCurrentBlock();
291 $output->setVariable(
"BACK_LINK", $this->
ctrl->getLinkTargetByClass(ilDclRecordListGUI::class,
"listRecords"));
292 $output->setVariable(
"BACK", $this->
lng->txt(
"back"));
293 $this->tpl->setContent($output->get());
302 $table->initFilter();
303 $table->resetOffset();
304 $table->writeFilterToSession();
305 $this->filter_changed =
true;
315 $table->initFilter();
316 $table->resetOffset();
317 $table->resetFilter();
318 $this->filter_changed =
true;
327 $hasIlFileHash = $this->
http->wrapper()->query()->has(
'ilfilehash');
329 if ($this->
access->checkAccess(
'read',
"", $this->parent_obj->getRefId())) {
331 if ($hasIlFileHash) {
332 $filehash = $this->
http->wrapper()->query()->retrieve(
334 $this->
refinery->kindlyTo()->string()
336 $field_id = $this->
http->wrapper()->query()->retrieve(
'field_id', $this->
refinery->kindlyTo()->int());
339 $filepath = $_FILES[
"field_" . $field_id][
'tmp_name'];
340 $filetitle = $_FILES[
"field_" . $field_id][
'name'];
344 $rec_id = $this->
http->wrapper()
346 ->retrieve(
'record_id', $this->
refinery->kindlyTo()->int());
353 $field_id = $this->
http->wrapper()
355 ->retrieve(
'field_id', $this->
refinery->kindlyTo()->string());
360 $rid_string = $record->getRecordFieldValue($field_id);
361 $identification = $this->irss->manage()->find($rid_string);
362 if ($identification ===
null) {
365 $current_revision = $this->irss->manage()->getCurrentRevision($identification);
368 $this->irss->consume()
369 ->download($identification)
370 ->overrideFileName($current_revision->getTitle())
379 public function confirmDeleteRecords(): void
381 $this->
tabs->clearTargets();
384 $conf->setFormAction($this->
ctrl->getFormAction($this));
385 $conf->setHeaderText($this->
lng->txt(
'dcl_confirm_delete_records'));
387 $has_record_ids = $this->
http->wrapper()->post()->has(
'record_ids');
389 if ($has_record_ids) {
390 $record_ids = $this->
http->wrapper()->post()->retrieve(
392 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
395 $all_fields = $this->table_obj->getRecordFields();
396 foreach ($record_ids as $record_id) {
400 foreach ($all_fields as $field) {
404 if ($record_representation->getConfirmationHTML() !=
false) {
405 $record_data .= $field->getTitle() .
": " . $record_representation->getConfirmationHTML() .
"<br />";
408 $conf->addItem(
'record_ids[]', (
string) $record->getId(), $record_data);
410 $conf->addHiddenItem(
'table_id', (
string) $this->table_id);
411 $conf->setConfirm($this->
lng->txt(
'dcl_delete_records'), self::CMD_DELETE_RECORDS);
412 $conf->setCancel($this->
lng->txt(
'cancel'), self::CMD_CANCEL_DELETE);
413 $this->tpl->setContent($conf->getHTML());
419 public function deleteRecords(): void
421 $has_record_ids = $this->
http->wrapper()->post()->has(
'record_ids');
423 if ($has_record_ids) {
424 $record_ids = $this->
http->wrapper()->post()->retrieve(
426 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
432 foreach ($record_ids as $record_id) {
435 $ref_id = $this->parent_obj->getRefId();
437 if ($record->hasPermissionToDelete(
$ref_id)) {
444 $n_deleted = (count($record_ids) - $n_skipped);
447 $this->
lng->txt(
'dcl_deleted_records'),
450 $this->tpl->setOnScreenMessage(
'success', $message,
true);
454 $this->
lng->txt(
'dcl_skipped_delete_records'),
457 $this->tpl->setOnScreenMessage(
'info', $message,
true);
459 $this->
ctrl->redirect($this, self::CMD_LIST_RECORDS);
465 $obj_id = $this->parent_obj->object->getId();
466 $obj_id_rec = $table->getCollectionObject()->getId();
471 protected function setSubTabs(
string $active_mode = self::GET_MODE): void
473 $this->
ctrl->setParameter($this, self::GET_MODE, self::MODE_VIEW);
474 if ($this->
http->wrapper()->query()->has(self::GET_TABLEVIEW_ID)) {
475 $this->
ctrl->setParameter(
477 self::GET_TABLEVIEW_ID,
478 $this->
http->wrapper()->query()->retrieve(self::GET_TABLEVIEW_ID, $this->refinery->kindlyTo()->int())
481 $this->
tabs->addSubTab(
483 $this->
lng->txt(
'view'),
484 $this->ctrl->getLinkTarget($this, self::CMD_LIST_RECORDS)
487 $ref_id = $this->
http->wrapper()->query()->retrieve(
'ref_id', $this->
refinery->kindlyTo()->int());
488 if ($this->table_obj->hasPermissionToDeleteRecords(
$ref_id)) {
489 $this->
ctrl->setParameter($this, self::GET_MODE, self::MODE_MANAGE);
490 $this->
tabs->addSubTab(
492 $this->
lng->txt(
'dcl_manage'),
493 $this->ctrl->getLinkTarget($this, self::CMD_LIST_RECORDS)
496 $this->
tabs->activateSubTab($active_mode);
497 $this->
ctrl->clearParameters($this);
507 $list->setExternalSegmentation(
true);
508 $list->setExternalSorting(
true);
509 $list->determineOffsetAndOrder();
511 if ($this->filter_changed) {
512 $list->resetOffset();
515 $limit = $list->getLimit();
516 $offset = $list->getOffset();
520 $list->getOrderField(),
521 $list->getOrderDirection(),
526 $records =
$data[
'records'];
527 $total =
$data[
'total'];
529 $list->setMaxCount($total);
530 $list->setRecordData($records);
532 $list->determineOffsetAndOrder();
533 $list->determineLimit();
541 $tables = $this->parent_obj->object->getTables();
543 $tables = $this->parent_obj->object->getVisibleTables();
547 $switcher->addTableSwitcherToToolbar(
554 $switcher->addViewSwitcherToToolbar(
555 $this->table_obj->getVisibleTableViews(),
559 $this->getTableviewId()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
static getRecordCache(?int $record_id)
static getRecordFieldCache(object $record, object $field)
static getTableCache(?int $table_id=null)
static getRecordRepresentation(ilDclBaseRecordFieldModel $record_field)
Returns a record representation.
ilObjDataCollectionGUI $parent_obj
sendFile()
send File to User
const CMD_SHOW_IMPORT_EXCEL
static array $available_modes
ILIAS UI Factory $ui_factory
endImport(int $i, array $warnings)
End import.
const CMD_CONFIRM_DELETE_RECORDS
ILIAS HTTP Services $http
executeCommand()
execute command
importExcel()
Import Data from Excel sheet.
initImportForm()
Init form.
showImportExcel(?ilPropertyFormGUI $form=null)
__construct(ilObjDataCollectionGUI $a_parent_obj, int $table_id, int $tableview_id)
ILIAS UI Renderer $renderer
ILIAS Refinery Factory $refinery
recordBelongsToCollection(ilDclBaseRecordModel $record)
string $mode
Stores current mode active.
ILIAS ResourceStorage Services $irss
setSubTabs(string $active_mode=self::GET_MODE)
ilGlobalTemplateInterface $tpl
importRecords(string $file, bool $simulate=false)
Import records from Excel file.
getPartialRecords(string $ref_id, string $sort, string $direction, ?int $limit, int $offset, array $filter=[])
Return only the needed subset of record objects for the table, according to sorting,...
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
static hasAccessToFields(int $ref_id, int $table_id)
static hasWriteAccess(int $ref, ?int $user_id=0)
static hasPermissionToAddRecord(int $ref_id, int $table_id)
@ilCtrl_Calls ilObjDataCollectionGUI: ilInfoScreenGUI, ilNoteGUI, ilCommonActionDispatcherGUI @ilCtrl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
static http()
Fetches the global http state from ILIAS.