From ab2aa9ed8e5cd88ce64f3abd31f989788461cf7e Mon Sep 17 00:00:00 2001 From: Todd Burry Date: Fri, 30 Sep 2011 15:32:40 -0400 Subject: [PATCH] Added the ability to include announcements in the /categories/discussions page. --- .../controllers/class.categoriescontroller.php | 2 +- .../vanilla/models/class.discussionmodel.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/applications/vanilla/controllers/class.categoriescontroller.php b/applications/vanilla/controllers/class.categoriescontroller.php index a2a21626464..afd6961c5fa 100755 --- a/applications/vanilla/controllers/class.categoriescontroller.php +++ b/applications/vanilla/controllers/class.categoriescontroller.php @@ -223,7 +223,7 @@ public function Discussions() { $this->CategoryDiscussionData = array(); foreach ($this->CategoryData->Result() as $Category) { if ($Category->CategoryID > 0) - $this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->Get(0, $this->DiscussionsPerCategory, array('d.CategoryID' => $Category->CategoryID, 'd.Announce' => 0)); + $this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->Get(0, $this->DiscussionsPerCategory, array('d.CategoryID' => $Category->CategoryID, 'Announce' => 'all')); } // Add modules diff --git a/applications/vanilla/models/class.discussionmodel.php b/applications/vanilla/models/class.discussionmodel.php index 16252371db5..f9a12d7b0cd 100644 --- a/applications/vanilla/models/class.discussionmodel.php +++ b/applications/vanilla/models/class.discussionmodel.php @@ -162,6 +162,12 @@ public function Get($Offset = '0', $Limit = '', $Wheres = '', $AdditionalFields $this->EventArguments['SortDirection'] = C('Vanilla.Discussions.SortDirection', 'desc'); $this->EventArguments['Wheres'] = &$Wheres; $this->FireEvent('BeforeGet'); // @see 'BeforeGetCount' for consistency in results vs. counts + + $IncludeAnnouncements = FALSE; + if (strtolower(GetValue('Announce', $Wheres)) == 'all') { + $IncludeAnnouncements = TRUE; + unset($Wheres['Announce']); + } if (is_array($Wheres)) $this->SQL->Where($Wheres); @@ -181,8 +187,10 @@ public function Get($Offset = '0', $Limit = '', $Wheres = '', $AdditionalFields $Data = $this->SQL->Get(); // If not looking at discussions filtered by bookmarks or user, filter announcements out. - if (!isset($Wheres['w.Bookmarked']) && !isset($Wheres['d.InsertUserID'])) - $this->RemoveAnnouncements($Data); + if (!$IncludeAnnouncements) { + if (!isset($Wheres['w.Bookmarked']) && !isset($Wheres['d.InsertUserID'])) + $this->RemoveAnnouncements($Data); + } // Change discussions returned based on additional criteria $this->AddDiscussionColumns($Data);