Skip to content

Commit 0147cae

Browse files
authored
Merge pull request #220 from topcoder-platform/issues-133
Fixed announcements in a group page, Issues-216(View filter), Issues-215
2 parents 1f0979a + bae9d65 commit 0147cae

File tree

3 files changed

+536
-53
lines changed

3 files changed

+536
-53
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CategoriesController extends VanillaController {
2929
public $Category;
3030

3131
/** @var bool Value indicating if the category-following filter should be displayed when rendering a view */
32-
public $enableFollowingFilter = false;
32+
public $enableFollowingFilter = true;//false;
3333

3434

3535
/**
@@ -265,7 +265,8 @@ public function index($categoryIdentifier = '', $page = '0') {
265265
$this->log('index: $categoryIdentifier='.$categoryIdentifier, []);
266266
if ($this->CategoryModel->followingEnabled()) {
267267
// Only use the following filter on the root category level.
268-
$this->enableFollowingFilter = $categoryIdentifier === '';
268+
// Show always
269+
$this->enableFollowingFilter = true;//$categoryIdentifier === '';
269270
$this->fireEvent('EnableFollowingFilter', [
270271
'CategoryIdentifier' => $categoryIdentifier,
271272
'EnableFollowingFilter' => &$this->enableFollowingFilter
@@ -510,7 +511,7 @@ public function index($categoryIdentifier = '', $page = '0') {
510511
* @access public
511512
*/
512513
public function all($Category = '', $displayAs = '') {
513-
$this->log('all:args($Category='.$Category);
514+
$this->log('all:args($Category='.$Category.')');
514515
// Setup head.
515516
$this->Menu->highlightRoute('/discussions');
516517
if (!$this->title()) {

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

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,6 @@ public function get($offset = '0', $limit = '', $wheres = '', $additionalFields
499499
unset($wheres['Announce']);
500500
}
501501

502-
if (is_array($wheres)) {
503-
$groupWhereCondition = strtolower(val('Groups', $wheres));
504-
if ($groupWhereCondition =='all') {
505-
$groupIDs = $wheres['d.GroupID'];
506-
$this->SQL->beginWhereGroup()
507-
->where('d.GroupID is null')
508-
->orWhere('d.GroupID', $groupIDs) // Make sure that cleared conversations do not show up unless they have new messages added.
509-
->endWhereGroup();
510-
unset($wheres['Groups']);
511-
unset($wheres['d.GroupID']);
512-
}
513-
$this->SQL->where($wheres);
514-
}
515502

516503
foreach ($orderBy as $orderField => $direction) {
517504
$this->SQL->orderBy($this->addFieldPrefix($orderField), $direction);
@@ -769,16 +756,6 @@ public function getWhere($where = false, $orderFields = '', $orderDirection = ''
769756
$removeAnnouncements = true;
770757
}
771758

772-
$groupWhereCondition = strtolower(val('Groups', $where));
773-
if ($groupWhereCondition =='all') {
774-
$groupIDs = $where['d.GroupID'];
775-
$this->SQL->beginWhereGroup()
776-
->where('d.GroupID is null')
777-
->orWhere('d.GroupID', $groupIDs) // Make sure that cleared conversations do not show up unless they have new messages added.
778-
->endWhereGroup();
779-
unset($where['Groups']);
780-
unset($where['d.GroupID']);
781-
}
782759

783760
// Make sure there aren't any ambiguous discussion references.
784761
$safeWheres = [];
@@ -1163,7 +1140,9 @@ public function addArchiveWhere($sql = null) {
11631140

11641141
/**
11651142
* Gets announced discussions.
1166-
*
1143+
* Options = 'AnnouncePinLocation' = 'all' - show all announcements
1144+
* 'AnnouncePinLocation' = 'recent' - show only Announce = 1
1145+
* * 'AnnouncePinLocation' = 'category' - show only with Announce = 2
11671146
* @since 2.0.0
11681147
* @access public
11691148
*
@@ -1172,43 +1151,46 @@ public function addArchiveWhere($sql = null) {
11721151
* @param int $limit The number of records to limit the query to.
11731152
* @return object SQL result.
11741153
*/
1175-
public function getAnnouncements($wheres = '', $offset = 0, $limit = false) {
1154+
public function getAnnouncements($wheres = '', $offset = 0, $limit = false, $options = []) {
11761155

11771156
$wheres = $this->combineWheres($this->getWheres(), $wheres);
11781157
$session = Gdn::session();
11791158
if ($limit === false) {
11801159
c('Vanilla.Discussions.PerPage', 30);
11811160
}
11821161
$userID = $session->UserID > 0 ? $session->UserID : 0;
1162+
// Step 1: get a list of all announcement IDs using '$wheres' condition
1163+
// Step 2: select data from tables (discussion and others) when discussionID in the list of discussionIDs from step 1
11831164
$categoryID = val('d.CategoryID', $wheres, 0);
1184-
$groupID = val('d.GroupID', $wheres, 0);
1165+
11851166
// Get the discussion IDs of the announcements.
11861167
$cacheKey = $this->getAnnouncementCacheKey($categoryID);
1187-
if ($groupID == 0) {
1188-
$this->SQL->cache($cacheKey);
1189-
}
1168+
$this->SQL->cache($cacheKey);
11901169
$this->SQL->select('d.DiscussionID')
11911170
->from('Discussion d');
11921171

11931172
$announceOverride = false;
1173+
$announceOverrideField = false;
11941174
$whereFields = array_keys($wheres);
11951175
foreach ($whereFields as $field) {
11961176
if (stringBeginsWith($field, 'd.Announce')) {
1177+
$announceOverrideField = $field;
11971178
$announceOverride = true;
11981179
break;
11991180
}
12001181
}
12011182
if (!$announceOverride) {
1202-
if (!is_array($categoryID) && ($categoryID > 0 || $groupID > 0)) {
1183+
if (!is_array($categoryID) && ($categoryID > 0)) {
12031184
$this->SQL->where('d.Announce >', '0');
12041185
} else {
12051186
$this->SQL->where('d.Announce', 1);
12061187
}
1188+
} else {
1189+
// FIX: missing where condition
1190+
$this->SQL->where($announceOverrideField, $wheres[$announceOverrideField]);
12071191
}
12081192

1209-
if ($groupID > 0) {
1210-
$this->SQL->where('d.GroupID', $groupID);
1211-
} elseif (is_array($categoryID)) {
1193+
if (is_array($categoryID)) {
12121194
$this->SQL->whereIn('d.CategoryID', $categoryID);
12131195
} elseif ($categoryID > 0) {
12141196
$this->SQL->where('d.CategoryID', $categoryID);
@@ -1217,6 +1199,13 @@ public function getAnnouncements($wheres = '', $offset = 0, $limit = false) {
12171199
$announcementIDs = $this->SQL->get()->resultArray();
12181200
$announcementIDs = array_column($announcementIDs, 'DiscussionID');
12191201

1202+
Logger::event(
1203+
'Discussion_model',
1204+
Logger::DEBUG
1205+
,' getAnnouncements: Step 1 : gettingIDs=',
1206+
['found DiscussionIDs' => $announcementIDs]
1207+
);
1208+
12201209
// Short circuit querying when there are no announcements.
12211210
if (count($announcementIDs) == 0) {
12221211
$this->_AnnouncementIDs = $announcementIDs;
@@ -1242,13 +1231,26 @@ public function getAnnouncements($wheres = '', $offset = 0, $limit = false) {
12421231

12431232
// Add conditions passed.
12441233
$this->SQL->whereIn('d.DiscussionID', $announcementIDs);
1234+
Logger::event(
1235+
'Discussion_model',
1236+
Logger::DEBUG
1237+
,' getAnnouncements',
1238+
['found DiscussionIDs: Step2.' => $announcementIDs]
1239+
);
12451240

1246-
// If we aren't viewing announcements in a category then only show global announcements.
1247-
if (empty($wheres) || is_array($categoryID)) {
1248-
$this->SQL->where('d.Announce', 1);
1249-
} else {
1250-
$this->SQL->where('d.Announce >', 0);
1251-
}
1241+
// If we aren't viewing announcements in a category then only show global announcements.
1242+
// FIX: Announcements might be viewed from a group page. We need to return all discussions with Announce > 0
1243+
if (empty($wheres)) {
1244+
$this->SQL->where('d.Announce', 1);
1245+
} else if (is_array($categoryID)) {
1246+
if($announceOverride) {
1247+
$this->SQL->where($announceOverrideField, $wheres[$announceOverrideField]);
1248+
} else {
1249+
$this->SQL->where('d.Announce', 1);
1250+
}
1251+
} else {
1252+
$this->SQL->where('d.Announce >', 0);
1253+
}
12521254

12531255
// If we allow users to dismiss discussions, skip ones this user dismissed
12541256
if (c('Vanilla.Discussions.Dismiss', 1) && $userID) {
@@ -1593,17 +1595,6 @@ public function getCount($wheres = [], $unused = null) {
15931595
$whereOnCategories = $hasWhere && isset($wheres['d.CategoryID']);
15941596
$whereOnCategoriesOnly = $whereOnCategories && count($wheres) === 1;
15951597

1596-
$groupWhereCondition = strtolower(val('Groups', $wheres));
1597-
if ($groupWhereCondition =='all') {
1598-
$groupIDs = $wheres['d.GroupID'];
1599-
$this->SQL->beginWhereGroup()
1600-
->where('d.GroupID is null')
1601-
->orWhere('d.GroupID', $groupIDs) // Make sure that cleared conversations do not show up unless they have new messages added.
1602-
->endWhereGroup();
1603-
unset($wheres['Groups']);
1604-
unset($wheres['d.GroupID']);
1605-
}
1606-
16071598
// We have access to everything and are requesting only by categories. Let's use the cache!
16081599
if ($perms === true && $whereOnCategoriesOnly) {
16091600
return $this->getCountForCategory($wheres['d.CategoryID']);

0 commit comments

Comments
 (0)