Skip to content

Commit

Permalink
Add sorting and pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
gvollbach committed Sep 19, 2023
1 parent c269853 commit b1ae8ec
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Modules/Forum/classes/class.ilForumProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class ilForumProperties
public const VIEW_DATE_DESC = 3;
public const FILE_UPLOAD_GLOBALLY_ALLOWED = 0;
public const FILE_UPLOAD_INDIVIDUAL = 1;
public const PAGE_SIZE_THREAD_OVERVIEW = 10;
public const PAGE_NAME_THREAD_OVERVIEW = 'page';

/** @var array<int, ilForumProperties> */
private static array $instances = [];

Expand Down
51 changes: 37 additions & 14 deletions Modules/Forum/classes/class.ilObjForumGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,29 @@ private function retrieveThrPk(): int
}

/**
* @return Sortation
* @return array
*/
protected function getSortation() : Sortation
protected function getSortationViewControl() : array
{
$sortation = $this->factory->input()->viewControl()->sortation([
$view_controls = [];
$view_controls[] = $this->factory->viewControl()->sortation([
/*
$this->lng->txt('forums_thread_sorting_asc') => new Order('sort_thread', 'ASC'),
$this->lng->txt('forums_thread_sorting_dsc') => new Order('sort_thread', 'DESC'),
$this->lng->txt('forums_last_posting_asc') => new Order('sort_posting', 'ASC'),
$this->lng->txt('forums_last_posting_dsc') => new Order('sort_posting', 'DESC'),
$this->lng->txt('forums_rating_asc') => new Order('sort_rating', 'ASC'),
$this->lng->txt('forums_rating_dsc') => new Order('sort_rating', 'DESC'),
*/
$this->lng->txt('forums_thread_sorting_asc') => 'thread_sorting_asc',
$this->lng->txt('forums_thread_sorting_dsc') => 'thread_sorting_dsc',
$this->lng->txt('forums_last_posting_asc') => 'last_posting_asc',
$this->lng->txt('forums_last_posting_dsc') => 'last_posting_dsc',
$this->lng->txt('forums_rating_asc') => 'rating_asc',
$this->lng->txt('forums_rating_dsc') => 'rating_dsc',

]);
return $sortation;
return $view_controls;
}

/**
Expand Down Expand Up @@ -897,7 +906,7 @@ public function getContent(): string
);
$data_objects = $tbl->setMapper($frm)->fetchDataAnReturnObject();

$thread_buffer = [];
$thread_buffer = [];

if(is_array($data_objects) && count($data_objects) > 0) {
foreach($data_objects as $thread) {
Expand All @@ -906,8 +915,11 @@ public function getContent(): string
$current_thread = $thread['thread'];

$ref_id = $this->object->getRefId();

$link = $this->getLinkActionForThread($current_thread->getId(), $current_thread->getSubject(), 'viewThread');
$subject = $current_thread->getSubject();
if($current_thread->isClosed()) {
$subject .= ' (' . $this->lng->txt('forums_closed') . ')';
}
$link = $this->getLinkActionForThread($current_thread->getId(), $subject, 'viewThread');
$actions = $this->getActionsForThreadOverview($ref_id, $current_thread);
$list_item = $this->factory->item()->standard($link)
->withActions($actions)
Expand All @@ -920,15 +932,26 @@ public function getContent(): string
}
}

$std_list = $this->factory->panel()->listing()->standard($this->object->getTitle(), [
$this->factory->item()->group("", $thread_buffer)
]);
$url = $this->http->request()->getRequestTarget();
$current_page = 0;
if($this->http->wrapper()->query()->has(ilForumProperties::PAGE_NAME_THREAD_OVERVIEW)) {
$current_page = $this->http->wrapper()->query()->retrieve(ilForumProperties::PAGE_NAME_THREAD_OVERVIEW, $this->refinery->kindlyTo()->int());
}

$frm_object = $frm->getOneTopic();
$view_control = $this->getSortationViewControl();
$view_control[] = $this->factory->viewControl()->pagination()
->withTargetURL($url, ilForumProperties::PAGE_NAME_THREAD_OVERVIEW)
->withTotalEntries($frm_object->getTopNumThreads())
->withPageSize(ilForumProperties::PAGE_SIZE_THREAD_OVERVIEW)
->withCurrentPage($current_page);

$sortation = $this->getSortation();
$vc_container = $this->factory->input()->container()->viewControl()->standard([$sortation])
->withRequest($this->http->request());
$vc_container = $this->factory->panel()->standard(
$this->object->getTitle(),
$thread_buffer)
->withViewControls($view_control);

$default_html = $this->renderer->render($vc_container) . $this->renderer->render($std_list);
$default_html = $this->renderer->render($vc_container);
$modals = $this->renderer->render($this->modal_collection);
$this->tpl->setContent($default_html . $modals);
return '';
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -4077,6 +4077,7 @@ common#:#forums_last_posting_asc#:#Last Posting aufsteigend
common#:#forums_last_posting_dsc#:#Last Posting absteigend
common#:#forums_rating_asc#:#Rating aufsteigend
common#:#forums_rating_dsc#:#Rating absteigend
common#:#forums_closed#:#geschlossen
common#:#forums_use_alias#:#Sie können hier ein Pseudonym eingeben, das Sie für diesen Beitrag verwenden möchten. Wenn Sie dieses Feld leer lassen, wird Ihr Beitrag als von "%s" geschrieben markiert.
common#:#forums_your_name#:#Ihr Name
common#:#frm#:#Forum
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -4075,6 +4075,7 @@ common#:#forums_last_posting_asc#:#Last Posting Ascending
common#:#forums_last_posting_dsc#:#Last Posting Descending
common#:#forums_rating_asc#:#Rating Ascending
common#:#forums_rating_dsc#:#Rating Descending
common#:#forums_closed#:#closed
common#:#forums_use_alias#:#You may use a pseudonym for your posting. If you leave this field blank, your posting will be marked as written by ‘%s’.
common#:#forums_your_name#:#Your Name
common#:#frm#:#Forum
Expand Down

0 comments on commit b1ae8ec

Please sign in to comment.