working on category sort ordering

This commit is contained in:
John Bintz 2009-07-13 20:13:19 -04:00
parent aca8e0110d
commit ef1077b3d4
5 changed files with 103 additions and 5 deletions

View File

@ -178,6 +178,33 @@ class ComicPressAddonCore extends ComicPressAddon {
return implode("\n", $output);
}
function get_storyline_move_statuses() {
$nodes_with_statuses = array();
for ($i = 0, $il = count($this->comicpress->category_tree); $i < $il; ++$i) {
$node = $this->comicpress->category_tree[$i];
$nodes_with_statuses[$node] = array();
$parts_count = count(explode("/", $node));
foreach (array(
'0' => -1,
'1' => 1
) as $position => $direction) {
$current_node_index = $i;
$status = false;
do {
$current_node_index += $direction;
if (isset($this->comicpress->category_tree[$current_node_index])) {
$current_node = $this->comicpress->category_tree[$current_node_index];
$current_parts_count = count(explode("/", $current_node));
if ($current_parts_count == $parts_count) { $status = true; break; }
if ($current_parts_count < $parts_count) { break; }
}
} while (isset($this->comicpress->category_tree[$current_node_index]));
$nodes_with_statuses[$node][$position] = $status;
}
}
return $nodes_with_statuses;
}
function handle_update() {
if (isset($_POST['attachments'])) {
//coming from media editor

View File

@ -4,7 +4,7 @@
<input type="hidden" name="cp[_nonce]" value="<?php echo $nonce ?>" />
<table>
<tr>
<th scope="row"><?php _e('Master Comic Category', 'comicpress') ?></th>
<th scope="row" valign="top"><?php _e('Master Comic Category', 'comicpress') ?></th>
<td>
<select name="cp[comic_category_id]">
<?php echo $this->create_category_options($root_categories, $this->comicpress->comicpress_options['comic_category_id']) ?>
@ -15,23 +15,61 @@
'comic_dimensions' => __('Comic Image Dimensions', 'comicpress'),
'rss_dimensions' => __('RSS Feed Image Dimensions', 'comicpress'),
'archive_dimensions' => __('Archive Image Dimensions', 'comicpress'),
'mini_dimensions' => __('Mini Image Dimensions', 'comicpress'),
) as $field => $name) { ?>
<tr>
<th scope="row"><?php echo $name ?></th>
<th scope="row" valign="top"><?php echo $name ?></th>
<td>
<?php echo $this->create_dimension_selector('cp[' . $field . ']', $this->comicpress->comicpress_options[$field]) ?>
</td>
</tr>
<?php } ?>
<tr>
<th scope="row"><?php _e("Number of blog posts on home page") ?></th>
<th scope="row" valign="top"><?php _e("Number of blog posts on home page", 'comicpress') ?></th>
<td>
<input type="text" name="cp[blogpost_count]" value="<?php echo $this->comicpress->comicpress_options['blogpost_count'] ?>" size="3" />
</td>
</tr>
<tr>
<th scope="row" valign="top"><?php _e("Set storyline category order", 'comicpress') ?></th>
<td>
<?php
for ($i = 0, $il = count($this->comicpress->category_tree); $i < $il; ++$i) {
$node = $this->comicpress->category_tree[$i];
$parts = explode("/", $node);
$category = get_category(end($parts));
if (!empty($category)) {
?>
<div class="storyline" style="padding-left: <?php echo (count($parts) - 2) * 20 ?>px">
<strong><?php echo $category->name ?></strong>
<?php
foreach (array(
"-1" => __("Up", 'comicpress'),
"1" => __("Down", 'comicpress')
) as $direction => $label) {
$target = ($i - $direction);
if (isset($this->comicpress->category_tree[$target])) {
$target_parts = explode("/", $this->comicpress->category_tree[$target]);
if (count($target_parts) == count($parts)) {
$query = add_query_arg('cp[_nonce]', $nonce);
$query = add_query_arg('cp[category]', $category->term_id, $query);
$query = add_query_arg('cp[move_direction', $direction, $query);
?>
| <a href="<?php echo $query ?>"><?php echo $label ?></a>
<?php }
}
}
?>
</div>
<?php }
}
?>
<p><em>(categories can be modified on the Posts -> Categories page)</em></p>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Submit Changes" /></td>
<td><input type="submit" value="<?php _e("Submit Changes", 'comicpress') ?>" /></td>
</tr>
</table>
</form>

View File

@ -2,6 +2,7 @@
require_once('PHPUnit/Framework.php');
require_once(dirname(__FILE__) . '/../../../../mockpress/mockpress.php');
require_once(dirname(__FILE__) . '/../../../classes/ComicPressAddon.inc');
require_once(dirname(__FILE__) . '/../Core.inc');
class CoreTest extends PHPUnit_Framework_TestCase {
@ -171,6 +172,38 @@ class CoreTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($value, $this->core->comicpress->comicpress_options[$key]);
}
}
function testGetStorylineMoveStatuses() {
$this->core->comicpress = (object)array(
'category_tree' => array(
'0/1',
'0/1/2',
'0/1/2/3',
'0/1/2/4',
'0/1/2/5',
'0/1/6',
'0/1/6/7',
'0/1/6/8',
'0/1/9',
'0/1/9/10',
'0/1/11'
)
);
$this->assertEquals(array(
'0/1' => array(false, false),
'0/1/2' => array(false, true),
'0/1/2/3' => array(false, true),
'0/1/2/4' => array(true, true),
'0/1/2/5' => array(true, false),
'0/1/6' => array(true, true),
'0/1/6/7' => array(false, true),
'0/1/6/8' => array(true, false),
'0/1/9' => array(true, true),
'0/1/9/10' => array(false, false),
'0/1/11' => array(true, false)
), $this->core->get_storyline_move_statuses());
}
}
?>

View File

@ -9,6 +9,7 @@ class ComicPress {
'comic_dimensions' => '760x',
'rss_dimensions' => '350x',
'archive_dimensions' => '125x',
'mini_dimensions' => '100x',
'category_order' => false,
'blogpost_count' => 10
);

View File

@ -48,7 +48,6 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
}
function testNormalizeAttachmentSorting() {
update_post_meta(1, 'comic_order', '2,1')
}
}