Skip to content

Commit

Permalink
DC, LUI Project replace legacy buttons and advanced selection lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Amstutz committed Aug 18, 2023
1 parent 72d1b80 commit 335e461
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 223 deletions.
63 changes: 29 additions & 34 deletions Modules/DataCollection/classes/Content/class.ilDclRecordListGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class ilDclRecordListGUI

private ilAccessHandler $access;
private ilGlobalTemplateInterface $tpl;
protected \ILIAS\UI\Factory $ui_factory;
protected \ILIAS\UI\Renderer $renderer;

/**
* Stores current mode active
Expand All @@ -47,7 +49,7 @@ class ilDclRecordListGUI
protected static array $available_modes = [self::MODE_VIEW, self::MODE_MANAGE];

protected ilCtrl $ctrl;
protected ilToolbarGUI $ilToolbar;
protected ilToolbarGUI $toolbar;
protected ilLanguage $lng;
protected ilTabsGUI $tabs;
protected ILIAS\HTTP\Services $http;
Expand All @@ -62,14 +64,16 @@ public function __construct(ilObjDataCollectionGUI $a_parent_obj, int $table_id,
global $DIC;

$this->ctrl = $DIC->ctrl();
$this->ilToolbar = $DIC->toolbar();
$this->toolbar = $DIC->toolbar();
$this->lng = $DIC->language();
$this->tabs = $DIC->tabs();
$this->http = $DIC->http();
$this->refinery = $DIC->refinery();
$this->irss = $DIC->resourceStorage();
$this->access = $DIC->access();
$this->tpl = $DIC->ui()->mainTemplate();
$this->ui_factory = $DIC->ui()->factory();
$this->renderer = $DIC->ui()->renderer();

$this->table_id = $table_id;
$this->tableview_id = $tableview_id;
Expand Down Expand Up @@ -147,11 +151,6 @@ public function executeCommand(): void

public function listRecords(bool $use_tableview_filter = false): void
{
global $DIC;
$ilToolbar = $DIC['ilToolbar'];
/**
* @var $ilToolbar ilToolbarGUI
*/
$list = $this->getRecordListTableGUI($use_tableview_filter);

$this->createSwitchers();
Expand All @@ -161,22 +160,23 @@ public function listRecords(bool $use_tableview_filter = false): void
$this->table_id
) && $this->table_obj->hasCustomFields();
if ($permission_to_add_or_import) {
$this->ctrl->setParameterByClass("ildclrecordeditgui", "record_id", null);
$this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "record_id", null);

$add_new = ilLinkButton::getInstance();
$add_new->setPrimary(true);
$add_new->setCaption("dcl_add_new_record");
$add_new->setUrl($this->ctrl->getFormActionByClass("ildclrecordeditgui", "create"));
$ilToolbar->addStickyItem($add_new);
$add_new = $this->ui_factory->button()->primary(
$this->lng->txt("dcl_add_new_record"),
$this->ctrl->getFormActionByClass(ilDclRecordEditGUI::class, "create")
);
$this->toolbar->addStickyItem($add_new);
}

if ($permission_to_add_or_import && $this->table_obj->getImportEnabled()) {
$this->ctrl->setParameterByClass("ildclrecordeditgui", "record_id", null);
$this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "record_id", null);

$import = ilLinkButton::getInstance();
$import->setCaption("dcl_import_records .xls");
$import->setUrl($this->ctrl->getFormActionByClass("ildclrecordlistgui", self::CMD_SHOW_IMPORT_EXCEL));
$ilToolbar->addButtonInstance($import);
$import_button = $this->ui_factory->button()->standard(
$this->lng->txt("dcl_import_records .xls"),
$this->ctrl->getFormActionByClass(ilDclRecordListGUI::class, self::CMD_SHOW_IMPORT_EXCEL)
);
$this->toolbar->addComponent($import_button);
}

