Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 71 additions & 81 deletions components/ILIAS/Forum/classes/class.ilObjForumGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
*********************************************************************/

declare(strict_types=1);

use ILIAS\Forum\ForumDraftAccess;
use ILIAS\Forum\Thread\ForumThreadTableSessionStorage;
use ILIAS\Forum\ThreadBelongsToForum;
use ILIAS\UI\Factory;
use ILIAS\UI\Renderer;
use ILIAS\UI\Component\Dropdown\Standard;
Expand Down Expand Up @@ -543,7 +544,48 @@ public function executeCommand(): void
$news_set_gui->setPublicNotification(true);
$this->ctrl->forwardCommand($news_set_gui);
break;
case strtolower(ForumStatisticsGUI::class):
$this->ctrl->forwardCommand(new ForumStatisticsGUI($this->getRefId()));
break;
case strtolower(ForumFileDeliveryGUI::class):
$forum_draft_access_adapter = new readonly class (
function(int|ilForumPostDraft $draft): void {
$this->checkDraftAccess($draft);
}
) implements ForumDraftAccess {
public function __construct(private Closure $closure)
{
}
public function checkDraftAccess(int|ilForumPostDraft $draft): void
{
($this->closure)($draft);
}
};

$thread_belongs_to_forum_adapter = new readonly class (
function(int $objId, ilForumTopic $thread): void {
$this->ensureThreadBelongsToForum($objId, $thread);
}
) implements ThreadBelongsToForum {
public function __construct(private Closure $closure)
{
}

public function ensureThreadBelongsToForum(int $objId, ilForumTopic $thread): void
{
($this->closure)($objId, $thread);
}
};

$forum_file_delivery_gui = new ForumFileDeliveryGUI(
$this->getRefId(),
$this->retrieveDraftId(),
$this->objCurrentPost,
$forum_draft_access_adapter,
$thread_belongs_to_forum_adapter,
);
$this->ctrl->forwardCommand($forum_file_delivery_gui);
break;
default:
if (in_array($cmd, ['close', 'reopen', 'make_topics_non_sticky', 'makesticky', 'editThread', 'move'])) {
$cmd = 'performThreadsAction';
Expand Down Expand Up @@ -1140,7 +1182,10 @@ private function renderDraftContent(
$download_zip_button = $this->uiFactory->button()
->standard(
$this->lng->txt('download'),
$this->ctrl->getLinkTarget($this, 'deliverDraftZipFile')
$this->ctrl->getLinkTargetByClass(
ForumFileDeliveryGUI::class,
ForumFileDeliveryGUI::CMD_DELIVER_DRAFT_ZIP_FILE
)
);
$this->ctrl->setParameter($this, 'draft_id', '');
$tpl->setVariable('DOWNLOAD_ZIP', $this->uiRenderer->render($download_zip_button));
Expand Down Expand Up @@ -1333,7 +1378,10 @@ protected function renderPostContent(
$download_zip_button = $this->uiFactory->button()
->standard(
$this->lng->txt('download'),
$this->ctrl->getLinkTarget($this, 'deliverZipFile')
$this->ctrl->getLinkTargetByClass(
ForumFileDeliveryGUI::class,
ForumFileDeliveryGUI::CMD_DELIVER_ZIP_FILE
)
);
$tpl->setVariable('DOWNLOAD_ZIP', $this->uiRenderer->render($download_zip_button));
}
Expand Down Expand Up @@ -1669,12 +1717,12 @@ protected function getTabs(): void
}

if ($hasStatisticsAccess) {
$force_active = $this->ctrl->getCmd() === 'showStatistics';
$force_active = $this->ctrl->getCmd() === ForumStatisticsGUI::CMD_SHOW;
$this->tabs_gui->addTarget(
self::UI_TAB_ID_STATS,
$this->ctrl->getLinkTarget($this, 'showStatistics'),
'showStatistics',
static::class,
$this->ctrl->getLinkTargetByClass(ForumStatisticsGUI::class, ForumStatisticsGUI::CMD_SHOW),
ForumStatisticsGUI::CMD_SHOW,
ForumStatisticsGUI::class,
'',
$force_active
);
Expand All @@ -1700,43 +1748,6 @@ protected function getTabs(): void
}
}

public function showStatisticsObject(): void
{
if (!$this->settings->get('enable_fora_statistics', '0')) {
$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);
}

if (!$this->objProperties->isStatisticEnabled()) {
if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
$this->tpl->setOnScreenMessage('info', $this->lng->txt('frm_statistics_disabled_for_participants'));
} else {
$this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
}
}

