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 @@ -29,7 +29,7 @@ class CategoriesController extends VanillaController {
public $Category;

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


/**
Expand Down Expand Up @@ -265,7 +265,8 @@ public function index($categoryIdentifier = '', $page = '0') {
$this->log('index: $categoryIdentifier='.$categoryIdentifier, []);
if ($this->CategoryModel->followingEnabled()) {
// Only use the following filter on the root category level.
$this->enableFollowingFilter = $categoryIdentifier === '';
// Show always
$this->enableFollowingFilter = true;//$categoryIdentifier === '';
$this->fireEvent('EnableFollowingFilter', [
'CategoryIdentifier' => $categoryIdentifier,
'EnableFollowingFilter' => &$this->enableFollowingFilter
Expand Down Expand Up @@ -510,7 +511,7 @@ public function index($categoryIdentifier = '', $page = '0') {
* @access public
*/
public function all($Category = '', $displayAs = '') {
$this->log('all:args($Category='.$Category);
$this->log('all:args($Category='.$Category.')');
// Setup head.
$this->Menu->highlightRoute('/discussions');
if (!$this->title()) {
Expand Down
91 changes: 41 additions & 50 deletions vanilla/applications/vanilla/models/class.discussionmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,19 +499,6 @@ public function get($offset = '0', $limit = '', $wheres = '', $additionalFields
unset($wheres['Announce']);
}

if (is_array($wheres)) {
$groupWhereCondition = strtolower(val('Groups', $wheres));
if ($groupWhereCondition =='all') {
$groupIDs = $wheres['d.GroupID'];
$this->SQL->beginWhereGroup()
->where('d.GroupID is null')
->orWhere('d.GroupID', $groupIDs) // Make sure that cleared conversations do not show up unless they have new messages added.
->endWhereGroup();
unset($wheres['Groups']);
unset($wheres['d.GroupID']);
}
$this->SQL->where($wheres);
}

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

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

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

/**
* Gets announced discussions.
*
* Options = 'AnnouncePinLocation' = 'all' - show all announcements
* 'AnnouncePinLocation' = 'recent' - show only Announce = 1
* * 'AnnouncePinLocation' = 'category' - show only with Announce = 2
* @since 2.0.0
* @access public
*
Expand All @@ -1172,43 +1151,46 @@ public function addArchiveWhere($sql = null) {
* @param int $limit The number of records to limit the query to.
* @return object SQL result.
*/
public function getAnnouncements($wheres = '', $offset = 0, $limit = false) {
public function getAnnouncements($wheres = '', $offset = 0, $limit = false, $options = []) {

$wheres = $this->combineWheres($this->getWheres(), $wheres);
$session = Gdn::session();
if ($limit === false) {
c('Vanilla.Discussions.PerPage', 30);
}
$userID = $session->UserID > 0 ? $session->UserID : 0;
// Step 1: get a list of all announcement IDs using '$wheres' condition
// Step 2: select data from tables (discussion and others) when discussionID in the list of discussionIDs from step 1
$categoryID = val('d.CategoryID', $wheres, 0);
$groupID = val('d.GroupID', $wheres, 0);

// Get the discussion IDs of the announcements.
$cacheKey = $this->getAnnouncementCacheKey($categoryID);
if ($groupID == 0) {
$this->SQL->cache($cacheKey);
}
$this->SQL->cache($cacheKey);
$this->SQL->select('d.DiscussionID')
->from('Discussion d');

$announceOverride = false;
$announceOverrideField = false;
$whereFields = array_keys($wheres);
foreach ($whereFields as $field) {
if (stringBeginsWith($field, 'd.Announce')) {
$announceOverrideField = $field;
$announceOverride = true;
break;
}
}
if (!$announceOverride) {
if (!is_array($categoryID) && ($categoryID > 0 || $groupID > 0)) {
if (!is_array($categoryID) && ($categoryID > 0)) {
$this->SQL->where('d.Announce >', '0');
} else {
$this->SQL->where('d.Announce', 1);
}
} else {
// FIX: missing where condition
$this->SQL->where($announceOverrideField, $wheres[$announceOverrideField]);
}

if ($groupID > 0) {
$this->SQL->where('d.GroupID', $groupID);
} elseif (is_array($categoryID)) {
if (is_array($categoryID)) {
$this->SQL->whereIn('d.CategoryID', $categoryID);
} elseif ($categoryID > 0) {
$this->SQL->where('d.CategoryID', $categoryID);
Expand All @@ -1217,6 +1199,13 @@ public function getAnnouncements($wheres = '', $offset = 0, $limit = false) {
$announcementIDs = $this->SQL->get()->resultArray();
$announcementIDs = array_column($announcementIDs, 'DiscussionID');

Logger::event(
'Discussion_model',
Logger::DEBUG
,' getAnnouncements: Step 1 : gettingIDs=',
['found DiscussionIDs' => $announcementIDs]
);

// Short circuit querying when there are no announcements.
if (count($announcementIDs) == 0) {
$this->_AnnouncementIDs = $announcementIDs;
Expand All @@ -1242,13 +1231,26 @@ public function getAnnouncements($wheres = '', $offset = 0, $limit = false) {

// Add conditions passed.
$this->SQL->whereIn('d.DiscussionID', $announcementIDs);
Logger::event(
'Discussion_model',
Logger::DEBUG
,' getAnnouncements',
['found DiscussionIDs: Step2.' => $announcementIDs]
);

// If we aren't viewing announcements in a category then only show global announcements.
if (empty($wheres) || is_array($categoryID)) {
$this->SQL->where('d.Announce', 1);
} else {
$this->SQL->where('d.Announce >', 0);
}
// If we aren't viewing announcements in a category then only show global announcements.
// FIX: Announcements might be viewed from a group page. We need to return all discussions with Announce > 0
if (empty($wheres)) {
$this->SQL->where('d.Announce', 1);
} else if (is_array($categoryID)) {
if($announceOverride) {
$this->SQL->where($announceOverrideField, $wheres[$announceOverrideField]);
} else {
$this->SQL->where('d.Announce', 1);
}
} else {
$this->SQL->where('d.Announce >', 0);
}

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

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

// We have access to everything and are requesting only by categories. Let's use the cache!
if ($perms === true && $whereOnCategoriesOnly) {
return $this->getCountForCategory($wheres['d.CategoryID']);
Expand Down
Loading