From cb7186b9c1d72e95e7adb56eec7876d7f43b02e2 Mon Sep 17 00:00:00 2001 From: mjansen Date: Thu, 22 Aug 2024 19:35:51 +0200 Subject: [PATCH] Forum: Use links instead of buttons for threads (+ boyscouting) (cherry picked from commit f920479a8d989f0282f8a31a1dd19b1cf3478f7a) --- .../Forum/classes/class.ilObjForumGUI.php | 175 +++++++++--------- 1 file changed, 85 insertions(+), 90 deletions(-) diff --git a/components/ILIAS/Forum/classes/class.ilObjForumGUI.php b/components/ILIAS/Forum/classes/class.ilObjForumGUI.php index be875f0faf3b..93f744377872 100755 --- a/components/ILIAS/Forum/classes/class.ilObjForumGUI.php +++ b/components/ILIAS/Forum/classes/class.ilObjForumGUI.php @@ -20,14 +20,9 @@ use ILIAS\UI\Factory; use ILIAS\UI\Renderer; -use ILIAS\UI\Component\Button\Shy; 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; use ILIAS\Data\Factory as DataFactory; use ILIAS\Forum\Drafts\ForumDraftsTable; @@ -242,7 +237,7 @@ private function decorateWithAutosave(ilPropertyFormGUI $form): void $this->ctrl->setParameter($this, 'draft_id', $draft_id); $this->ctrl->setParameter($this, 'action', ilUtil::stripSlashes($this->requestAction)); $this->tpl->addOnLoadCode( - "il.Language.setLangVar('saving', " . json_encode($this->lng->txt('saving'), JSON_THROW_ON_ERROR) . ");" + "il.Language.setLangVar('saving', " . json_encode($this->lng->txt('saving'), JSON_THROW_ON_ERROR) . ');' ); $this->tpl->addOnLoadCode('il.ForumDraftsAutosave.init(' . json_encode([ @@ -436,7 +431,7 @@ public function executeCommand(): void case strtolower(ilRepositoryObjectSearchGUI::class): $this->addHeaderAction(); $this->setSideBlocks(); - $this->tabs_gui->activateTab("forums_threads"); + $this->tabs_gui->activateTab('forums_threads'); $this->ctrl->setReturn($this, 'view'); $search_gui = new ilRepositoryObjectSearchGUI( $this->object->getRefId(), @@ -533,7 +528,7 @@ public function executeCommand(): void $this->objCurrentTopic->setAverageRating($avg['avg']); $this->objCurrentTopic->update(); - $this->ctrl->redirect($this, "showThreads"); + $this->ctrl->redirect($this, 'showThreads'); // no break case strtolower(ilCommonActionDispatcherGUI::class): @@ -706,7 +701,6 @@ public function getContent(): string $frm->setForumId($this->object->getId()); $frm->setForumRefId($this->object->getRefId()); $frm->setMDB2Wherecondition('top_frm_fk = %s ', ['integer'], [$frm->getForumId()]); - $ref_id = $this->retrieveRefId(); // Import information: Topic (variable $topicData) means frm object, not thread $frm_object = $frm->getOneTopic(); if ($frm_object->getTopPk() > 0) { @@ -728,7 +722,6 @@ public function getContent(): string $this->tpl->setPermanentLink($this->object->getType(), $this->object->getRefId()); $ref_id = $this->retrieveRefId(); - // Create topic button if (!$this->hideToolbar() && $this->access->checkAccess('add_thread', '', $this->object->getRefId())) { $btn = $this->uiFactory->button() ->standard( @@ -742,7 +735,6 @@ public function getContent(): string $this->addDraftButtonIfDraftsExists($cmd); } - // Mark all topics as read button if ($this->confirmation_gui_html === '' && !$this->user->isAnonymous()) { $this->toolbar->addButton( $this->lng->txt('forums_mark_read'), @@ -761,7 +753,6 @@ public function getContent(): string ); } - $tbl = new ilForumThreadObjectTableGUI( $this, $cmd, @@ -798,9 +789,11 @@ private function renderThreadOverview(ilForumThreadObjectTableGUI $tbl, ilForum $link = $this->getLinkActionForThread($ref_id, $subject, 'viewThread', $current_thread->getId()); $actions = $this->getActionsForThreadOverview($ref_id, $current_thread); - $list_item = $this->factory->item()->standard($link) - ->withActions($actions) - ->withProperties($this->getThreadProperties($current_thread)); + $list_item = $this->factory + ->item() + ->standard($link) + ->withActions($actions) + ->withProperties($this->getThreadProperties($current_thread)); $list_item = $this->markTopThreadInOverview($current_thread, $list_item); if ($current_thread->isSticky()) { $top_group[] = $list_item; @@ -905,7 +898,7 @@ private function initializeThreadOffsetAndLimit(ilForumThreadObjectTableGUI $tbl $tbl->setLimit($limit); } - protected function initializeThreadSortation(ilForumThreadObjectTableGUI $tbl): void + private function initializeThreadSortation(ilForumThreadObjectTableGUI $tbl): void { $sortation = ThreadSortation::tryFrom( $this->getRequestedThreadSortation() ?? ThreadSortation::DEFAULT_SORTATION->value @@ -969,7 +962,7 @@ private function retrieveThreadIds(): array /** * @return array */ - protected function getThreadProperties(ilForumTopic $forum_topic): array + private function getThreadProperties(ilForumTopic $forum_topic): array { $this->ctrl->setParameter($this, 'thr_pk', $forum_topic->getId()); $unread_counter = $forum_topic->getNumUnreadPosts(); @@ -1006,32 +999,30 @@ protected function getThreadProperties(ilForumTopic $forum_topic): array $rating_property = [$this->lng->txt('frm_rating') => $rating->getHTML()]; } $this->ctrl->setParameter($this, 'thr_pk', null); + return array_merge($properties, $rating_property); } - /** - * @throws ilCtrlException - */ - protected function getLinkActionForThread(int $ref_id, string $title, string $cmd, int $thread_id = null): Shy - { + private function getLinkActionForThread( + int $ref_id, + string $title, + string $cmd, + int $thread_id = null + ): \ILIAS\UI\Component\Link\Link { $this->ctrl->setParameter($this, 'ref_id', $ref_id); $this->ctrl->setParameter($this, 'thr_pk', $thread_id); $this->ctrl->setParameter($this, 'page', 0); - $f = $this->uiFactory; $url = $this->ctrl->getLinkTarget($this, $cmd); $this->ctrl->setParameter($this, 'ref_id', null); $this->ctrl->setParameter($this, 'thr_pk', null); $this->ctrl->setParameter($this, 'page', null); - return $f->button()->shy($title, $url); + return $this->uiFactory->link()->standard($title, $url); } private function getActionsForThreadOverview(int $ref_id, ilForumTopic $forum_topic): Standard { - $f = $this->uiFactory; - - $actions = $f->dropdown()->standard([]); - + $actions = $this->uiFactory->dropdown()->standard([]); if ($this->is_moderator) { $open_close = $this->getOpenCloseActionForThread($forum_topic, $ref_id); $stick_or_no_stick = $this->getStickyActionForThread($forum_topic, $ref_id); @@ -1041,10 +1032,25 @@ private function getActionsForThreadOverview(int $ref_id, ilForumTopic $forum_to $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()); - $delete = $this->getLinkActionForThread($ref_id, $this->lng->txt('delete_thread'), 'confirmDeleteThreads', $forum_topic->getId()); - $actions = $f->dropdown()->standard([ + $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() + ); + $delete = $this->getLinkActionForThread( + $ref_id, + $this->lng->txt('delete_thread'), + 'confirmDeleteThreads', + $forum_topic->getId() + ); + $actions = $this->uiFactory->dropdown()->standard([ $stick_or_no_stick, $open_close, $edit_title, @@ -1068,10 +1074,10 @@ private function getEditTitleModal(ilForumTopic $topic): RoundTrip $this->ctrl->setParameter($this, 'thread_id', null); return $this->factory->modal()->roundtrip( - $this->lng->txt("frm_edit_title"), - null, + $this->lng->txt('frm_edit_title'), + [], [ - $this->factory->input()->field()->text($this->lng->txt("frm_edit_title"))->withValue($topic->getSubject()), + $this->factory->input()->field()->text($this->lng->txt('frm_edit_title'))->withValue($topic->getSubject()), ], $target ); @@ -1105,10 +1111,9 @@ private function addDraftButtonIfDraftsExists(string $cmd) $threadsTemplate->setVariable('THREADS_DRAFTS_TABLE', $this->uiRenderer->render($table->getComponent())); $draft_modal = $this->factory->modal()->roundtrip( - $this->lng->txt("drafts"), - $this->factory->legacy($threadsTemplate->get()) + $this->lng->txt('drafts'), + [$this->factory->legacy($threadsTemplate->get())] ); - ; $this->modal_collection[] = $draft_modal; $edit_title = $this->factory->button()->standard($this->lng->txt('drafts'), '#')->withOnClick( $draft_modal->getShowSignal() @@ -1119,38 +1124,27 @@ private function addDraftButtonIfDraftsExists(string $cmd) } } - /** - * @throws ilCtrlException - */ - protected function getStickyActionForThread(ilForumTopic $forum_topic, int $ref_id): Shy + private function getStickyActionForThread(ilForumTopic $forum_topic, int $ref_id): \ILIAS\UI\Component\Link\Link { - if ($forum_topic->isSticky()) { - $stick_or_no_stick = $this->getLinkActionForThread( - $ref_id, - $this->lng->txt('make_topics_non_sticky'), - 'make_topics_non_sticky', - $forum_topic->getId() - ); - } else { - $stick_or_no_stick = $this->getLinkActionForThread($ref_id, $this->lng->txt('make_topics_sticky'), 'makesticky', $forum_topic->getId()); - } - return $stick_or_no_stick; + return $this->getLinkActionForThread( + $ref_id, + $this->lng->txt($forum_topic->isSticky() ? 'make_topics_non_sticky' : 'make_topics_sticky'), + $forum_topic->isSticky() ? 'make_topics_non_sticky' : 'makesticky', + $forum_topic->getId() + ); } - /** - * @throws ilCtrlException - */ - protected function getOpenCloseActionForThread(ilForumTopic $forum_topic, int $ref_id): Shy + private function getOpenCloseActionForThread(ilForumTopic $forum_topic, int $ref_id): \ILIAS\UI\Component\Link\Link { - if ($forum_topic->isClosed()) { - $open_close = $this->getLinkActionForThread($ref_id, $this->lng->txt('reopen_topics'), 'reopen', $forum_topic->getId()); - } else { - $open_close = $this->getLinkActionForThread($ref_id, $this->lng->txt('close_topics'), 'close', $forum_topic->getId()); - } - return $open_close; + return $this->getLinkActionForThread( + $ref_id, + $this->lng->txt($forum_topic->isClosed() ? 'reopen_topics' : 'close_topics'), + $forum_topic->isClosed() ? 'reopen' : 'close', + $forum_topic->getId() + ); } - protected function markTopThreadInOverview( + private function markTopThreadInOverview( ilForumTopic $current_thread, Item $list_item ): Item { @@ -1162,7 +1156,7 @@ protected function markTopThreadInOverview( return $list_item; } - protected function initStyleSheets(): void + private function initStyleSheets(): void { $this->content_style_gui->addCss($this->tpl, $this->ref_id); $this->tpl->setCurrentBlock('SyntaxStyle'); @@ -1171,11 +1165,9 @@ protected function initStyleSheets(): void } /** - * @param ilForumPostDraft[] $drafts - * @throws ilCtrlException - * @throws ilTemplateException + * @param list $drafts */ - protected function renderDraftContent( + private function renderDraftContent( ilTemplate $tpl, string $action, ilForumPost $referencePosting, @@ -1345,13 +1337,13 @@ protected function renderDraftContent( $draft->setPostMessage(nl2br($draft->getPostMessage())); } - if ($spanClass !== "") { + if ($spanClass !== '') { $tpl->setVariable( 'POST', - "" . ilRTE::_replaceMediaObjectImageSrc( + '' . ilRTE::_replaceMediaObjectImageSrc( $draft->getPostMessage(), 1 - ) . "" + ) . '' ); } else { $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($draft->getPostMessage(), 1)); @@ -1575,14 +1567,14 @@ protected function renderPostContent( $tpl->setVariable( 'SUBJECT', - "" . $node->getSubject() . "" + '' . $node->getSubject() . '' ); } $tpl->setVariable('POST_DATE', $frm->convertDate($node->getCreateDate())); if (!$node->isCensored() || ($this->objCurrentPost->getId() === $node->getId() && $action === 'censor')) { - $spanClass = ""; + $spanClass = ''; if (ilForum::_isModerator($this->ref_id, $node->getDisplayUserId())) { $spanClass = 'moderator'; } @@ -1596,15 +1588,18 @@ protected function renderPostContent( if ($spanClass !== '') { $tpl->setVariable( 'POST', - "" . + '' . ilRTE::_replaceMediaObjectImageSrc($node->getMessage(), 1) . - "" + '' ); } else { $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($node->getMessage(), 1)); } } else { - $tpl->setVariable('POST', "" . nl2br((string) $node->getCensorshipComment()) . ""); + $tpl->setVariable( + 'POST', + '' . nl2br((string) $node->getCensorshipComment()) . '' + ); } $tpl->parseCurrentBlock(); @@ -1635,7 +1630,7 @@ protected function afterSave(ilObject $new_object): void protected function getTabs(): void { - $this->ilHelp->setScreenIdComponent("frm"); + $this->ilHelp->setScreenIdComponent('frm'); $this->ctrl->setParameter($this, 'ref_id', $this->ref_id); @@ -1897,9 +1892,9 @@ public function performDeleteThreadsObject(): void $frm = new ilForum(); - $success_message = "forums_thread_deleted"; + $success_message = 'forums_thread_deleted'; if (count($threadIds) > 1) { - $success_message = "forums_threads_deleted"; + $success_message = 'forums_threads_deleted'; } $threads = []; @@ -2021,11 +2016,11 @@ static function (array $draft): int { public function prepareThreadScreen(ilObjForum $a_forum_obj): void { - $this->ilHelp->setScreenIdComponent("frm"); + $this->ilHelp->setScreenIdComponent('frm'); $this->tpl->loadStandardTemplate(); - $this->tpl->setTitleIcon(ilObject::_getIcon(0, "big", "frm")); + $this->tpl->setTitleIcon(ilObject::_getIcon(0, 'big', 'frm')); $this->tabs_gui->setBackTarget( $this->lng->txt('frm_all_threads'), @@ -3357,10 +3352,10 @@ public function viewThreadObject(): void if ($firstNodeInThread) { $this->objCurrentTopic->updateVisits(); - $this->tpl->setTitle($this->lng->txt('forums_thread') . " \"" . $this->objCurrentTopic->getSubject() . "\""); + $this->tpl->setTitle($this->lng->txt('forums_thread') . ' "' . $this->objCurrentTopic->getSubject() . '"'); $this->locator->addRepositoryItems(); - $this->locator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "_top"); + $this->locator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ''), '_top'); $this->tpl->setLocator(); if ( @@ -3955,7 +3950,7 @@ public function performMoveThreadsObject(): void ); if ([] !== $errorMessages) { - $this->tpl->setOnScreenMessage('failure', implode("

", $errorMessages), true); + $this->tpl->setOnScreenMessage('failure', implode('

', $errorMessages), true); $this->ctrl->redirect($this, 'showThreads'); } @@ -4519,7 +4514,7 @@ protected function addLocatorItems(): void public function handleFormInput(string $a_text, bool $a_stripslashes = true): string { - $a_text = str_replace(["<", ">"], ["<", ">"], $a_text); + $a_text = str_replace(['<', '>'], ['<', '>'], $a_text); if ($a_stripslashes) { $a_text = ilUtil::stripSlashes($a_text); } @@ -4529,7 +4524,7 @@ public function handleFormInput(string $a_text, bool $a_stripslashes = true): st public function prepareFormOutput(string $a_text): string { - $a_text = str_replace(["<", ">"], ["<", ">"], $a_text); + $a_text = str_replace(['<', '>'], ['<', '>'], $a_text); return ilLegacyFormElementsUtil::prepareFormOutput($a_text); } @@ -4649,7 +4644,7 @@ protected function initHeaderAction(?string $sub_type = null, ?int $sub_id = nul $notificationsModal = $this->uiFactory->modal()->roundtrip( $this->lng->txt('notification_settings'), - $events_form_builder->build() + [$events_form_builder->build()] )->withActionButtons([ $this->uiFactory ->button() @@ -5826,7 +5821,7 @@ private function renderSplitButton( $items = []; foreach ($actions as $lng_id => $url) { if ('frm_revoke_censorship' === $lng_id || 'frm_censorship' === $lng_id) { - $modalTemplate = new ilTemplate("tpl.forums_censor_modal.html", true, true, 'components/ILIAS/Forum'); + $modalTemplate = new ilTemplate('tpl.forums_censor_modal.html', true, true, 'components/ILIAS/Forum'); $formID = str_replace('.', '_', uniqid('form', true)); $modalTemplate->setVariable('FORM_ID', $formID); @@ -5850,7 +5845,7 @@ static function (string $id) use ($formID): string { ); $modal = $this->uiFactory->modal()->roundtrip( $this->lng->txt($lng_id), - $content + [$content] )->withActionButtons([$submitBtn]); $items[] = $this->uiFactory->button()->shy($this->lng->txt($lng_id), '#')->withOnClick( $modal->getShowSignal()