add current storyline helper method

This commit is contained in:
John Bintz 2009-10-22 06:56:53 -04:00
parent 705a38595a
commit 4f40c2457c
4 changed files with 21 additions and 10 deletions

View File

@ -30,6 +30,8 @@ class ComicPressDBInterface {
* Find the terminal post in a specific category. * Find the terminal post in a specific category.
*/ */
function get_terminal_post_in_category($category_id, $first = true) { function get_terminal_post_in_category($category_id, $first = true) {
global $wp_query;
$temp = $wp_query; $wp_query = null; $temp = $wp_query; $wp_query = null;
$sort_order = $first ? "asc" : "desc"; $sort_order = $first ? "asc" : "desc";
$terminal_comic_query = new WP_Query(); $terminal_comic_query = new WP_Query();

View File

@ -34,10 +34,18 @@ class ComicPressNavigation {
if (is_array($valid = $this->_storyline->valid($category))) { if (is_array($valid = $this->_storyline->valid($category))) {
foreach ($valid as $field) { foreach ($valid as $field) {
$nav["storyline-chapter-${field}"] = $this->_dbi->get_first_comic($this->_storyline->{$field}($category)); $nav["storyline-chapter-${field}"] = $this->_dbi->get_first_comic($this->_storyline->{$field}($category));
if ($field == "previous") {
if ($post->ID != $nav['storyline-chapter-current']) {
$nav['storyline-chapter-previous'] = $nav['storyline-chapter-current'];
} }
} }
} }
} }
} }
return $nav;
}
}
?> ?>

View File

@ -83,12 +83,13 @@ class ComicPressStoryline {
return false; return false;
} }
function current($id) { return $id; }
function parent($id) { return $this->_get_field('parent', $id); } function parent($id) { return $this->_get_field('parent', $id); }
function previous($id) { return $this->_get_field('previous', $id); } function previous($id) { return $this->_get_field('previous', $id); }
function next($id) { return $this->_get_field('next', $id); } function next($id) { return $this->_get_field('next', $id); }
function valid($id) { function valid($id) {
if (isset($this->_structure[$id])) { if (isset($this->_structure[$id])) {
return array_keys($this->_structure[$id]); return array_merge(array_keys($this->_structure[$id]), array('current'));
} }
return false; return false;
} }

View File

@ -96,7 +96,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
array('parent', 2, 1), array('parent', 2, 1),
array('next', 2, 3), array('next', 2, 3),
array('next', 3, 4), array('next', 3, 4),
array('valid', 1, array('next')), array('valid', 1, array('next', 'current')),
array('valid', 6, false), array('valid', 6, false),
); );
} }
@ -117,11 +117,11 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
function providerTestGetValidNav() { function providerTestGetValidNav() {
return array( return array(
array(array(1), array('next')), array(array(1), array('next', 'current')),
array(array(1,2), false), array(array(1,2), false),
array(array(1,4), array('next')), array(array(1,4), array('next', 'current')),
array(array(2), array('previous', 'next')), array(array(2), array('previous', 'next', 'current')),
array(array(3), array('previous')), array(array(3), array('previous', 'current')),
); );
} }