AndyB
Well-known member
Hello,
I'm creating a new XF2 add-on called Remove moderated notices. It allows registered members to see their moderated threads in the forum view.
I have extended the function actionForum like this.
Inside the foreach I offsetUnset the thread I don't want to show, but I'm not understanding how I can update the $parent before I return it.
Thank you.
I'm creating a new XF2 add-on called Remove moderated notices. It allows registered members to see their moderated threads in the forum view.
I have extended the function actionForum like this.
PHP:
<?php
namespace Andy\RemoveModeratedNotices\XF\Pub\Controller;
use XF\Mvc\ParameterBag;
class Forum extends XFCP_Forum
{
public function actionForum(ParameterBag $params)
{
// get parent
$parent = parent::actionForum($params);
$visitor = \XF::visitor();
$userId = $visitor['user_id'];
$forum = $this->assertViewableForum($params->node_id ?: $params->node_name, $this->getForumViewExtraWith());
if ($this->responseType == 'rss')
{
return $this->getForumRss($forum);
}
$page = $this->filterPage($params->page);
$perPage = $this->options()->discussionsPerPage;
$this->assertCanonicalUrl($this->buildLink('forums', $forum, ['page' => $page]));
$threadRepo = $this->getThreadRepo();
$threadList = $threadRepo->findThreadsForForumView($forum, [
'allowOwnPending' => $this->hasContentPendingApproval()
]);
$filters = $this->getForumFilterInput($forum);
$this->applyForumFilters($forum, $threadList, $filters);
if ($page == 1)
{
$stickyThreadList = clone $threadList;
/** @var \XF\Entity\Thread[] $stickyThreads */
$stickyThreads = $stickyThreadList->where('sticky', 1)->fetch();
}
else
{
$stickyThreads = null;
}
$threadList->where('sticky', 0)
->limitByPage($page, $perPage);
$threads = $threadList->fetch();
foreach ($threads AS $thread)
{
if ($thread['discussion_state'] == 'moderated')
{
// only show thread to thread author
if ($thread['user_id'] != $userId)
{
$threads->offsetUnset($thread['thread_id']);
}
}
}
// return parent
return $parent;
}
}
Inside the foreach I offsetUnset the thread I don't want to show, but I'm not understanding how I can update the $parent before I return it.
Thank you.