Skip to content
This repository was archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
Updating the media holder filters to support categories.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Glasl committed Mar 23, 2015
1 parent 4de5af6 commit 36e82bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
32 changes: 28 additions & 4 deletions code/pages/MediaHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down Expand Up @@ -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'
)
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion templates/Layout/MediaPage.ss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<% if $Categories %>
<h3 class='media-page-categories'>
<% loop $Categories %>
<span><a href='{$Up.getParent.Link}?tag={$Title.URLATT}'>{$Title}</a></span>
<span><a href='{$Up.getParent.Link}?category={$Title.URLATT}'>{$Title}</a></span>
<% end_loop %>
</h3>
<% end_if %>
Expand Down

0 comments on commit 36e82bf

Please sign in to comment.