if (count($this->table_obj->getRecordFields()) == 0) {
Expand Down Expand Up @@ -285,7 +285,7 @@ public function endImport(int $i, array $warnings): void
$output->setVariable("WARNING", $this->lng->txt("dcl_no_warnings"));
$output->parseCurrentBlock();
}
$output->setVariable("BACK_LINK", $this->ctrl->getLinkTargetByClass("ilDclRecordListGUI", "listRecords"));
$output->setVariable("BACK_LINK", $this->ctrl->getLinkTargetByClass(ilDclRecordListGUI::class, "listRecords"));
$output->setVariable("BACK", $this->lng->txt("back"));
$this->tpl->setContent($output->get());
}
Expand All @@ -311,7 +311,7 @@ public function doTableSwitch(): void
public function doTableViewSwitch(): void
{
$tableview_id = $this->http->wrapper()->post()->retrieve('tableview_id', $this->refinery->kindlyTo()->int());
$this->ctrl->setParameterByClass("ilObjDataCollectionGUI", "tableview_id", $tableview_id);
$this->ctrl->setParameterByClass(ilObjDataCollectionGUI::class, "tableview_id", $tableview_id);
$this->ctrl->redirect($this, self::CMD_SHOW);
}

Expand Down Expand Up @@ -585,8 +585,7 @@ protected function getRecordListTableGUI(bool $use_tableview_filter): ilDclRecor

protected function createSwitchers(): void
{
$ilToolbar = $this->ilToolbar;
$ilToolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclRecordListGUI", "doTableSwitch"));
$this->toolbar->setFormAction($this->ctrl->getFormActionByClass(ilDclRecordListGUI::class, "doTableSwitch"));

//table switcher
$options = $this->getAvailableTables();
Expand All @@ -595,13 +594,13 @@ protected function createSwitchers(): void
$table_selection->setOptions($options);
$table_selection->setValue($this->table_id);

$ilToolbar->addText($this->lng->txt("dcl_table"));
$ilToolbar->addInputItem($table_selection);
$this->toolbar->addText($this->lng->txt("dcl_table"));
$this->toolbar->addInputItem($table_selection);
$button = ilSubmitButton::getInstance();
$button->setCaption('change');
$button->setCommand('doTableSwitch');
$ilToolbar->addButtonInstance($button);
$ilToolbar->addSeparator();
$this->toolbar->addButtonInstance($button);
$this->toolbar->addSeparator();
}

//tableview switcher
Expand All @@ -614,14 +613,10 @@ protected function createSwitchers(): void
$tableview_selection = new ilSelectInputGUI('', 'tableview_id');
$tableview_selection->setOptions($options);
$tableview_selection->setValue($this->tableview_id);
$ilToolbar->addText($this->lng->txt("dcl_tableview"));
$ilToolbar->addInputItem($tableview_selection);

