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.
*/
function get_terminal_post_in_category($category_id, $first = true) {
global $wp_query;
$temp = $wp_query; $wp_query = null;
$sort_order = $first ? "asc" : "desc";
$terminal_comic_query = new WP_Query();

View File

@ -34,9 +34,17 @@ class ComicPressNavigation {
if (is_array($valid = $this->_storyline->valid($category))) {
foreach ($valid as $field) {
$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

@ -18,9 +18,9 @@ class ComicPressStoryline {
$adjacents_by_parent = array();
if (is_string($structure)) {
$structure = explode(',', $structure);
}
if (is_string($structure)) {
$structure = explode(',', $structure);
}
if (is_array($structure)) {
$is_valid = true;
@ -65,7 +65,7 @@ class ComicPressStoryline {
}
}
}
$this->_structure = $new_structure;
}
}
@ -83,12 +83,13 @@ class ComicPressStoryline {
return false;
}
function current($id) { return $id; }
function parent($id) { return $this->_get_field('parent', $id); }
function previous($id) { return $this->_get_field('previous', $id); }
function next($id) { return $this->_get_field('next', $id); }
function valid($id) {
if (isset($this->_structure[$id])) {
return array_keys($this->_structure[$id]);
return array_merge(array_keys($this->_structure[$id]), array('current'));
}
return false;
}

View File

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