change comic ordering to normalizing function
This commit is contained in:
parent
0d8b995764
commit
350fae9aa8
@ -103,7 +103,7 @@ class ComicPressComicPost {
|
|||||||
return $orderings;
|
return $orderings;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_comic_image_ordering($post_id) {
|
function normalize_comic_image_ordering($post_id) {
|
||||||
if (is_array($this->get_comic_image_attachments())) {
|
if (is_array($this->get_comic_image_attachments())) {
|
||||||
$ordering_by_type = array();
|
$ordering_by_type = array();
|
||||||
$ordering_types = get_post_meta($post_id, 'comic_ordering', true);
|
$ordering_types = get_post_meta($post_id, 'comic_ordering', true);
|
||||||
@ -114,12 +114,12 @@ class ComicPressComicPost {
|
|||||||
if (!empty($ordering_types)) {
|
if (!empty($ordering_types)) {
|
||||||
foreach ($ordering_types as $type => $post_ids) {
|
foreach ($ordering_types as $type => $post_ids) {
|
||||||
$comic_image_ordering[$type] = array();
|
$comic_image_ordering[$type] = array();
|
||||||
foreach ($post_ids as $post_id) {
|
foreach ($post_ids as $ordering_post_id) {
|
||||||
foreach ($this->get_comic_image_attachments() as $attachment) {
|
foreach ($this->get_comic_image_attachments() as $attachment) {
|
||||||
if (!isset($found_post_ids[$attachment->ID])) {
|
if (!isset($found_post_ids[$attachment->ID])) {
|
||||||
if ($attachment->ID == $post_id) {
|
if ($attachment->ID == $ordering_post_id) {
|
||||||
$comic_image_ordering[$type][] = $attachment->ID;
|
$comic_image_ordering[$type][] = $attachment->ID;
|
||||||
$found_post_ids[$post_id] = true;
|
$found_post_ids[$ordering_post_id] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,7 +145,16 @@ class ComicPressComicPost {
|
|||||||
usort($remaining_posts_to_sort[$type], array(&$this, 'sort_remaining_comic_images'));
|
usort($remaining_posts_to_sort[$type], array(&$this, 'sort_remaining_comic_images'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_merge($comic_image_ordering, $remaining_posts_to_sort);
|
$result = array_merge($comic_image_ordering, $remaining_posts_to_sort);
|
||||||
|
$result_string_parts = array();
|
||||||
|
|
||||||
|
foreach ($result as $key => $values) {
|
||||||
|
$result_string_parts[] = "${key}:" . implode(",", $values);
|
||||||
|
}
|
||||||
|
sort($result_string_parts);
|
||||||
|
|
||||||
|
update_post_meta($post_id, 'comic_ordering', implode(";", $result_string_parts));
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals($expected_result, $this->p->breakdown_comic_ordering_string($string));
|
$this->assertEquals($expected_result, $this->p->breakdown_comic_ordering_string($string));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetComicImageOrdering() {
|
function testNormalizeComicImageOrdering() {
|
||||||
$p = $this->getMock('ComicPressComicPost', array('get_comic_image_attachments'));
|
$p = $this->getMock('ComicPressComicPost', array('get_comic_image_attachments'));
|
||||||
|
|
||||||
$comic_attachments = array(
|
$comic_attachments = array(
|
||||||
@ -153,9 +153,10 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
|
|||||||
wp_insert_post((object)array('ID' => 1));
|
wp_insert_post((object)array('ID' => 1));
|
||||||
update_post_meta(1, 'comic_ordering', "comic:3,2");
|
update_post_meta(1, 'comic_ordering', "comic:3,2");
|
||||||
|
|
||||||
$result = $p->get_comic_image_ordering(1);
|
$result = $p->normalize_comic_image_ordering(1);
|
||||||
|
|
||||||
$this->assertEquals(array('comic' => array(3,2), 'rss' => array(5,4)), $result);
|
$this->assertEquals(array('comic' => array(3,2), 'rss' => array(5,4)), $result);
|
||||||
|
$this->assertEquals('comic:3,2;rss:5,4', get_post_meta(1, 'comic_ordering', true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user