Skip to content

Commit d9746e5

Browse files
authored
Merge pull request #596 from topcoder-platform/issues-563
Issues-563: Updated breadcrumbs, Issues-593
2 parents 7c08db0 + c3a9d0a commit d9746e5

File tree

5 files changed

+100
-25
lines changed

5 files changed

+100
-25
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,9 @@ public function all($Category = '', $displayAs = '') {
689689
$this->addModule('BookmarkedModule');
690690
// FIX: https://github.com/topcoder-platform/forums/issues/548
691691
// Show only for 'Public forums'
692-
$isGroupCategory = val('GroupID',$this->data('Category'));
693-
if(gdn::session()->isValid() && $this->data('Category') && !$isGroupCategory) {
692+
$categoryID = val('CategoryID',$this->data('Category'));
693+
$isChallengeForums = $this->checkChallengeForums($categoryID);
694+
if(gdn::session()->isValid() && $this->data('Category') && !$isChallengeForums) {
694695
$this->addModule('CategoriesModule');
695696
}
696697

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,58 @@ protected function checkPageRange(int $offset, int $totalCount) {
7272
}
7373
}
7474

75+
public function checkChallengeForums($CategoryID) {
76+
$Category = CategoryModel::categories($CategoryID);
77+
$ancestors = CategoryModel::getAncestors($CategoryID);
78+
if(val('GroupID', $Category) > 0) {
79+
return true;
80+
}
81+
82+
foreach ($ancestors as $id => $ancestor) {
83+
if($ancestor['UrlCode'] == self::CHALLENGE_FORUMS_URLCODE) {
84+
return true;
85+
}
86+
if($ancestor['GroupID'] > 0) {
87+
return true;
88+
}
89+
}
90+
91+
return false;
92+
}
93+
7594
protected function buildBreadcrumbs($CategoryID) {
7695
$Category = CategoryModel::categories($CategoryID);
7796
$ancestors = CategoryModel::getAncestors($CategoryID);
7897
$parentCategoryID = val('ParentCategoryID', $Category);
7998
if(val('GroupID', $Category) > 0) {
99+
$challenge = $this->data('Challenge');
100+
$track = $challenge ? $challenge['Track']: false;
80101
$temp = [];
102+
$GroupCategoryID = $this->data('Breadcrumbs.Options.GroupCategoryID');
81103
foreach ($ancestors as $id => $ancestor) {
82104
if($ancestor['GroupID'] > 0) {
83-
$temp[$ancestor['CategoryID']] = $ancestor;
105+
if($GroupCategoryID == $ancestor['CategoryID']) {// root category for a group
106+
array_push($temp, ['Name' => $ancestor['Name'], 'Url'=>'/group/'.$ancestor['GroupID']]);
107+
} else {
108+
$temp[$ancestor['CategoryID']] = $ancestor;
109+
}
84110
} else {
85111
if($ancestor['UrlCode'] == self::CHALLENGE_FORUMS_URLCODE) {
86112
array_push($temp, ['Name' => 'Challenge Forums', 'Url'=>'/groups/mine?filter=challenge']);
87113
}else if($ancestor['UrlCode'] == 'groups') {
88114
array_push($temp, ['Name' => 'Group Forums', 'Url'=>'/groups/mine?filter=regular']);
115+
} else {
116+
if($track) {
117+
switch ($ancestor['UrlCode']) {
118+
case 'development-forums':
119+
case 'data-science-forums':
120+
case 'design-forums':
121+
array_push($temp, ['Name' => $track, 'Url'=>'/groups/mine?filter=challenge']);
122+
break;
123+
default:
124+
$temp[$ancestor['CategoryID']] = $ancestor;
125+
}
126+
}
89127
}
90128
}
91129
}

vanilla/applications/vanilla/models/class.commentmodel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ public function recordAdvancedNotications($activityModel, $activity, $discussion
14351435

14361436
$userID = $row['UserID'];
14371437

1438-
if (in_array($userID, $removeUserIDs)) {
1438+
if ($row['Value'] == '2' && in_array($userID, $removeUserIDs)) {
14391439
continue;
14401440
}
14411441

vanilla/applications/vanilla/models/class.discussionmodel.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,6 +2890,40 @@ public function bookmark($discussionID, $userID, $bookmarked = null) {
28902890
return (int)$bookmarked;
28912891
}
28922892

2893+
/**
2894+
* Bookmarks (or unbookmarks) all discussions in a category for the specified user.
2895+
*
2896+
* @param int|array $CategoryID The id of the category.
2897+
* @param int $userID The unique id of the user.
2898+
* @param bool|null $bookmarked Whether or not to bookmark or unbookmark. Pass null to toggle the bookmark.
2899+
*/
2900+
public function bookmarkAll($categoryID, $userID, $bookmarked) {
2901+
2902+
if(is_numeric($categoryID)) {
2903+
$categoryID = [$categoryID];
2904+
}
2905+
$discussions = $this->SQL
2906+
->select('ud.DiscussionID')
2907+
->from('UserDiscussion ud')
2908+
->join('Discussion d', 'ud.DiscussionID = d.DiscussionID ')
2909+
->join('Category c', 'd.CategoryID = c.CategoryID')
2910+
->where('ud.UserID', $userID)
2911+
->where('c.CategoryID', $categoryID)
2912+
->get()->resultArray();
2913+
$discussionIDs = array_column($discussions, 'DiscussionID');
2914+
if(count($discussionIDs) > 0 ) {
2915+
// Update the bookmarked value.
2916+
$this->SQL
2917+
->update('UserDiscussion')
2918+
->set('Bookmarked', $bookmarked)
2919+
->where('UserID', $userID)
2920+
->where('DiscussionID', $discussionIDs)
2921+
->put();
2922+
2923+
$this->setUserBookmarkCount($userID);
2924+
}
2925+
}
2926+
28932927
/**
28942928
* Bookmarks (or unbookmarks) a discussion for specified user.
28952929
*

vanilla/applications/vanilla/views/discussions/helper_functions.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,35 @@ function bookmarkButton($discussion) {
9191
);
9292
} else {
9393
$notificationPreferences = $categoryModel->getCategoryNotificationPreferences($discussion->CategoryID, Gdn::session()->UserID);
94-
9594
$categoryNotificationPreferences = $notificationPreferences[$discussion->CategoryID];
96-
$newEmailDiscussionKey = 'Preferences.Email.NewDiscussion.' . $discussion->CategoryID;
95+
$newEmailDiscussionKey = 'Preferences.Email.NewComment.' . $discussion->CategoryID;
96+
//$newPopupDiscussionKey = 'Preferences.Popup.NewComment.' . $discussion->CategoryID;
9797
$hasWatchedCategory = val($newEmailDiscussionKey, $categoryNotificationPreferences);
9898

99-
$hasWatched = false;
100-
// Author is added by default with Bookmarked = 0, Participated = 1
101-
$isAuthor = ($discussion->InsertUserID == Gdn::session()->UserID);
102-
103-
// If Watched Category: unwatched discussion
104-
if ($discussion->Bookmarked === null) {
105-
$hasWatched = $hasWatchedCategory == '1' || $hasWatchedCategory == '2' ? true: false;
106-
$newValue = $hasWatched ? 0 : 1;
107-
} else if ($discussion->Bookmarked == 0) {
108-
$hasWatched = false;
109-
if ($isAuthor) {
110-
$hasWatched = $hasWatchedCategory == '1' || $hasWatchedCategory == '2'? true: false;
111-
$newValue = 2;
112-
} else {
99+
if($hasWatchedCategory == '1') { // The watched category
100+
$hasWatched = true;
101+
$newValue = 0;
102+
} else if($hasWatchedCategory == '2') {// The watched category except some discussions
103+
if ($discussion->Bookmarked === null) {
104+
$hasWatched = true;
105+
$newValue = 0;
106+
} else if ($discussion->Bookmarked == 0) {
107+
$hasWatched = false;
113108
$newValue = 1;
109+
} else if ($discussion->Bookmarked == 1) {
110+
$hasWatched = true;
111+
$newValue = 0;
114112
}
115-
} else if ($discussion->Bookmarked == 1) {
116-
$hasWatched = true;
117-
$newValue = $isAuthor ? 2 : 0;
118-
} else if ($discussion->Bookmarked == 2) {
113+
} else {
119114
$hasWatched = false;
120-
$newValue = 1;
115+
if ($discussion->Bookmarked === null) {
116+
$newValue = 1;
117+
} else if ($discussion->Bookmarked == 0) {
118+
$newValue = 1;
119+
} else if ($discussion->Bookmarked == 1) {
120+
$hasWatched = true;
121+
$newValue = 0;
122+
}
121123
}
122124

123125
$title = t($hasWatched ? 'Stop watching the discussion' : 'Watch the discussion');

0 commit comments

Comments
 (0)