<?php
namespace AH\FeaturedThreads\XF\Pub;
use XF\Container;
use XF\HTTP\Response;
use XF\Mvc\Renderer\AbstractRenderer;
use XF\Mvc\Reply\AbstractReply;
class App extends \XF\App
{
protected $preLoadLocal = [
'featuredThreads',
'featuredThreadsLastReset'
];
protected function updateUserCaches()
{
$visitor = \XF::visitor();
$session = $this->session();
if (!$visitor->user_id)
{
return;
}
if (!$session->keyExists('dismissedFeaturedThreads'))
{
$updateDismissed = true;
}
else
{
$sessionLastFeaturedThreadUpdate = intval($session->get('lastFeaturedThreadUpdate'));
$dbLastFeaturedThreadReset = $this->get('featuredThreads.lastReset');
$updateDismissed = ($dbLastFeaturedThreadReset > $sessionLastFeaturedThreadUpdate);
}
if ($updateDismissed)
{
$session->dismissedFeaturedThreads = $this->repository('AH\FeaturedThreads:FeaturedThread')->getDismissedFeaturedThreadsForUser($visitor);
$session->lastFeaturedThreadUpdate = \XF::$time;
}
}
protected function renderPageHtml($content, array $params, AbstractReply $reply, AbstractRenderer $renderer)
{
$params['featuredThreads'] = $this->getFeaturedThreadList($params)->getFeaturedThreads();
$this->fire('app_pub_render_page', [$this, &$params, $reply, $renderer]);
return $templater->renderTemplate($templateName, $params);
}
protected function getFeaturedThreadList(array $pageParams)
{
$class = $this->extendClass('AH\FeaturedThreads\FeaturedThreadList');
/** @var \AH\FeaturedThreads\FeaturedThread $noticeList */
$featuredThreadList = new $class($this, \XF::visitor(), $pageParams);
$dismissedFeaturedThreads = $this->session()->dismissedFeaturedThreads;
if ($dismissedFeaturedThreads)
{
$featuredThreadsList->setDismissed($dismissedFeaturedThreads);
}
foreach ($this->container('featuredThreads') AS $key => $featuredThread)
{
$featuredThreadList->addConditionalFeaturedThread($key, $featuredThread);
}
$this->fire('featuredThreads_setup', [$this, $featuredThreadList, $pageParams]);
return $featuredThreadList;
}
}