19 declare(strict_types=1);
43 protected string $mode = self::MODE_VIEW;
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_TABLEVIEW_ID, $this->tableview_id);
90 $this->mode = self::MODE_VIEW;
92 if ($this->
http->wrapper()->query()->has(self::GET_MODE)) {
93 $mode = $this->
http->wrapper()->query()->retrieve(self::GET_MODE, $this->
refinery->kindlyTo()->string());
94 if (in_array($mode, self::$available_modes,
true)) {
102 return $this->parent_obj->getRefId();
107 return $this->parent_obj->getObject()->getId();
117 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'permission_denied'),
true);
121 $this->
ctrl->saveParameter($this, self::GET_MODE);
122 $cmd = $this->
ctrl->getCmd(self::CMD_SHOW);
128 case self::CMD_CANCEL_DELETE:
129 case self::CMD_LIST_RECORDS:
133 case self::CMD_CONFIRM_DELETE_RECORDS:
134 $this->confirmDeleteRecords();
136 case self::CMD_DELETE_RECORDS:
137 $this->deleteRecords();
139 case self::CMD_SHOW_IMPORT_EXCEL:
140 $this->
tabs->setBackTarget($this->
lng->txt(
'back'), $this->
ctrl->getLinkTarget($this));
157 $this->parent_obj->getRefId(),
159 ) && $this->table_obj->hasCustomFields();
160 if ($permission_to_add_or_import) {
161 $this->
ctrl->setParameterByClass(ilDclRecordEditGUI::class,
"record_id",
null);
163 $add_new = $this->ui_factory->button()->primary(
164 $this->
lng->txt(
"dcl_add_new_record"),
165 $this->
ctrl->getFormActionByClass(ilDclRecordEditGUI::class,
"create")
167 $this->
toolbar->addStickyItem($add_new);
170 if ($permission_to_add_or_import && $this->table_obj->getImportEnabled()) {
171 $this->
ctrl->setParameterByClass(ilDclRecordEditGUI::class,
"record_id",
null);
173 $import_button = $this->ui_factory->button()->standard(
174 $this->
lng->txt(
"dcl_import_records .xls"),
175 $this->
ctrl->getFormActionByClass(ilDclRecordListGUI::class, self::CMD_SHOW_IMPORT_EXCEL)
177 $this->
toolbar->addComponent($import_button);
180 if (count($this->table_obj->getRecordFields()) == 0) {
181 $message = $this->
lng->txt(
"dcl_no_fields_yet") .
" " 183 $this->parent_obj->getRefId(),
185 ) ? $this->
lng->txt(
"dcl_create_fields") :
"");
186 $this->tpl->setOnScreenMessage(
'info',
$message,
true);
190 if ($this->
http->wrapper()->query()->has(
'table_id')) {
191 $target .= $this->
http->wrapper()->query()->retrieve(
'table_id', $this->
refinery->to()->string());
193 if ($this->
http->wrapper()->query()->has(
'tableview_id')) {
194 $target .=
'_' . $this->
http->wrapper()->query()->retrieve(
'tableview_id', $this->
refinery->to()->string());
197 $this->tpl->setPermanentLink(
"dcl", $this->parent_obj->getRefId(), $target);
199 if ($desc = $this->table_obj->getDescription()) {
200 $desc = $this->
refinery->string()->markdown()->toHTML()->transform($desc);
201 $desc =
'<div class="ilDclTableDescription">' . $desc .
'</div>';
203 $this->tpl->setContent($desc . $list->getHTML());
211 $this->tpl->setContent($form->getHTML());
222 $item->setHtml($this->
lng->txt(
'dcl_file_format_description'));
223 $item->setTitle(
"Info");
224 $form->addItem($item);
228 $file->setRequired(
true);
229 $form->addItem($file);
232 $cb->setInfo($this->
lng->txt(
"dcl_simulate_info"));
235 $form->addCommandButton(
"importExcel", $this->
lng->txt(
"import"));
246 $this->parent_obj->getRefId(),
248 )) || !$this->table_obj->getImportEnabled()) {
252 if ($form->checkInput()) {
253 $file = $form->getInput(
"import_file");
254 $file_location = $file[
"tmp_name"];
255 $simulate = $form->getInput(
"simulate");
268 $result = $importer->
import($file, $simulate);
270 $this->
endImport($result[
'line'], $result[
'warnings']);
277 public function endImport(
int $i, array $warnings): void
279 $output =
new ilTemplate(
"tpl.dcl_import_terminated.html",
true,
true,
"components/ILIAS/DataCollection");
280 $output->setVariable(
"IMPORT_TERMINATED", $this->
lng->txt(
"dcl_import_terminated") .
": " . $i);
281 foreach ($warnings as $warning) {
282 $output->setCurrentBlock(
"warnings");
283 $output->setVariable(
"WARNING", $warning);
284 $output->parseCurrentBlock();
287 $output->setVariable(
"BACK_LINK", $this->
ctrl->getLinkTargetByClass(ilDclRecordListGUI::class,
"listRecords"));
288 $output->setVariable(
"BACK", $this->
lng->txt(
"back"));
289 $this->tpl->setContent($output->get());
298 $table->initFilter();
299 $table->resetOffset();
300 $table->writeFilterToSession();
301 $this->filter_changed =
true;
311 $table->initFilter();
312 $table->resetOffset();
313 $table->resetFilter();
314 $this->filter_changed =
true;
323 $hasIlFileHash = $this->
http->wrapper()->query()->has(
'ilfilehash');
325 if ($this->
access->checkAccess(
'read',
"", $this->parent_obj->getRefId())) {
327 if ($hasIlFileHash) {
328 $filehash = $this->
http->wrapper()->query()->retrieve(
330 $this->
refinery->kindlyTo()->string()
332 $field_id = $this->
http->wrapper()->query()->retrieve(
'field_id', $this->
refinery->kindlyTo()->int());
335 $filepath = $_FILES[
"field_" . $field_id][
'tmp_name'];
336 $filetitle = $_FILES[
"field_" . $field_id][
'name'];
340 $rec_id = $this->
http->wrapper()
342 ->retrieve(
'record_id', $this->
refinery->kindlyTo()->int());
349 $field_id = $this->
http->wrapper()
351 ->retrieve(
'field_id', $this->
refinery->kindlyTo()->string());
356 $rid_string = $record->getRecordFieldValue($field_id);
357 $identification = $this->irss->manage()->find($rid_string);
358 if ($identification ===
null) {
361 $current_revision = $this->irss->manage()->getCurrentRevision($identification);
364 $this->irss->consume()
365 ->download($identification)
366 ->overrideFileName($current_revision->getTitle())
375 public function confirmDeleteRecords():
void 377 $this->
tabs->clearTargets();
380 $conf->setFormAction($this->
ctrl->getFormAction($this));
381 $conf->setHeaderText($this->
lng->txt(
'dcl_confirm_delete_records'));
383 $has_record_ids = $this->
http->wrapper()->post()->has(
'record_ids');
385 if ($has_record_ids) {
386 $record_ids = $this->
http->wrapper()->post()->retrieve(
391 $all_fields = $this->table_obj->getRecordFields();
392 foreach ($record_ids as $record_id) {
396 foreach ($all_fields as $field) {
400 if ($record_representation->getConfirmationHTML() !=
false) {
401 $record_data .= $field->getTitle() .
": " . $record_representation->getConfirmationHTML() .
"<br />";
404 $conf->addItem(
'record_ids[]', (
string) $record->getId(), $record_data);
406 $conf->addHiddenItem(
'table_id', (
string) $this->table_id);
407 $conf->setConfirm($this->
lng->txt(
'dcl_delete_records'), self::CMD_DELETE_RECORDS);
408 $conf->setCancel($this->
lng->txt(
'cancel'), self::CMD_CANCEL_DELETE);
409 $this->tpl->setContent($conf->getHTML());
415 public function deleteRecords():
void 417 $has_record_ids = $this->
http->wrapper()->post()->has(
'record_ids');
419 if ($has_record_ids) {
420 $record_ids = $this->
http->wrapper()->post()->retrieve(
428 foreach ($record_ids as $record_id) {
431 $ref_id = $this->parent_obj->getRefId();
433 if ($record->hasPermissionToDelete(
$ref_id)) {
440 $n_deleted = (count($record_ids) - $n_skipped);
443 $this->
lng->txt(
'dcl_deleted_records'),
446 $this->tpl->setOnScreenMessage(
'success',
$message,
true);
450 $this->
lng->txt(
'dcl_skipped_delete_records'),
453 $this->tpl->setOnScreenMessage(
'info',
$message,
true);
455 $this->
ctrl->redirect($this, self::CMD_LIST_RECORDS);
461 $obj_id = $this->parent_obj->object->getId();
462 $obj_id_rec = $table->getCollectionObject()->getId();
464 return $obj_id == $obj_id_rec;
467 protected function setSubTabs(
string $active_mode = self::GET_MODE): void
469 $this->
ctrl->setParameter($this, self::GET_MODE, self::MODE_VIEW);
470 $this->
tabs->addSubTab(
472 $this->
lng->txt(
'view'),
473 $this->
ctrl->getLinkTarget($this, self::CMD_LIST_RECORDS)
476 $ref_id = $this->
http->wrapper()->query()->retrieve(
'ref_id', $this->
refinery->kindlyTo()->int());
477 if ($this->table_obj->hasPermissionToDeleteRecords(
$ref_id)) {
478 $this->
ctrl->setParameter($this, self::GET_MODE, self::MODE_MANAGE);
479 $this->
tabs->addSubTab(
481 $this->
lng->txt(
'dcl_manage'),
482 $this->
ctrl->getLinkTarget($this, self::CMD_LIST_RECORDS)
485 $this->
tabs->activateSubTab($active_mode);
486 $this->
ctrl->clearParameters($this);
496 $list->setExternalSegmentation(
true);
497 $list->setExternalSorting(
true);
498 $list->determineOffsetAndOrder();
500 if ($this->filter_changed) {
501 $list->resetOffset();
504 $limit = $list->getLimit();
505 $offset = $list->getOffset();
509 $list->getOrderField(),
510 $list->getOrderDirection(),
515 $records =
$data[
'records'];
516 $total =
$data[
'total'];
518 $list->setMaxCount($total);
519 $list->setRecordData($records);
521 $list->determineOffsetAndOrder();
522 $list->determineLimit();
530 $tables = $this->parent_obj->object->getTables();
532 $tables = $this->parent_obj->object->getVisibleTables();
536 $switcher->addTableSwitcherToToolbar(
542 $switcher->addViewSwitcherToToolbar(
543 $this->table_obj->getVisibleTableViews(),
552 if (
null === $this->table_id ||
null === $this->tableview_id) {
556 return ilObjDataCollectionAccess::hasAccessTo(
557 $this->parent_obj->getRefId(),
setSubTabs(string $active_mode=self::GET_MODE)
ilObjDataCollectionGUI $parent_obj
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS UI Renderer $renderer
static array $available_modes
ilGlobalTemplateInterface $tpl
recordBelongsToCollection(ilDclBaseRecordModel $record)
endImport(int $i, array $warnings)
End import.
import(string $file, bool $simulate=false)
const CMD_SHOW_IMPORT_EXCEL
executeCommand()
execute command
sendFile()
send File to User
showImportExcel(?ilPropertyFormGUI $form=null)
const CMD_CONFIRM_DELETE_RECORDS
__construct(ilObjDataCollectionGUI $a_parent_obj, int $table_id, int $tableview_id)
ILIAS HTTP Services $http
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static hasAccessToFields(int $ref_id, int $table_id)
ilObjDataCollectionGUI: ilInfoScreenGUI, ilNoteGUI, ilCommonActionDispatcherGUI ilObjDataCollectionG...
static http()
Fetches the global http state from ILIAS.
ILIAS Refinery Factory $refinery
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, paging and filters.
static getTableCache(?int $table_id=null)
static getRecordRepresentation(ilDclBaseRecordFieldModel $record_field)
Returns a record representation.
static hasWriteAccess(int $ref, ?int $user_id=0)
string $mode
Stores current mode active.
ILIAS UI Factory $ui_factory
ILIAS ResourceStorage Services $irss
static getRecordCache(?int $record_id)
static hasPermissionToAddRecord(int $ref_id, int $table_id)
static getRecordFieldCache(object $record, object $field)
importExcel()
Import Data from Excel sheet.
initImportForm()
Init form.
importRecords(string $file, bool $simulate=false)
Import records from Excel file.