diff --git a/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc index b10f7d1..7b3c74d 100644 --- a/classes/ComicPressComicPost.inc +++ b/classes/ComicPressComicPost.inc @@ -187,9 +187,9 @@ class ComicPressComicPost { sort($ids); $requested_order = array_merge($requested_order, $ids); } - + $requested_order = array_merge($requested_order, array_diff($current_order, $requested_order)); - + foreach ($requested_order as $requested_comic) { if (in_array($requested_comic, $current_order)) { $new_order[$type][] = $requested_comic; @@ -199,7 +199,6 @@ class ComicPressComicPost { update_post_meta($this->post->ID, 'comic_ordering', $new_order); } - } ?> \ No newline at end of file diff --git a/classes/ComicPressNavigation.inc b/classes/ComicPressNavigation.inc index 34a6c91..9f14b39 100644 --- a/classes/ComicPressNavigation.inc +++ b/classes/ComicPressNavigation.inc @@ -1,37 +1,7 @@ post = $post; - $this->storyline = $storyline; - } - - /** - * Find the terminal post in a specific category. - */ - function get_terminal_post_in_category($category_id, $first = true) { - $sort_order = $first ? "asc" : "desc"; - $terminal_comic_query = new WP_Query(); - $terminal_comic_query->query("showposts=1&order=${sort_order}&cat=${category_id}&status=publish"); - if ($terminal_comic_query->have_posts()) { - return reset($terminal_comic_query->posts); - } - return false; - } - - /** - * Get the first comic in a category. - */ - function get_first_in_category($category_id) { - return $this->get_terminal_post_in_category($category_id); - } - - /** - * Get the last comic in a category. - */ - function get_last_in_category($category_id) { - return $this->get_terminal_post_in_category($category_id, false); - } + } ?> \ No newline at end of file diff --git a/classes/ComicPressStoryline.inc b/classes/ComicPressStoryline.inc index 513989d..f6e1c83 100644 --- a/classes/ComicPressStoryline.inc +++ b/classes/ComicPressStoryline.inc @@ -1,5 +1,7 @@ _structure); } - + function _get_field($field, $id) { if (isset($this->_structure)) { if (isset($this->_structure[$id])) { @@ -96,18 +98,31 @@ class ComicPressStoryline { return false; } + /** + * Get the valid navigation directions for a particular post. + */ function get_valid_nav($post_id) { - $data = false; + if (($category = $this->get_valid_post_category($post_id)) !== false) { + return $this->valid($category); + } + return false; + } + /** + * Get the valid comic category for this post. + */ + function get_valid_post_category($post_id) { + $result = false; + foreach (wp_get_post_categories($post_id) as $category) { - if ($result = $this->valid($category)) { - if ($data) { return false; } + if ($this->valid($category)) { + if ($result) { return false; } - $data = $result; + $result = $category; } } - return $data; - } + return $result; + } } ?> \ No newline at end of file diff --git a/test/ComicPressStorylineTest.php b/test/ComicPressStorylineTest.php index 51a06a2..52d2d38 100644 --- a/test/ComicPressStorylineTest.php +++ b/test/ComicPressStorylineTest.php @@ -134,6 +134,26 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected_navigation, $this->css->get_valid_nav(1)); } + + function providerTestGetValidPostCategory() { + return array( + array(array(1,2), false), + array(array(1,3), false), + array(array(1), 1), + ); + } + + /** + * @dataProvider providerTestGetValidPostCategory + */ + function testGetValidPostCategory($post_categories, $expected_result) { + $css = $this->getMock('ComicPressStoryline', array('valid')); + $css->expects($this->any())->method('valid')->will($this->returnValue(true)); + + wp_set_post_categories(1, $post_categories); + + $this->assertEquals($expected_result, $css->get_valid_post_category(1)); + } } ?> \ No newline at end of file