From 36e82bf6de80e8d2cc6819def86cdde962d7247c Mon Sep 17 00:00:00 2001 From: Nathan Glasl Date: Mon, 23 Mar 2015 16:49:22 +1100 Subject: [PATCH] Updating the media holder filters to support categories. --- code/pages/MediaHolder.php | 32 ++++++++++++++++++++++++++++---- templates/Layout/MediaPage.ss | 2 +- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/code/pages/MediaHolder.php b/code/pages/MediaHolder.php index 51969a7..9f699ef 100644 --- a/code/pages/MediaHolder.php +++ b/code/pages/MediaHolder.php @@ -134,6 +134,7 @@ public function getPaginatedChildren($limit = 5, $sort = 'Date', $order = 'DESC' $order = $orderVar; } $from = $this->getRequest()->getVar('from'); + $category = $this->getRequest()->getVar('category'); $tag = $this->getRequest()->getVar('tag'); // Apply custom request filters to media page children. @@ -142,6 +143,9 @@ public function getPaginatedChildren($limit = 5, $sort = 'Date', $order = 'DESC' if($from) { $children = $children->where("Date >= '" . Convert::raw2sql("{$from} 00:00:00") . "'"); } + if($category) { + $children = $children->filter('Categories.Title:ExactMatch', $category); + } if($tag) { $children = $children->filter('Tags.Title:ExactMatch', $tag); } @@ -192,6 +196,9 @@ public function getDateFilterForm() { 'from', '' )->setConfig('showcalendar', true)->setConfig('min', $children->min('Date'))->setConfig('max', $children->max('Date'))->setAttribute('placeholder', 'From'), + HiddenField::create( + 'category' + ), HiddenField::create( 'tag' ) @@ -234,7 +241,6 @@ public function dateFilter() { // Apply the from date filter. $from = $this->getRequest()->getVar('from'); - $tag = $this->getRequest()->getVar('tag'); $link = $this->AbsoluteLink(); $separator = '?'; if($from) { @@ -243,8 +249,14 @@ public function dateFilter() { $separator = '&'; } - // Preserve the tag filter if one exists. + // Preserve the category/tag filters if they exist. + $category = $this->getRequest()->getVar('category'); + $tag = $this->getRequest()->getVar('tag'); + if($category) { + $link = HTTP::setGetVar('category', $category, $link, $separator); + $separator = '&'; + } if($tag) { $link = HTTP::setGetVar('tag', $tag, $link, $separator); } @@ -264,10 +276,22 @@ public function dateFilter() { public function clearFilter() { - // Clear the from date filter, and preserve the tag filter if one exists. + // Clear the from date filter. + + $link = $this->AbsoluteLink(); + $separator = '?'; + // Preserve the category/tag filters if they exist. + + $category = $this->getRequest()->getVar('category'); $tag = $this->getRequest()->getVar('tag'); - $link = $tag ? HTTP::setGetVar('tag', $tag, $this->AbsoluteLink(), '?') : $this->AbsoluteLink(); + if($category) { + $link = HTTP::setGetVar('category', $category, $link, $separator); + $separator = '&'; + } + if($tag) { + $link = HTTP::setGetVar('tag', $tag, $link, $separator); + } // Request the paginated children. diff --git a/templates/Layout/MediaPage.ss b/templates/Layout/MediaPage.ss index 4513506..caa7931 100644 --- a/templates/Layout/MediaPage.ss +++ b/templates/Layout/MediaPage.ss @@ -8,7 +8,7 @@ <% if $Categories %>

<% loop $Categories %> - {$Title} + {$Title} <% end_loop %>

<% end_if %>