Skip to content

Commit

Permalink
Removid legacy pagination and button
Browse files Browse the repository at this point in the history
  • Loading branch information
iszmais committed Jun 20, 2024
1 parent 613f84e commit 81a0c0e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class ilDclDetailedViewGUI
protected ilDclTable $table;
protected int $tableview_id;
protected ilDclBaseRecordModel $record_obj;
protected int $next_record_id = 0;
protected int $prev_record_id = 0;
protected int $current_record_position = 0;
protected array $record_ids = [];
protected bool $is_enabled_paging = true;
protected ilLanguage $lng;
protected ilCtrlInterface $ctrl;
Expand Down Expand Up @@ -66,19 +62,23 @@ public function __construct(ilObjDataCollectionGUI $a_dcl_object, int $tableview
'record_id',
$this->refinery->kindlyTo()->int()
);
} elseif ($this->http->wrapper()->query()->has('record_pos')) {
$pos = $this->http->wrapper()->query()->retrieve('record_pos', $this->refinery->kindlyTo()->int());
$records = array_values(ilDclTableView::findOrGetInstance($tableview_id)->getTable()->getRecords());
$record = $records[$pos] ?? end($records);
$this->record_id = $record->getId();
}
if ($this->http->wrapper()->post()->has('record_id')) {
$this->record_id = $this->http->wrapper()->post()->retrieve(
'record_id',
$this->refinery->kindlyTo()->int()
);
}
$ref_id = $this->dcl_gui_object->getRefId();

if ($this->record_id) {
$this->record_obj = ilDclCache::getRecordCache($this->record_id);
$this->table = $this->record_obj->getTable();
if (!$this->record_obj->hasPermissionToView($ref_id)) {
if (!$this->record_obj->hasPermissionToView($this->dcl_gui_object->getRefId())) {
$this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_no_perm_view'), true);
$this->ctrl->redirectByClass(ilDclRecordListGUI::class, "show");
}
Expand Down Expand Up @@ -108,10 +108,6 @@ public function __construct(ilObjDataCollectionGUI $a_dcl_object, int $tableview
&& $this->http->wrapper()->query()->retrieve('disable_paging', $this->refinery->kindlyTo()->bool())) {
$this->is_enabled_paging = false;
}
// Find current, prev and next records for navigation
if ($this->is_enabled_paging) {
$this->determineNextPrevRecords();
}
$this->content_style_domain = $DIC->contentStyle()
->domain()
->styleForRefId(
Expand Down Expand Up @@ -154,6 +150,12 @@ protected function offerAlternativeViews(): void
$tpl->setContent($table_gui->getHTML());
}

public function jumpToRecord(): void
{
$this->ctrl->setParameterByClass(self::class, 'record_id', $this->record_id);
$this->ctrl->redirectByClass(self::class, 'renderRecord');
}

public function renderRecord(bool $editComments = false): void
{
global $DIC;
Expand Down Expand Up @@ -227,37 +229,31 @@ public function renderRecord(bool $editComments = false): void

// Buttons for previous/next records

$tools = $DIC->ui()->factory()->viewControl();
if ($this->is_enabled_paging) {
$prevNextLinks = $this->renderPrevNextLinks();
$rctpl->setVariable('PREV_NEXT_RECORD_LINKS', $prevNextLinks);
$ilCtrl->clearParameters($this); // #14083
$rctpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this));
$rctpl->setVariable('RECORD', $this->lng->txt('dcl_record'));
$rctpl->setVariable(
'RECORD_FROM_TOTAL',
sprintf(
$this->lng->txt('dcl_record_from_total'),
$this->current_record_position,
count($this->record_ids)
)
$records = $this->table->getRecords();
$DIC->toolbar()->addComponent(
$DIC->ui()->factory()->viewControl()->pagination()
->withTargetURL($this->ctrl->getLinkTargetByClass(self::class, 'jumpToRecord'), 'record_pos')
->withPageSize(1)
->withDropdownAt(2)
->withDropdownLabel($this->lng->txt('entry_of'))
->withCurrentPage(array_search($this->record_id, array_keys($records)))
->withTotalEntries(count($records))
->withMaxPaginationButtons(20)
);
$rctpl->setVariable('TABLEVIEW_ID', $this->tableview_id);
$rctpl->setVariable('SELECT_OPTIONS', $this->renderSelectOptions());
}

// Edit Button
$ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());

if ($this->record_obj->hasPermissionToEdit($ref_id)) {
$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(
if ($this->record_obj->hasPermissionToEdit($this->dcl_gui_object->getRefId())) {
$DIC->toolbar()->addSpacer('100%');
$this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'table_id', $this->table->getId());
$this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'tableview_id', $this->tableview_id);
$this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'redirect', ilDclRecordEditGUI::REDIRECT_DETAIL);
$this->ctrl->saveParameterByClass(ilDclRecordEditGUI::class, 'record_id');
$DIC->toolbar()->addComponent($DIC->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));
$this->ctrl->getLinkTargetByClass(ilDclRecordEditGUI::class, 'edit')
));
}

