forked from ILIAS-eLearning/ILIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mantis 38554: Forum: Get rid of ilForumThreadObjectTableGUI (ILIAS-eL…
- Loading branch information
Showing
4 changed files
with
244 additions
and
248 deletions.
There are no files selected for viewing
170 changes: 170 additions & 0 deletions
170
components/ILIAS/Forum/classes/Thread/ForumThreadTableSessionStorage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ILIAS\Forum\Thread; | ||
|
||
use ForumDto; | ||
use ilForum; | ||
use ilForumAuthorInformationCache; | ||
use ilForumProperties; | ||
use ilForumTopic; | ||
use ILIAS\HTTP\Wrapper\WrapperFactory; | ||
use ILIAS\Refinery\Factory; | ||
use ilObjForum; | ||
use ilSession; | ||
use ThreadSortation; | ||
|
||
class ForumThreadTableSessionStorage | ||
{ | ||
public const string KEY_THREAD_SORTATION = 'thread_sortation'; | ||
public const string KEY_THREAD_PAGE = 'thread_page'; | ||
|
||
private WrapperFactory $http_wrapper; | ||
private Factory $refinery; | ||
|
||
public function __construct( | ||
private readonly int $forum_ref_id, | ||
private readonly bool $is_moderator, | ||
?WrapperFactory $http_wrapper = null, | ||
?Factory $refinery = null | ||
) { | ||
global $DIC; | ||
$this->http_wrapper = $http_wrapper ?? $DIC->http()->wrapper(); | ||
$this->refinery = $refinery ?? $DIC->refinery(); | ||
} | ||
|
||
public function fetchData(ilForum $forum, ForumDto $topicData): ThreadsPage | ||
{ | ||
$sortation = $this->getThreadSortation(); | ||
$page = $this->getThreadPage(); | ||
$limit = ilForumProperties::PAGE_SIZE_THREAD_OVERVIEW; | ||
|
||
$params = [ | ||
'is_moderator' => $this->is_moderator, | ||
'excluded_ids' => [], | ||
'order_column' => $sortation->field(), | ||
'order_direction' => $sortation->direction() | ||
]; | ||
|
||
$data = $forum->getAllThreads( | ||
$topicData->getTopPk(), | ||
$params, | ||
$limit, | ||
$page * $limit | ||
); | ||
if ($data['items'] === [] && $page > 0) { | ||
ilSession::set($this->buildSessionKey($this->forum_ref_id, self::KEY_THREAD_PAGE), 0); | ||
$data = $forum->getAllThreads( | ||
$topicData->getTopPk(), | ||
$params, | ||
$limit, | ||
$page * $limit | ||
); | ||
} | ||
|
||
$items = $data['items']; | ||
|
||
$thread_ids = []; | ||
$user_ids = []; | ||
foreach ($items as $thread) { | ||
/** @var ilForumTopic $thread */ | ||
$thread_ids[] = $thread->getId(); | ||
if ($thread->getDisplayUserId() > 0) { | ||
$user_ids[$thread->getDisplayUserId()] = $thread->getDisplayUserId(); | ||
} | ||
} | ||
|
||
$user_ids = array_merge( | ||
ilObjForum::getUserIdsOfLastPostsByRefIdAndThreadIds($this->forum_ref_id, $thread_ids), | ||
$user_ids | ||
); | ||
|
||
ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids)); | ||
|
||
return new ThreadsPage($items); | ||
} | ||
|
||
public function getThreadSortation(): ThreadSortation | ||
{ | ||
$query_thread_sortation = $this->getKeyValueFromQuery(self::KEY_THREAD_SORTATION); | ||
|
||
if ($query_thread_sortation !== null) { | ||
$this->setSessionKeyValue($this->forum_ref_id, self::KEY_THREAD_SORTATION, $query_thread_sortation); | ||
return ThreadSortation::tryFrom($query_thread_sortation); | ||
} | ||
|
||
$session_thread_sortation = $this->getKeyValueFromSession( | ||
$this->forum_ref_id, | ||
self::KEY_THREAD_SORTATION, | ||
ThreadSortation::DEFAULT_SORTATION->value | ||
); | ||
|
||
return ThreadSortation::tryFrom( | ||
$session_thread_sortation | ||
); | ||
} | ||
|
||
public function getThreadPage(): int | ||
{ | ||
$query_thread_page = $this->getKeyValueFromQuery(self::KEY_THREAD_PAGE, null); | ||
|
||
if ($query_thread_page !== null) { | ||
$this->setSessionKeyValue($this->forum_ref_id, self::KEY_THREAD_PAGE, $query_thread_page); | ||
return $query_thread_page; | ||
} | ||
|
||
return $this->getKeyValueFromSession( | ||
$this->forum_ref_id, | ||
self::KEY_THREAD_PAGE, | ||
$query_thread_page | ||
); | ||
} | ||
|
||
private function getKeyValueFromQuery(string $key, ?int $default = null): ?int | ||
{ | ||
return $this->http_wrapper->query()->retrieve( | ||
$key, | ||
$this->refinery->byTrying([ | ||
$this->refinery->kindlyTo()->int(), | ||
$this->refinery->always($default) | ||
]) | ||
); | ||
} | ||
|
||
private function getKeyValueFromSession(int $refId, string $key, mixed $default = null): mixed | ||
{ | ||
$session_value = ilSession::get($this->buildSessionKey($refId, $key)); | ||
if ($session_value === null) { | ||
$session_value = $default; | ||
} | ||
|
||
return $session_value; | ||
} | ||
|
||
private function setSessionKeyValue(int $refId, string $key, mixed $value): void | ||
{ | ||
ilSession::set($this->buildSessionKey($refId, $key), $value); | ||
} | ||
|
||
private function buildSessionKey(int $refId, string $key): string | ||
{ | ||
return "frm_{$refId}_$key"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ILIAS\Forum\Thread; | ||
|
||
use ilForumTopic; | ||
|
||
readonly class ThreadsPage | ||
{ | ||
/** | ||
* @param ilForumTopic[] $forum_topics | ||
*/ | ||
public function __construct(private array $forum_topics) | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @return ilForumTopic[] | ||
*/ | ||
public function getForumTopics(): array | ||
{ | ||
return $this->forum_topics; | ||
} | ||
} |
164 changes: 0 additions & 164 deletions
164
components/ILIAS/Forum/classes/class.ilForumThreadObjectTableGUI.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.