$button = ilSubmitButton::getInstance();
$button->setCaption('change');
$button->setCommand('doTableViewSwitch');
$ilToolbar->addButtonInstance($button);
$ilToolbar->addSeparator();
$this->toolbar->addText($this->lng->txt("dcl_tableview"));
$this->toolbar->addInputItem($tableview_selection);
$this->toolbar->addFormButton('change', 'doTableViewSwitch');
$this->toolbar->addSeparator();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,25 @@ public function executeCommand(): string
public function showPage(): string
{
if ($this->getOutputMode() == ilPageObjectGUI::EDIT) {
$delete_button = ilLinkButton::getInstance();
$delete_button->setCaption('dcl_empty_detailed_view');
$delete_button->setUrl($this->ctrl->getLinkTarget($this, 'confirmDelete'));
$this->toolbar->addButtonInstance($delete_button);
$delete_button = $this->ui->factory()->button()->standard(
$this->lng->txt('dcl_empty_detailed_view'),
$this->ctrl->getLinkTarget($this, 'confirmDelete')
);
$this->toolbar->addComponent($delete_button);

$activation_button = ilLinkButton::getInstance();
if ($this->getPageObject()->getActive()) {
$activation_button->setCaption('dcl_deactivate_view');
$activation_button->setUrl($this->ctrl->getLinkTarget($this, 'deactivate'));
$activation_button = $this->ui->factory()->button()->standard(
$this->lng->txt('dcl_deactivate_view'),
$this->ctrl->getLinkTarget($this, 'deactivate')
);
} else {
$activation_button->setCaption('dcl_activate_view');
$activation_button->setUrl($this->ctrl->getLinkTarget($this, 'activate'));
$activation_button = $this->ui->factory()->button()->standard(
$this->lng->txt('dcl_activate_view'),
$this->ctrl->getLinkTarget($this, 'activate')
);
}

$this->toolbar->addButtonInstance($activation_button);
$this->toolbar->addComponent($activation_button);

$legend = $this->getPageObject()->getAvailablePlaceholders();
if (sizeof($legend)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
class ilDclDetailedViewGUI
{
protected \ILIAS\UI\Factory $ui_factory;
protected \ILIAS\UI\Renderer $renderer;
protected ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
protected ilObjDataCollectionGUI $dcl_gui_object;
protected ilNoteGUI $notes_gui;
Expand Down Expand Up @@ -54,6 +56,8 @@ public function __construct(ilObjDataCollectionGUI $a_dcl_object, int $tableview
$this->http = $DIC->http();
$this->refinery = $DIC->refinery();
$this->main_tpl = $DIC->ui()->mainTemplate();
$this->ui_factory = $DIC->ui()->factory();
$this->renderer = $DIC->ui()->renderer();

$this->record_id = null;
if ($this->http->wrapper()->query()->has('record_id')) {
Expand Down Expand Up @@ -94,8 +98,8 @@ public function __construct(ilObjDataCollectionGUI $a_dcl_object, int $tableview
$this->notesGUI = new ilNoteGUI($repId, $objId);
$this->notesGUI->enablePublicNotes();
$this->notesGUI->enablePublicNotesDeletion();
$this->ctrl->setParameterByClass("ilnotegui", "record_id", $this->record_id);
$this->ctrl->setParameterByClass("ilnotegui", "rep_id", $repId);
$this->ctrl->setParameterByClass(ilNoteGUI::class, "record_id", $this->record_id);
$this->ctrl->setParameterByClass(ilNoteGUI::class, "rep_id", $repId);

$this->tableview_id = $tableview_id;

Expand Down Expand Up @@ -245,14 +249,15 @@ public function renderRecord(bool $editComments = false): void
$ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());

if ($this->record_obj->hasPermissionToEdit($ref_id)) {
$button = ilLinkButton::getInstance();
$ilCtrl->setParameterByClass('ildclrecordeditgui', 'table_id', $this->table->getId());
$ilCtrl->setParameterByClass('ildclrecordeditgui', 'tableview_id', $this->tableview_id);
$ilCtrl->setParameterByClass('ildclrecordeditgui', 'redirect', ilDclRecordEditGUI::REDIRECT_DETAIL);
$ilCtrl->saveParameterByClass('ildclrecordeditgui', 'record_id');
$button->setUrl($ilCtrl->getLinkTargetByClass('ildclrecordeditgui', 'edit'));
$button->setCaption($this->lng->txt('dcl_edit_record'), false);
$rctpl->setVariable('EDIT_RECORD_BUTTON', $button->render());
$ilCtrl->setParameterByClass(ilDclRecordEditGUI::class, 'table_id', $this->table->getId());
$ilCtrl->setParameterByClass(ilDclRecordEditGUI::class, 'tableview_id', $this->tableview_id);
$ilCtrl->setParameterByClass(ilDclRecordEditGUI::class, 'redirect', ilDclRecordEditGUI::REDIRECT_DETAIL);
$ilCtrl->saveParameterByClass(ilDclRecordEditGUI::class, 'record_id');
$edit_button = $this->ui_factory->button()->standard(
$this->lng->txt('dcl_edit_record'),
$ilCtrl->getLinkTargetByClass(ilDclRecordEditGUI::class, 'edit')
);
$rctpl->setVariable('EDIT_RECORD_BUTTON', $this->renderer->render($edit_button));
}

// Comments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ public function getRecordQuerySortObject(
string $direction = "asc",
bool $sort_by_status = false
): ilDclRecordQueryObject {
global $DIC;
$ilDB = $DIC['ilDB'];

$join_str
= "LEFT JOIN il_dcl_record_field AS sort_record_field_{$this->getId()} ON (sort_record_field_{$this->getId()}.record_id = record.id AND sort_record_field_{$this->getId()}.field_id = "
. $ilDB->quote($this->getId(), 'integer') . ") ";
. $this->db->quote($this->getId(), 'integer') . ") ";
$join_str .= "LEFT JOIN il_dcl_stloc{$this->getStorageLocation()}_value AS sort_stloc_{$this->getId()} ON (sort_stloc_{$this->getId()}.record_field_id = sort_record_field_{$this->getId()}.id) ";
$join_str .= "LEFT JOIN object_reference AS sort_object_reference_{$this->getId()} ON (sort_object_reference_{$this->getId()}.ref_id = sort_stloc_{$this->getId()}.value AND sort_object_reference_{$this->getId()}.deleted IS NULL)";
$join_str .= "LEFT JOIN object_data AS sort_object_data_{$this->getId()} ON (sort_object_data_{$this->getId()}.obj_id = sort_object_reference_{$this->getId()}.obj_id)";
Expand All @@ -41,7 +38,7 @@ public function getRecordQuerySortObject(
global $DIC;
$ilUser = $DIC['ilUser'];
$join_str .= "LEFT JOIN ut_lp_marks AS ut ON (ut.obj_id = sort_object_data_{$this->getId()}.obj_id AND ut.usr_id = "
. $ilDB->quote($ilUser->getId(), 'integer') . ") ";
. $this->db->quote($ilUser->getId(), 'integer') . ") ";
}

$select_str = (!$sort_by_status) ? " sort_object_data_{$this->getId()}.title AS field_{$this->getId()}," : " ut.status AS field_{$this->getId()}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,28 @@ public function getSingleHTML(array $options = null, bool $link = true): string

public function getLinkHTML(string $title, bool $show_action_menu = false): string
{
$lng = $this->lng;
$link = ilLink::_getStaticLink($this->getRecordField()->getValue());
if ($show_action_menu) {
$field = $this->getRecordField()->getField();
$record = $this->getRecordField()->getRecord();

$list = new ilAdvancedSelectionListGUI();
$list->setId('adv_list_copy_link_' . $field->getId() . $record->getId());
$list->setListTitle($title);
$dropdown_items = [];
if ($field->getProperty(ilDclBaseFieldModel::PROP_ILIAS_REFERENCE_LINK)) {
$list->addItem($lng->txt('view'), 'view', $link);
$dropdown_items[] = $this->factory->link()->standard(
$this->lng->txt('view'),
$link
);
}
$list->addItem($lng->txt('copy'), 'copy', $this->getActionLink('copy'));
$list->addItem($lng->txt('link'), 'link', $this->getActionLink('link'));

return $list->getHTML();
$dropdown_items[] = $this->factory->link()->standard(
$this->lng->txt('link'),
$this->getActionLink('link')
);
$dropdown_items[] = $this->factory->link()->standard(
$this->lng->txt('copy'),
$this->getActionLink('copy')
);
$dropdown = $this->factory->dropdown()->standard($dropdown_items)->withLabel($title);
return $this->renderer->render($dropdown);
} else {
return "<a href=\"$link\">$title</a>";
return $this->renderer->render($this->factory->link()->standard($title, $link));
}
}

Expand All @@ -84,18 +88,15 @@ public function getLinkHTML(string $title, bool $show_action_menu = false): stri
*/
protected function getActionLink(string $mode): string
{
global $DIC;
$ilCtrl = $DIC['ilCtrl'];

switch ($mode) {
case 'copy':
$ilCtrl->setParameterByClass('ilobjectcopygui', 'item_ref_id', $this->getRecordField()->getValue());
$ilCtrl->setParameterByClass('ilobjrootfoldergui', 'item_ref_id', $this->getRecordField()->getValue());
$ilCtrl->setParameterByClass('ilobjectcopygui', 'source_id', $this->getRecordField()->getValue());
$this->ctrl->setParameterByClass(ilObjectCopyGUI::class, 'item_ref_id', $this->getRecordField()->getValue());
$this->ctrl->setParameterByClass(ilObjRootFolderGUI::class, 'item_ref_id', $this->getRecordField()->getValue());
$this->ctrl->setParameterByClass(ilObjectCopyGUI::class, 'source_id', $this->getRecordField()->getValue());

return $ilCtrl->getLinkTargetByClass('ilobjectcopygui', 'initTargetSelection');
return $this->ctrl->getLinkTargetByClass(ilObjectCopyGUI::class, 'initTargetSelection');
case 'link':
return $ilCtrl->getLinkTargetByClass(['ilrepositorygui', 'ilobjrootfoldergui'], 'link');
return $this->ctrl->getLinkTargetByClass([ilRepositoryGUI::class, ilObjRootFolderGUI::class], 'link');
default:
return '';
}
Expand Down
24 changes: 14 additions & 10 deletions Modules/DataCollection/classes/Fields/class.ilDclFieldListGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

class ilDclFieldListGUI
{
protected \ILIAS\UI\Factory $ui_factory;
protected \ILIAS\UI\Renderer $renderer;
protected ilCtrl $ctrl;
protected ilLanguage $lng;
protected ilToolbarGUI $toolbar;
Expand Down Expand Up @@ -50,17 +52,19 @@ public function __construct(ilDclTableListGUI $a_parent_obj)
$this->tpl = $DIC->ui()->mainTemplate();
$this->tabs = $DIC->tabs();
$this->toolbar = $DIC->toolbar();
$this->ui_factory = $DIC->ui()->factory();
$this->renderer = $DIC->ui()->renderer();

$this->ctrl->saveParameterByClass('ilDclTableEditGUI', 'table_id');
$this->ctrl->saveParameterByClass(ilDclTableEditGUI::class, 'table_id');
$locator->addItem(
ilDclCache::getTableCache($this->table_id)->getTitle(),
$this->ctrl->getLinkTargetByClass('ilDclTableEditGUI', 'edit')
$this->ctrl->getLinkTargetByClass(ilDclTableEditGUI::class, 'edit')
);
$this->tpl->setLocator();

if (!$this->checkAccess()) {
$this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
$this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
$this->ctrl->redirectByClass(ilDclRecordListGUI::class, 'listRecords');
}
}

Expand Down Expand Up @@ -177,10 +181,10 @@ public function save(): void
public function listFields(): void
{
//add button
$add_new = ilLinkButton::getInstance();
$add_new->setPrimary(true);
$add_new->setCaption("dcl_add_new_field");
$add_new->setUrl($this->ctrl->getLinkTargetByClass('ildclfieldeditgui', 'create'));
$add_new = $this->ui_factory->button()->primary(
$this->lng->txt("dcl_add_new_field"),
$this->ctrl->getLinkTargetByClass(ilDclFieldEditGUI::class, 'create')
);
$this->toolbar->addStickyItem($add_new);

$this->toolbar->addSeparator();
Expand All @@ -196,7 +200,7 @@ public function listFields(): void
$table_selection->setOptions($options);
$table_selection->setValue($this->table_id);

$this->toolbar->setFormAction($this->ctrl->getFormActionByClass("ilDclFieldListGUI", "doTableSwitch"));
$this->toolbar->setFormAction($this->ctrl->getFormActionByClass(ilDclFieldListGUI::class, "doTableSwitch"));
$this->toolbar->addText($this->lng->txt("dcl_select"));
$this->toolbar->addInputItem($table_selection);
$this->toolbar->addFormButton($this->lng->txt('change'), 'doTableSwitch');
Expand All @@ -212,8 +216,8 @@ public function listFields(): void
public function doTableSwitch(): void
{
$table_id = $this->http->wrapper()->post()->retrieve('table_id', $this->refinery->kindlyTo()->int());
$this->ctrl->setParameterByClass("ilObjDataCollectionGUI", "table_id", $table_id);
$this->ctrl->redirectByClass("ilDclFieldListGUI", "listFields");
$this->ctrl->setParameterByClass(ilObjDataCollectionGUI::class, "table_id", $table_id);
$this->ctrl->redirectByClass(ilDclFieldListGUI::class, "listFields");
}

protected function checkAccess(): bool
Expand Down
Loading

0 comments on commit 335e461

Please sign in to comment.