// Comments
Expand Down Expand Up @@ -320,71 +316,6 @@ protected function renderComments(bool $edit = false): string
}
}

/**
* Find the previous/next record from the current position. Also determine position of current record in whole set.
*/
protected function determineNextPrevRecords(): void
{
if (!ilSession::has("dcl_record_ids") || ilSession::get('dcl_record_ids') != $this->table->getId()) {
$this->loadSession();
}

if (ilSession::has("dcl_record_ids") && count(ilSession::get("dcl_record_ids"))) {
$this->record_ids = ilSession::get("dcl_record_ids");
foreach ($this->record_ids as $k => $recId) {
if ($recId == $this->record_id) {
if ($k != 0) {
$this->prev_record_id = $this->record_ids[$k - 1];
}
if (($k + 1) < count($this->record_ids)) {
$this->next_record_id = $this->record_ids[$k + 1];
}
$this->current_record_position = $k + 1;
break;
}
}
}
}

/**
* Determine and return the markup for the previous/next records
*/
protected function renderPrevNextLinks(): string
{
global $DIC;
$ilCtrl = $DIC['ilCtrl'];
$ilCtrl->setParameter($this, 'tableview_id', $this->tableview_id);
$prevStr = $this->lng->txt('dcl_prev_record');
$nextStr = $this->lng->txt('dcl_next_record');
$ilCtrl->setParameter($this, 'record_id', $this->prev_record_id);
$url = $ilCtrl->getLinkTarget($this, 'renderRecord');
$out = ($this->prev_record_id) ? "<a href='$url'>$prevStr</a>" : "<span class='light'>$prevStr</span>";
$out .= " | ";
$ilCtrl->setParameter($this, 'record_id', $this->next_record_id);
$url = $ilCtrl->getLinkTarget($this, 'renderRecord');
$out .= ($this->next_record_id) ? "<a href='$url'>$nextStr</a>" : "<span class='light'>$nextStr</span>";

return $out;
}

/**
* Render select options
*/
protected function renderSelectOptions(): string
{
$out = '';
foreach ($this->record_ids as $k => $recId) {
$selected = ($recId == $this->record_id) ? " selected" : "";
$out .= "<option value='$recId'$selected>" . ($k + 1) . "</option>";
}

return $out;
}

/**
* setOptions
* string $link_name
*/
private function setOptions(string $link_name): array
{
$options = [];
Expand Down Expand Up @@ -417,13 +348,9 @@ private function loadSession(): void
);
}

