/** * Show all categories and few discussions from each. * * @param string $Category The url code of the parent category. * @since 2.0.0 * @access public */ public function discussions($Category = '') { // Setup head $this->addJsFile('discussions.js'); $this->Menu->highlightRoute('/discussions'); if (!$this->title()) { $Title = c('Garden.HomepageTitle'); if ($Title) { $this->title($Title, ''); } else { $this->title(t('All Categories')); } } if (!$Category) { $this->Description(c('Garden.Description', null)); } Gdn_Theme::section('CategoryDiscussionList'); // Set the category follow toggle before we load category data so that it affects the category query appropriately. $CategoryFollowToggleModule = new CategoryFollowToggleModule($this); $CategoryFollowToggleModule->SetToggle(); $this->CategoryModel->Watching = !Gdn::session()->GetPreference('ShowAllCategories'); if ($Category) { $Subtree = CategoryModel::GetSubtree($Category, false); $CategoryIDs = consolidateArrayValuesByKey($Subtree, 'CategoryID'); $Categories = $this->CategoryModel->GetFull($CategoryIDs)->resultArray(); } else { $Categories = $this->CategoryModel->GetFull()->resultArray(); } $this->setData('Categories', $Categories); // Get category data and discussions $this->DiscussionsPerCategory = c('Vanilla.Discussions.PerCategory', 5); $DiscussionModel = new DiscussionModel(); $this->CategoryDiscussionData = array(); foreach ($this->CategoryData->result() as $Category) { if ($Category->CategoryID > 0) { $this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->get(0, $this->DiscussionsPerCategory, array('d.CategoryID' => $Category->CategoryID, 'Announce' => 'all')); } } // Add modules $this->addModule('NewDiscussionModule'); $this->addModule('DiscussionFilterModule'); $this->addModule('CategoriesModule'); $this->addModule('BookmarkedModule'); $this->addModule($CategoryFollowToggleModule); // Set view and render $this->View = 'discussions'; $this->canonicalUrl(url('/categories', true)); $Path = $this->fetchViewLocation('helper_functions', 'discussions', false, false); if ($Path) { include_once $Path; } // For GetOptions function $Path2 = $this->fetchViewLocation('helper_functions', 'categories', false, false); if ($Path2) { include_once $Path2; } $this->render(); }
/** * Show all discussions in a particular category. * * @since 2.0.0 * @access public * * @param string $CategoryIdentifier Unique category slug or ID. * @param int $Offset Number of discussions to skip. */ public function Index($CategoryIdentifier = '', $Page = '0') { if ($CategoryIdentifier == '') { // Figure out which category layout to choose (Defined on "Homepage" settings page). $Layout = C('Vanilla.Categories.Layout'); switch ($Layout) { case 'mixed': $this->View = 'discussions'; $this->Discussions(); break; case 'table': $this->Table(); break; default: $this->View = 'all'; $this->All(); break; } return; } else { Gdn_Theme::Section('DiscussionList'); // 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; } $Category = CategoryModel::Categories($CategoryIdentifier); if (empty($Category)) { if ($CategoryIdentifier) { throw NotFoundException(); } } $Category = (object) $Category; Gdn_Theme::Section($Category->CssClass); // Load the breadcrumbs. $this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $Category))); $this->SetData('Category', $Category, TRUE); // Load the subtree. if (C('Vanilla.ExpandCategories')) { $Categories = CategoryModel::GetSubtree($CategoryIdentifier); } else { $Categories = array($Category); } $this->SetData('Categories', $Categories); // Setup head $this->AddCssFile('vanilla.css'); $this->Menu->HighlightRoute('/discussions'); if ($this->Head) { $this->AddJsFile('discussions.js'); $this->AddJsFile('bookmark.js'); $this->AddJsFile('options.js'); $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title()); } $this->Title(GetValue('Name', $Category, '')); $this->Description(GetValue('Description', $Category), TRUE); // Set CategoryID $CategoryID = GetValue('CategoryID', $Category); $this->SetData('CategoryID', $CategoryID, TRUE); // Add modules $this->AddModule('NewDiscussionModule'); $this->AddModule('DiscussionFilterModule'); $this->AddModule('CategoriesModule'); $this->AddModule('BookmarkedModule'); // Get a DiscussionModel $DiscussionModel = new DiscussionModel(); $CategoryIDs = ConsolidateArrayValuesByKey($this->Data('Categories'), 'CategoryID'); $Wheres = array('d.CategoryID' => $CategoryIDs); $this->SetData('_ShowCategoryLink', count($CategoryIDs) > 1); // Check permission $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', GetValue('PermissionCategoryID', $Category)); // Set discussion meta data. $this->EventArguments['PerPage'] = C('Vanilla.Discussions.PerPage', 30); $this->FireEvent('BeforeGetDiscussions'); list($Offset, $Limit) = OffsetLimit($Page, $this->EventArguments['PerPage']); if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } $CountDiscussions = $DiscussionModel->GetCount($Wheres); $this->SetData('CountDiscussions', $CountDiscussions); $this->SetData('_Limit', $Limit); // We don't wan't child categories in announcements. $Wheres['d.CategoryID'] = $CategoryID; $AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet(); $this->SetData('AnnounceData', $AnnounceData, TRUE); $Wheres['d.CategoryID'] = $CategoryIDs; $this->DiscussionData = $this->SetData('Discussions', $DiscussionModel->GetWhere($Wheres, $Offset, $Limit)); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('Pager', $this); $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($Offset, $Limit, $CountDiscussions, array('CategoryUrl')); $this->Pager->Record = $Category; PagerModule::Current($this->Pager); $this->SetData('_Page', $Page); // Set the canonical Url. $this->CanonicalUrl(CategoryUrl($Category, PageNumber($Offset, $Limit))); // Change the controller name so that it knows to grab the discussion views $this->ControllerName = 'DiscussionsController'; // Pick up the discussions class $this->CssClass = 'Discussions'; // 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'; } // Render default view. $this->FireEvent('BeforeCategoriesRender'); $this->Render(); } }
/** * Show all (nested) categories. * * @since 2.0.17 * @access public */ public function All($Category = '') { // Setup head. $this->Menu->HighlightRoute('/discussions'); if (!$this->Title()) { $Title = C('Garden.HomepageTitle'); if ($Title) { $this->Title($Title, ''); } else { $this->Title(T('All Categories')); } } Gdn_Theme::Section('CategoryList'); $this->Description(C('Garden.Description', NULL)); $this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $this->Data('Category')))); // Set the category follow toggle before we load category data so that it affects the category query appropriately. $CategoryFollowToggleModule = new CategoryFollowToggleModule($this); $CategoryFollowToggleModule->SetToggle(); // Get category data $this->CategoryModel->Watching = !Gdn::Session()->GetPreference('ShowAllCategories'); if ($Category) { $Subtree = CategoryModel::GetSubtree($Category); $CategoryIDs = ConsolidateArrayValuesByKey($Subtree, 'CategoryID'); $Categories = $this->CategoryModel->GetFull($CategoryIDs)->ResultArray(); } else { $Categories = $this->CategoryModel->GetFull()->ResultArray(); } $this->SetData('Categories', $Categories); // Add modules $this->AddModule('NewDiscussionModule'); $this->AddModule('DiscussionFilterModule'); $this->AddModule('BookmarkedModule'); $this->AddModule($CategoryFollowToggleModule); $this->CanonicalUrl(Url('/categories', TRUE)); $Location = $this->FetchViewLocation('helper_functions', 'categories', FALSE, FALSE); if ($Location) { include_once $Location; } $this->Render(); }