$this->object->Forum->setForumId($this->object->getId());

$tbl = new \ILIAS\Forum\Statistics\ForumStatisticsTable(
$this->object,
$this->objProperties,
ilLearningProgressAccess::checkAccess($this->object->getRefId()),
$this->access->checkRbacOrPositionPermissionAccess(
'read_learning_progress',
'read_learning_progress',
$this->object->getRefId()
),
$this->user,
$this->ui_factory,
$this->request,
$this->lng
);
$this->tpl->setContent($this->uiRenderer->render($tbl->getComponent()));
}

public static function _goto($a_target, $a_thread = 0, $a_posting = 0): void
{
global $DIC;
Expand Down Expand Up @@ -3128,15 +3139,22 @@ public function viewThreadObject(): void
$oForumObjects = $this->getForumObjects();
$forumObj = $oForumObjects['forumObj'];
$frm = $oForumObjects['frm'];
$file_obj = $oForumObjects['file_obj'];

$selected_draft_id = (int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0);
if (isset($this->httpRequest->getQueryParams()['file'])) {
$file_obj_for_delivery = $file_obj;
if ($selected_draft_id > 0 && ilForumPostDraft::isSavePostDraftAllowed()) {
$file_obj_for_delivery = new ilFileDataForumDrafts($forumObj->getId(), $selected_draft_id);
}
$file_obj_for_delivery->deliverFile(ilUtil::stripSlashes($this->httpRequest->getQueryParams()['file']));
$file = $this->http->wrapper()->query()->retrieve(
'file',
$this->refinery->byTrying([
$this->refinery->kindlyTo()->string(),
$this->refinery->always(null)
])
);
if ($file) {
$this->ctrl->setParameterByClass(ForumFileDeliveryGUI::class, 'pos_pk', $this->objCurrentPost->getId());
$this->ctrl->setParameterByClass(ForumFileDeliveryGUI::class, 'draft_id', $this->retrieveDraftId());
$this->ctrl->setParameterByClass(ForumFileDeliveryGUI::class, 'file', $file);
$this->ctrl->redirectByClass(
ForumFileDeliveryGUI::class,
ForumFileDeliveryGUI::CMD_DELIVER_FILE
);
}

if ($this->objCurrentTopic->getId() === 0) {
Expand Down Expand Up @@ -4785,34 +4803,6 @@ protected function setSideBlocks(): void
$this->tpl->setRightContent($content);
}

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

$draft = ilForumPostDraft::newInstanceByDraftId($this->retrieveDraftId());
$this->checkDraftAccess($draft);
$fileData = new ilFileDataForumDrafts(0, $draft->getDraftId());
if (!$fileData->deliverZipFile()) {
$this->ctrl->redirect($this);
}
}

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

$this->ensureThreadBelongsToForum($this->object->getId(), $this->objCurrentPost->getThread());

$fileData = new ilFileDataForum($this->object->getId(), $this->objCurrentPost->getId());
if (!$fileData->deliverZipFile()) {
$this->ctrl->redirect($this);
}
}

protected function editThreadDraftObject(?ilPropertyFormGUI $form = null): void
{
if (!ilForumPostDraft::isSavePostDraftAllowed() ||
Expand Down Expand Up @@ -5682,7 +5672,7 @@ private function hasDraftAccess(int|ilForumPostDraft $draft): bool
{
$draft = is_int($draft) ? ilForumPostDraft::newInstanceByDraftId($draft) : $draft;
return (
$draft->getDraftId() > 1 &&
$draft->getDraftId() > 0 &&
!$this->user->isAnonymous() &&
$this->access->checkAccess('add_reply', '', $this->object->getRefId()) &&
$this->user->getId() === $draft->getPostAuthorId()
Expand Down
31 changes: 31 additions & 0 deletions components/ILIAS/Forum/src/ForumDraftAccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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;

use Closure;
use ilForumPostDraft;

interface ForumDraftAccess
{
public function __construct(Closure $draft_access_closure);

public function checkDraftAccess(int|ilForumPostDraft $draft): void;
}
31 changes: 31 additions & 0 deletions components/ILIAS/Forum/src/ThreadBelongsToForum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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;

use Closure;
use ilForumTopic;

interface ThreadBelongsToForum
{
public function __construct(Closure $draft_access_closure);

public function ensureThreadBelongsToForum(int $objId, ilForumTopic $thread): void;
}
Loading