public function unread($Page = '0')
{
if (!Gdn::session()->isValid()) {
redirect('/discussions/index', 302);
}
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = c('Vanilla.Discussions.Layout');
switch ($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE) {
$this->View = 'table';
}
break;
default:
// $this->View = 'index';
break;
}
Gdn_Theme::section('DiscussionList');
// Determine offset from $Page
list($Page, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30));
$this->canonicalUrl(url(ConcatSep('/', 'discussions', 'unread', PageNumber($Page, $Limit, true, false)), true));
// Validate $Page
if (!is_numeric($Page) || $Page < 0) {
$Page = 0;
}
// Setup head.
if (!$this->data('Title')) {
$Title = c('Garden.HomepageTitle');
if ($Title) {
$this->title($Title, '');
} else {
$this->title(t('Unread Discussions'));
}
}
if (!$this->Description()) {
$this->Description(c('Garden.Description', null));
}
if ($this->Head) {
$this->Head->AddRss(url('/discussions/unread/feed.rss', true), $this->Head->title());
}
// Add modules
$this->addModule('DiscussionFilterModule');
$this->addModule('NewDiscussionModule');
$this->addModule('CategoriesModule');
$this->addModule('BookmarkedModule');
$this->setData('Breadcrumbs', array(array('Name' => t('Discussions'), 'Url' => '/discussions'), array('Name' => t('Unread'), 'Url' => '/discussions/unread')));
// Set criteria & get discussions data
$this->setData('Category', false, true);
$DiscussionModel = new DiscussionModel();
$DiscussionModel->setSort(Gdn::request()->get());
$DiscussionModel->setFilters(Gdn::request()->get());
$this->setData('Sort', $DiscussionModel->getSort());
$this->setData('Filters', $DiscussionModel->getFilters());
$DiscussionModel->Watching = true;
// Get Discussion Count
$CountDiscussions = $DiscussionModel->GetUnreadCount();
$this->setData('CountDiscussions', $CountDiscussions);
// Get Discussions
$this->DiscussionData = $DiscussionModel->GetUnread($Page, $Limit);
$this->setData('Discussions', $this->DiscussionData, true);
$this->setJson('Loading', $Page . ' to ' . $Limit);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->fireEvent('BeforeBuildPager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->configure($Page, $Limit, $CountDiscussions, 'discussions/unread/%1$s');
if (!$this->data('_PagerUrl')) {
$this->setData('_PagerUrl', 'discussions/unread/{Page}');
}
$this->setData('_Page', $Page);
$this->setData('_Limit', $Limit);
$this->fireEvent('AfterBuildPager');
// Deliver JSON data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->setJson('LessRow', $this->Pager->toString('less'));
$this->setJson('MoreRow', $this->Pager->toString('more'));
$this->View = 'discussions';
}
$this->render();
}