/**
* @return bool
*/
protected function checkAccess(): bool
{
$ref_id = $this->dcl_gui_object->getRefId();
$has_accass = ilObjDataCollectionAccess::hasAccessTo($ref_id, $this->table->getId(), $this->tableview_id);
$has_accass = ilObjDataCollectionAccess::hasAccessTo($this->dcl_gui_object->getRefId(), $this->table->getId(), $this->tableview_id);
$is_active = ilDclDetailedViewDefinition::isActive($this->tableview_id);
return $has_accass && $is_active;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
<div class="ilDclRecordViewNavWrapper ilClearFloat">
<!-- BEGIN paging -->
<div class="ilDclRecordViewNav">
<span class="ilDclRecordViewRecordOfTotal light">({RECORD_FROM_TOTAL})</span>
{PREV_NEXT_RECORD_LINKS}
<label for="dcl_select_record" class="ilDclSelectRecord">{RECORD}</label>
<form action="{FORM_ACTION}" method="POST" name="dcl_change_record" class="ilDclChangeRecord">
<input type="hidden" name="cmd[renderRecord]" value="1">
<input type="hidden" name="tableview_id" value="{TABLEVIEW_ID}">
<select name="record_id" id="dcl_select_record" onchange="document.dcl_change_record.submit()">
{SELECT_OPTIONS}
</select>
</form>
</div>
<!-- END paging -->
<!-- BEGIN edit_record -->
<div class="ilDclEditRecordButtonWrapper">{EDIT_RECORD_BUTTON}</div>
<!-- END edit_record -->
</div>
<div class="ilc_page_cont_PageContainer">
<div class="ilc_page_Page">{CONTENT}</div>
</div>
<div class="ilDclPermanentLinkWrapper">{PERMA_LINK}</div>
{COMMENTS}
{COMMENTS}
3 changes: 2 additions & 1 deletion lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -8824,6 +8824,7 @@ dcl#:#dcl_wrong_input_type#:#Der eingegebene Text passt nicht zum Typ dieses Fel
dcl#:#dcl_wrong_length#:#Der eingegebene Text ist zu lang.
dcl#:#dcl_wrong_regex#:#Der eingegebene Text passt nicht zur Spezifikation dieses Feldes (regulärer Ausdruck).
dcl#:#dlc_xls_async_export#:#Asynchroner XLSX-Export
dcl#:#entry_of#:#Eintrag %1$d von %2$d
dcl#:#fieldtitle_allow_chars#:#Nicht Erlaubte Zeichen: %s
dcl#:#fileupload_not_migrated#:#Die Datei wurde noch nicht migriert und kann deshalb nicht angezeigt werden. Bitte wenden Sie sich an Ihre Systemadministration.
didactic#:#activate_exclusive_template#:#Standard ausgrauen
Expand Down Expand Up @@ -17692,4 +17693,4 @@ wsp#:#wsp_type_ltiv#:#Zertifikat: LTI-Konsument
wsp#:#wsp_type_scov#:#Zertifikat: SCORM
wsp#:#wsp_type_tstv#:#Zertifikat: Test
wsp#:#wsp_type_webr#:#Weblink
wsp#:#wsp_type_wfld#:#Ordner
wsp#:#wsp_type_wfld#:#Ordner
3 changes: 2 additions & 1 deletion lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -8818,6 +8818,7 @@ dcl#:#dcl_wrong_input_type#:#The value you entered does not match the specificat
dcl#:#dcl_wrong_length#:#The text you entered is to long.
dcl#:#dcl_wrong_regex#:#The text you entered does not match the specification for this field (Regular Expression).
dcl#:#dlc_xls_async_export#:#Asynchronous XLSX-Export
dcl#:#entry_of#:#Entry %1$d of %2$d
dcl#:#fieldtitle_allow_chars#:#Not allowed chars: %s
dcl#:#fileupload_not_migrated#:#File has not yet been migration and cannot be displayed. Please contact your System-Administrator.
didactic#:#activate_exclusive_template#:#Grey Out Default
Expand Down Expand Up @@ -17692,4 +17693,4 @@ wsp#:#wsp_type_ltiv#:#Certificate: LTI Consumer
wsp#:#wsp_type_scov#:#Certificate: SCORM
wsp#:#wsp_type_tstv#:#Certificate: Test
wsp#:#wsp_type_webr#:#Weblink
wsp#:#wsp_type_wfld#:#Folder
wsp#:#wsp_type_wfld#:#Folder

0 comments on commit 81a0c0e

Please sign in to comment.