Skip to content

Commit

Permalink
Add modal an ordering elements
Browse files Browse the repository at this point in the history
  • Loading branch information
gvollbach committed Sep 19, 2023
1 parent 0fa5054 commit c269853
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 47 deletions.
160 changes: 113 additions & 47 deletions Modules/Forum/classes/class.ilObjForumGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
use ILIAS\UI\Component\Dropdown\Standard;
use ILIAS\UI\Component\Item\Item;
use ILIAS\UI\Component\Symbol\Avatar\Avatar;
use ILIAS\UI\Component\Modal\Interruptive;
use ILIAS\UI\Component\Modal\RoundTrip;
use ILIAS\Data\Order;
use ILIAS\UI\Component\Input\ViewControl\Sortation;

/**
* Class ilObjForumGUI
Expand Down Expand Up @@ -80,6 +84,7 @@ class ilObjForumGUI extends ilObjectGUI implements ilDesktopItemHandling, ilForu
private ilForumThreadSettingsSessionStorage $selected_post_storage;
protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
protected \ILIAS\Style\Content\GUIService $content_style_gui;
private array $modal_collection = [];

public function __construct($data, int $id = 0, bool $call_by_reference = true, bool $prepare_output = true)
{
Expand Down Expand Up @@ -153,6 +158,23 @@ private function retrieveThrPk(): int
return $this->retrieveIntOrZeroFrom($this->http->wrapper()->query(), 'thr_pk');
}

/**
* @return Sortation
*/
protected function getSortation() : Sortation
{
$sortation = $this->factory->input()->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'),

]);
return $sortation;
}

/**
* @return list<int>
*/
Expand Down Expand Up @@ -659,32 +681,6 @@ private function getThreadEditingForm(int $a_thread_id): ilPropertyFormGUI

return $form;
}

public function editThreadObject(int $threadId, ilPropertyFormGUI $form = null): void
{
if (!$this->is_moderator) {
$this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
}

if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
$this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
}

$thread = new ilForumTopic($threadId);
$this->ensureThreadBelongsToForum($this->object->getId(), $thread);

$this->tabs_gui->activateTab('forums_threads');

if (!($form instanceof ilPropertyFormGUI)) {
$form = $this->getThreadEditingForm($threadId);
$form->setValuesByArray([
'title' => $thread->getSubject()
]);
}

$this->tpl->setContent($form->getHTML());
}

public function updateThreadObject(): void
{
if (!$this->is_moderator) {
Expand All @@ -702,18 +698,15 @@ public function updateThreadObject(): void

$this->ensureThreadBelongsToForum($this->object->getId(), $this->objCurrentTopic);

$form = $this->getThreadEditingForm($this->objCurrentTopic->getId());
if (!$form->checkInput()) {
$form->setValuesByPost();
$this->editThreadObject($this->objCurrentTopic->getId(), $form);
return;
}
$title = $this->getEditTitleModal($this->objCurrentTopic)->withRequest($this->http->request())->getData();
if(array_key_exists(0, $title)) {
$new_subject = $title[0];
$this->objCurrentTopic->setSubject($new_subject);
$this->objCurrentTopic->updateThreadTitle();

$this->objCurrentTopic->setSubject($form->getInput('title'));
$this->objCurrentTopic->updateThreadTitle();

$this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
$this->showThreadsObject();
$this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
$this->showThreadsObject();
}
}

public function markAllReadObject(): void
Expand Down Expand Up @@ -848,6 +841,51 @@ public function getContent(): string
$this->content_style_domain
);
$forwarder->setPresentationMode(ilForumPageCommandForwarder::PRESENTATION_MODE_PRESENTATION);*/

// Create topic button
if (!$this->hideToolbar() && $this->access->checkAccess('add_thread', '', $this->object->getRefId())) {
$btn = $this->uiFactory->button()
->standard(
$this->lng->txt('forums_new_thread'),
$this->ctrl->getLinkTarget($this, 'createThread')
);
$this->toolbar->addStickyItem($btn);
}

// Mark all topics as read button
if ($this->confirmation_gui_html === '' && !$this->user->isAnonymous()) {
$this->toolbar->addButton(
$this->lng->txt('forums_mark_read'),
$this->ctrl->getLinkTarget($this, 'markAllRead')
);
$this->ctrl->clearParameters($this);
}

if (!$this->user->isAnonymous() && $this->access->checkAccess('write', '', $this->ref_id)) {
$this->lng->loadLanguageModule('cntr');
$this->toolbar->addComponent(
$this->uiFactory->button()->standard(
$this->lng->txt('cntr_text_media_editor'),
$this->ctrl->getLinkTargetByClass(ilForumPageGUI::class, 'edit')
)
);
}

if (ilForumPostDraft::isSavePostDraftAllowed()) {
$drafts = ilForumPostDraft::getThreadDraftData(
$this->user->getId(),
ilObjForum::lookupForumIdByObjId($this->object->getId())
);
if ($drafts !== []) {
$draftsTable = new ilForumDraftsTableGUI(
$this,
$cmd,
$this->access->checkAccess('add_thread', '', $this->object->getRefId())
);
# $draftsTable->setData($drafts);
# $threadsTemplate->setVariable('THREADS_DRAFTS_TABLE', $draftsTable->getHTML());
}
}
$ref_id = $this->retrieveRefId();
$topicData = $frm->getOneTopic();
$tbl = new ilForumThreadObject(
Expand All @@ -859,9 +897,7 @@ public function getContent(): string
);
$data_objects = $tbl->setMapper($frm)->fetchDataAnReturnObject();

