refactor storyline code some more
This commit is contained in:
parent
2517034936
commit
8b63f3a1fd
@ -199,7 +199,6 @@ class ComicPressComicPost {
|
||||
|
||||
update_post_meta($this->post->ID, 'comic_ordering', $new_order);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,37 +1,7 @@
|
||||
<?php
|
||||
|
||||
class ComicPressNavigation {
|
||||
function init($post, $storyline) {
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once('ComicPressDBInterface.inc');
|
||||
|
||||
class ComicPressStoryline {
|
||||
var $_structure;
|
||||
|
||||
@ -96,17 +98,30 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user