/** * Displays the amounts of unanswered questions. * * @param DiscussionsController $sender Sending controller instance. * @param array $args Event arguments. */ public function discussionsController_unanswered_render($sender, $args) { $sender->setData('CountDiscussions', false); // Add 'Ask a Question' button if using BigButtons. if (c('Plugins.QnA.UseBigButtons')) { $QuestionModule = new NewQuestionModule($sender, 'plugins/QnA'); $sender->addModule($QuestionModule); } // Remove announcements that aren't questions... if (is_a($sender->data('Announcements'), 'Gdn_DataSet')) { $sender->data('Announcements')->result(); $Announcements = array(); foreach ($sender->data('Announcements') as $i => $Row) { if (val('Type', $Row) == 'Question') { $Announcements[] = $Row; } } trace($Announcements); $sender->setData('Announcements', $Announcements); $sender->AnnounceData = $Announcements; } }
/** * Load discussions for a specific tag. * @param DiscussionsController $Sender */ public function discussionsController_Tagged_create($Sender) { Gdn_Theme::section('DiscussionList'); $Args = $Sender->RequestArgs; $Get = array_change_key_case($Sender->Request->get()); if ($UseCategories = c('Plugins.Tagging.UseCategories')) { // The url is in the form /category/tag/p1 $CategoryCode = val(0, $Args); $Tag = val(1, $Args); $Page = val(2, $Args); } else { // The url is in the form /tag/p1 $CategoryCode = ''; $Tag = val(0, $Args); $Page = val(1, $Args); } // Look for explcit values. $CategoryCode = val('category', $Get, $CategoryCode); $Tag = val('tag', $Get, $Tag); $Page = val('page', $Get, $Page); $Category = CategoryModel::categories($CategoryCode); $Tag = stringEndsWith($Tag, '.rss', true, true); list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30)); $MultipleTags = strpos($Tag, ',') !== false; $Sender->setData('Tag', $Tag, true); $TagModel = TagModel::instance(); $RecordCount = false; if (!$MultipleTags) { $Tags = $TagModel->getWhere(array('Name' => $Tag))->resultArray(); if (count($Tags) == 0) { throw notFoundException('Page'); } if (count($Tags) > 1) { foreach ($Tags as $TagRow) { if ($TagRow['CategoryID'] == val('CategoryID', $Category)) { break; } } } else { $TagRow = array_pop($Tags); } $Tags = $TagModel->getRelatedTags($TagRow); $RecordCount = $TagRow['CountDiscussions']; $Sender->setData('CountDiscussions', $RecordCount); $Sender->setData('Tags', $Tags); $Sender->setData('Tag', $TagRow); $ChildTags = $TagModel->getChildTags($TagRow['TagID']); $Sender->setData('ChildTags', $ChildTags); } $Sender->title(htmlspecialchars($TagRow['FullName'])); $UrlTag = rawurlencode($Tag); if (urlencode($Tag) == $Tag) { $Sender->canonicalUrl(url(ConcatSep('/', "/discussions/tagged/{$UrlTag}", PageNumber($Offset, $Limit, true)), true)); $FeedUrl = url(ConcatSep('/', "/discussions/tagged/{$UrlTag}/feed.rss", PageNumber($Offset, $Limit, true, false)), '//'); } else { $Sender->canonicalUrl(url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, true)) . '?Tag=' . $UrlTag, true)); $FeedUrl = url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, true, false), 'feed.rss') . '?Tag=' . $UrlTag, '//'); } if ($Sender->Head) { $Sender->addJsFile('discussions.js'); $Sender->Head->addRss($FeedUrl, $Sender->Head->title()); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Add Modules $Sender->addModule('NewDiscussionModule'); $Sender->addModule('DiscussionFilterModule'); $Sender->addModule('BookmarkedModule'); $Sender->setData('Category', false, true); $Sender->AnnounceData = false; $Sender->setData('Announcements', array(), true); $DiscussionModel = new DiscussionModel(); $TagModel->setTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->get('op', 'or')); $Sender->DiscussionData = $DiscussionModel->get($Offset, $Limit, array('Announce' => 'all')); $Sender->setData('Discussions', $Sender->DiscussionData, true); $Sender->setJson('Loading', $Offset . ' to ' . $Limit); // Build a pager. $PagerFactory = new Gdn_PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender); $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->configure($Offset, $Limit, $RecordCount, ''); $Sender->View = c('Vanilla.Discussions.Layout'); /* // If these don't equal, then there is a category that should be inserted. if ($UseCategories && $Category && $TagRow['FullName'] != val('Name', $Category)) { $Sender->Data['Breadcrumbs'][] = array('Name' => $Category['Name'], 'Url' => TagUrl($TagRow)); } $Sender->Data['Breadcrumbs'][] = array('Name' => $TagRow['FullName'], 'Url' => ''); */ // Render the controller. $this->View = c('Vanilla.Discussions.Layout') == 'table' ? 'table' : 'index'; $Sender->render($this->View, 'discussions', 'vanilla'); }