$f = $this->factory;
$renderer = $this->renderer;
$thread_buffer = [];
$thread_buffer = [];

if(is_array($data_objects) && count($data_objects) > 0) {
foreach($data_objects as $thread) {
Expand All @@ -873,7 +909,7 @@ public function getContent(): string

$link = $this->getLinkActionForThread($current_thread->getId(), $current_thread->getSubject(), 'viewThread');
$actions = $this->getActionsForThreadOverview($ref_id, $current_thread);
$list_item = $f->item()->standard($link)
$list_item = $this->factory->item()->standard($link)
->withActions($actions)
->withProperties($this->getThreadProperties($current_thread))
->withDescription($current_thread->getFirstVisiblePostNode()->getMessage());
Expand All @@ -884,11 +920,17 @@ public function getContent(): string
}
}

$std_list = $f->panel()->listing()->standard($this->object->getTitle(), [
$f->item()->group("", $thread_buffer)
$std_list = $this->factory->panel()->listing()->standard($this->object->getTitle(), [
$this->factory->item()->group("", $thread_buffer)
]);

$this->tpl->setContent($renderer->render($std_list));
$sortation = $this->getSortation();
$vc_container = $this->factory->input()->container()->viewControl()->standard([$sortation])
->withRequest($this->http->request());

$default_html = $this->renderer->render($vc_container) . $this->renderer->render($std_list);
$modals = $this->renderer->render($this->modal_collection);
$this->tpl->setContent($default_html . $modals);
return '';
}

Expand Down Expand Up @@ -950,10 +992,14 @@ protected function getActionsForThreadOverview(int $ref_id, ilForumTopic $forum_

$open_close = $this->getOpenCloseActionForThread($forum_topic, $ref_id);
$stick_or_no_stick = $this->getStickyActionForThread($forum_topic, $ref_id);
$edit_title = $this->getLinkActionForThread($ref_id, $this->lng->txt('frm_edit_title'), 'editThread', $forum_topic->getId());
$edit_title_modal = $this->getEditTitleModal($forum_topic);
$this->modal_collection[] = $edit_title_modal;
$edit_title = $this->factory->button()->shy($this->lng->txt('frm_edit_title'), '#')->withOnClick(
$edit_title_modal->getShowSignal()
);

$move = $this->getLinkActionForThread($ref_id, $this->lng->txt('move_thread_to_forum'), 'move', $forum_topic->getId());
$merge = $this->getLinkActionForThread($ref_id, $this->lng->txt('merge_posts_into_thread'), 'mergeThreads', $forum_topic->getId());

$actions = $f->dropdown()->standard([
$stick_or_no_stick,
$open_close,
Expand All @@ -968,6 +1014,26 @@ protected function getActionsForThreadOverview(int $ref_id, ilForumTopic $forum_
return $actions;
}

private function getEditTitleModal(ilForumTopic $topic)
{
$topic_id = $this->refinery->kindlyTo()->string()->transform($topic->getId());
$this->ctrl->setParameter($this, 'thr_pk', (string) $topic_id);
$target = $this->ctrl->getLinkTargetByClass(
ilObjForumGUI::class,
'editThread'
);
$this->ctrl->setParameter($this, 'thread_id', null);

return $this->factory->modal()->roundtrip(
$this->lng->txt("frm_edit_title"),
null,
[
$this->factory->input()->field()->text($this->lng->txt("frm_edit_title"))->withValue($topic->getSubject()),
],
$target
);
}

/**
* @param ilForumTopic $forum_topic
* @param int $ref_id
Expand Down Expand Up @@ -3754,7 +3820,7 @@ public function performThreadsActionObject(): void
$this->tpl->setOnScreenMessage('info', $this->lng->txt('select_max_one_thread'), true);
$this->ctrl->redirect($this, 'showThreads');
} else {
$this->editThreadObject(current($thread_ids));
$this->updateThreadObject();
return;
}
}
Expand Down
6 changes: 6 additions & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -4071,6 +4071,12 @@ common#:#forums_forum_notification_enabled#:#Sie werden über neue Beiträge in
common#:#forums_last_post#:#Letzter Beitrag
common#:#forums_notification_settings#:#Benachrichtigung über neue und geänderte Forenbeiträge
common#:#forums_threads#:#Themen
common#:#forums_thread_sorting_asc#:#Thread Title A→Z
common#:#forums_thread_sorting_dsc#:#Thread Title Z→A
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_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
6 changes: 6 additions & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -4069,6 +4069,12 @@ common#:#forums_forum_notification_enabled#:#You will be notified about new mess
common#:#forums_last_post#:#Latest Article
common#:#forums_notification_settings#:#Forums Notification Settings
common#:#forums_threads#:#Threads
common#:#forums_thread_sorting_asc#:#Thread Title A→Z
common#:#forums_thread_sorting_dsc#:#Thread Title Z→A
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_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 c269853

Please sign in to comment.