Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class CategoriesController extends VanillaController {
const SORT_LAST_POST = 'new';
const SORT_OLDEST_POST = 'old';

const ROOT_CATEGORY = ['Name' => 'Roundtables', 'Url'=>'/'];
/**
* @var \Closure $categoriesCompatibilityCallback A backwards-compatible callback to get `$this->data('Categories')`.
*/
Expand Down Expand Up @@ -140,14 +139,8 @@ private function getCategoryTree($category = null, $displayAs = null, $recent =
$perPage = c('Vanilla.Categories.PerPage', 30);
$page = Gdn::request()->get('Page', Gdn::request()->get('page', null));
list($offset, $limit) = offsetLimit($page, $perPage);

$filter = [];
if(Gdn::session()->isValid()) {
$filter['UserID'] = Gdn::session()->UserID;
$filter['isAdmin'] = Gdn::session()->User->Admin;
}
$categoryTree = $this->CategoryModel->getTreeAsFlat($categoryIdentifier, $offset, $limit,$filter, 'c.DateInserted', 'desc');
$countOfCategoryTree = $this->CategoryModel->countOfCategories($categoryIdentifier,$filter);
$categoryTree = $this->CategoryModel->getTreeAsFlat($categoryIdentifier, $offset, $limit,null, 'c.DateInserted', 'desc');
$countOfCategoryTree = $this->CategoryModel->countOfCategories($categoryIdentifier, null);
$this->setData('_Limit', $perPage);
$this->setData('_RecordCount', $countOfCategoryTree);
$this->setData('_CurrentRecords', count($categoryTree));
Expand Down Expand Up @@ -341,11 +334,7 @@ public function index($categoryIdentifier = '', $page = '0') {
}

// Load the breadcrumbs.

$ancestors = CategoryModel::getAncestors(val('CategoryID', $category));
array_unshift ( $ancestors , self::ROOT_CATEGORY);
$this->setData('Breadcrumbs', $ancestors);

$this->setData('Breadcrumbs', $this->buildBreadcrumbs(val('CategoryID', $category)));

$this->setData('Category', $category, true);
// Set CategoryID
Expand Down Expand Up @@ -416,8 +405,10 @@ public function index($categoryIdentifier = '', $page = '0') {
$this->Head->addRss(categoryUrl($category) . '/feed.rss', $this->Head->title());
}

// Add modules
$this->addModule('NewDiscussionModule');
if($category->DisplayAs == 'Discussions') {
// Add modules
$this->addModule('NewDiscussionModule');
}
$this->addModule('DiscussionFilterModule');
// $this->addModule('CategoriesModule');
$this->addModule('BookmarkedModule');
Expand Down Expand Up @@ -557,10 +548,7 @@ public function all($Category = '', $displayAs = '') {
$this->description(c('Garden.Description', null));
}

$ancestors = CategoryModel::getAncestors(val('CategoryID', $this->data('Category')));
array_unshift ( $ancestors , self::ROOT_CATEGORY);
$this->setData('Breadcrumbs', $ancestors);

$this->setData('Breadcrumbs', $this->buildBreadcrumbs(val('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);
Expand Down Expand Up @@ -648,7 +636,7 @@ public function all($Category = '', $displayAs = '') {
$this->setData('CategoryTree', $categoryTree);

// Add modules
if($Category) {
if($Category && $displayAs == 'Discussions') {
$this->addModule('NewDiscussionModule');
}
$this->addModule('DiscussionFilterModule');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ public function index($DiscussionID = '', $DiscussionStub = '', $Page = '') {
Gdn_Theme::section($CategoryCssClass);
}

$ancestors = CategoryModel::getAncestors($this->CategoryID);
array_unshift ( $ancestors , CategoriesController::ROOT_CATEGORY);
$this->setData('Breadcrumbs', $ancestors);
$this->setData('Breadcrumbs', $this->buildBreadcrumbs($this->CategoryID));

// Setup
$this->title($this->Discussion->Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public function discussion($categoryUrlCode = '') {
$this->fireEvent('BeforeDiscussionRender');

if ($this->CategoryID) {
$breadcrumbs = CategoryModel::getAncestors($this->CategoryID);
$breadcrumbs = $this->buildBreadcrumbs($this->CategoryID);
} else {
$breadcrumbs = [];
}
Expand All @@ -419,7 +419,6 @@ public function discussion($categoryUrlCode = '') {
'Url' => val('AddUrl', val($this->data('Type'), DiscussionModel::discussionTypes()), '/post/discussion')
];

array_unshift ( $breadcrumbs , CategoriesController::ROOT_CATEGORY);
$this->setData('Breadcrumbs', $breadcrumbs);

// FIX: Hide Announce options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class VanillaController extends Gdn_Controller {

const ROOT_CATEGORY = ['Name' => 'Roundtables', 'Url'=>'/'];

/**
* Include JS, CSS, and modules used by all methods.
*
Expand Down Expand Up @@ -70,6 +72,29 @@ protected function checkPageRange(int $offset, int $totalCount) {
}
}

protected function buildBreadcrumbs($CategoryID) {
$Category = CategoryModel::categories($CategoryID);
$ancestors = CategoryModel::getAncestors($CategoryID);
if(val('GroupID', $Category) > 0) {
$temp = [];
foreach ($ancestors as $id => $ancestor) {
if($ancestor['GroupID'] > 0) {
$temp[$ancestor['CategoryID']] = $ancestor;
} else {
if($ancestor['UrlCode'] == 'challenges-forums') {
array_push($temp, ['Name' => 'Challenge Discussions', 'Url'=>'/groups/mine?filter=challenge']);
}else if($ancestor['UrlCode'] == 'groups') {
array_push($temp, ['Name' => 'Group Discussions', 'Url'=>'/groups/mine?filter=regular']);
}
}
}
return $temp;
} else {
array_unshift($ancestors, self::ROOT_CATEGORY);
return $ancestors;
}
}

protected function log($message, $context = [], $level = Logger::DEBUG) {
// if(c('Debug')) {
Logger::log($level, sprintf('%s : %s',get_class($this), $message), $context);
Expand Down
Loading