Skip to content

Commit c45a9e0

Browse files
authored
Merge pull request #442 from topcoder-platform/issues-438
Issues-438: fixed rendering templates, Issues-439: Category Dropdown, Issues-415: breadcrumbs
2 parents 1adbe1f + 2b50cd4 commit c45a9e0

File tree

6 files changed

+328
-42
lines changed

6 files changed

+328
-42
lines changed

vanilla/applications/vanilla/controllers/class.categoriescontroller.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class CategoriesController extends VanillaController {
3434
const SORT_LAST_POST = 'new';
3535
const SORT_OLDEST_POST = 'old';
3636

37-
const ROOT_CATEGORY = ['Name' => 'Roundtables', 'Url'=>'/'];
3837
/**
3938
* @var \Closure $categoriesCompatibilityCallback A backwards-compatible callback to get `$this->data('Categories')`.
4039
*/
@@ -140,14 +139,8 @@ private function getCategoryTree($category = null, $displayAs = null, $recent =
140139
$perPage = c('Vanilla.Categories.PerPage', 30);
141140
$page = Gdn::request()->get('Page', Gdn::request()->get('page', null));
142141
list($offset, $limit) = offsetLimit($page, $perPage);
143-
144-
$filter = [];
145-
if(Gdn::session()->isValid()) {
146-
$filter['UserID'] = Gdn::session()->UserID;
147-
$filter['isAdmin'] = Gdn::session()->User->Admin;
148-
}
149-
$categoryTree = $this->CategoryModel->getTreeAsFlat($categoryIdentifier, $offset, $limit,$filter, 'c.DateInserted', 'desc');
150-
$countOfCategoryTree = $this->CategoryModel->countOfCategories($categoryIdentifier,$filter);
142+
$categoryTree = $this->CategoryModel->getTreeAsFlat($categoryIdentifier, $offset, $limit,null, 'c.DateInserted', 'desc');
143+
$countOfCategoryTree = $this->CategoryModel->countOfCategories($categoryIdentifier, null);
151144
$this->setData('_Limit', $perPage);
152145
$this->setData('_RecordCount', $countOfCategoryTree);
153146
$this->setData('_CurrentRecords', count($categoryTree));
@@ -341,11 +334,7 @@ public function index($categoryIdentifier = '', $page = '0') {
341334
}
342335

343336
// Load the breadcrumbs.
344-
345-
$ancestors = CategoryModel::getAncestors(val('CategoryID', $category));
346-
array_unshift ( $ancestors , self::ROOT_CATEGORY);
347-
$this->setData('Breadcrumbs', $ancestors);
348-
337+
$this->setData('Breadcrumbs', $this->buildBreadcrumbs(val('CategoryID', $category)));
349338

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

419-
// Add modules
420-
$this->addModule('NewDiscussionModule');
408+
if($category->DisplayAs == 'Discussions') {
409+
// Add modules
410+
$this->addModule('NewDiscussionModule');
411+
}
421412
$this->addModule('DiscussionFilterModule');
422413
// $this->addModule('CategoriesModule');
423414
$this->addModule('BookmarkedModule');
@@ -557,10 +548,7 @@ public function all($Category = '', $displayAs = '') {
557548
$this->description(c('Garden.Description', null));
558549
}
559550

560-
$ancestors = CategoryModel::getAncestors(val('CategoryID', $this->data('Category')));
561-
array_unshift ( $ancestors , self::ROOT_CATEGORY);
562-
$this->setData('Breadcrumbs', $ancestors);
563-
551+
$this->setData('Breadcrumbs', $this->buildBreadcrumbs(val('CategoryID', $this->data('Category'))));
564552

565553
// Set the category follow toggle before we load category data so that it affects the category query appropriately.
566554
$CategoryFollowToggleModule = new CategoryFollowToggleModule($this);
@@ -648,7 +636,7 @@ public function all($Category = '', $displayAs = '') {
648636
$this->setData('CategoryTree', $categoryTree);
649637

650638
// Add modules
651-
if($Category) {
639+
if($Category && $displayAs == 'Discussions') {
652640
$this->addModule('NewDiscussionModule');
653641
}
654642
$this->addModule('DiscussionFilterModule');

vanilla/applications/vanilla/controllers/class.discussioncontroller.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ public function index($DiscussionID = '', $DiscussionStub = '', $Page = '') {
125125
Gdn_Theme::section($CategoryCssClass);
126126
}
127127

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

132130
// Setup
133131
$this->title($this->Discussion->Name);

vanilla/applications/vanilla/controllers/class.postcontroller.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public function discussion($categoryUrlCode = '') {
409409
$this->fireEvent('BeforeDiscussionRender');
410410

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

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

425424
// FIX: Hide Announce options

vanilla/applications/vanilla/controllers/class.vanillacontroller.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
class VanillaController extends Gdn_Controller {
1515

16+
const ROOT_CATEGORY = ['Name' => 'Roundtables', 'Url'=>'/'];
17+
1618
/**
1719
* Include JS, CSS, and modules used by all methods.
1820
*
@@ -70,6 +72,29 @@ protected function checkPageRange(int $offset, int $totalCount) {
7072
}
7173
}
7274

75+
protected function buildBreadcrumbs($CategoryID) {
76+
$Category = CategoryModel::categories($CategoryID);
77+
$ancestors = CategoryModel::getAncestors($CategoryID);
78+
if(val('GroupID', $Category) > 0) {
79+
$temp = [];
80+
foreach ($ancestors as $id => $ancestor) {
81+
if($ancestor['GroupID'] > 0) {
82+
$temp[$ancestor['CategoryID']] = $ancestor;
83+
} else {
84+
if($ancestor['UrlCode'] == 'challenges-forums') {
85+
array_push($temp, ['Name' => 'Challenge Discussions', 'Url'=>'/groups/mine?filter=challenge']);
86+
}else if($ancestor['UrlCode'] == 'groups') {
87+
array_push($temp, ['Name' => 'Group Discussions', 'Url'=>'/groups/mine?filter=regular']);
88+
}
89+
}
90+
}
91+
return $temp;
92+
} else {
93+
array_unshift($ancestors, self::ROOT_CATEGORY);
94+
return $ancestors;
95+
}
96+
}
97+
7398
protected function log($message, $context = [], $level = Logger::DEBUG) {
7499
// if(c('Debug')) {
75100
Logger::log($level, sprintf('%s : %s',get_class($this), $message), $context);

0 commit comments

Comments
 (0)