previous next categories finding worked out

This commit is contained in:
John Bintz 2009-07-27 20:16:40 -04:00
parent abcfc8ca2d
commit 9f963e1fbd
2 changed files with 42 additions and 4 deletions

View File

@ -380,11 +380,34 @@ class ComicPress {
function get_previous_next_categories($category_id) {
$prev_next_categories = array();
for ($i = 0, $il < count($this->category_tree); $i < $il; ++$i) {
$parts = explode("/", $this->category_tree);
for ($i = 0, $il = count($this->category_tree); $i < $il; ++$i) {
$parts = explode("/", $this->category_tree[$i]);
if (count($parts) > 2) {
if (end($parts) == $category_id) {
while (count($parts) > 2) {
foreach (array(
'previous' => -1,
'next' => 1
) as $key => $direction) {
$index = $i;
while (isset($this->category_tree[$index])) {
$index += $direction;
if (isset($this->category_tree[$index])) {
$compare_parts = explode("/", $this->category_tree[$index]);
if (count($compare_parts) == count($parts)) {
$target_category = array_pop($compare_parts);
$parent_category = array_pop($compare_parts);
if (!isset($prev_next_categories[$parent_category])) {
$prev_next_categories[$parent_category] = array();
}
$prev_next_categories[$parent_category][$key] = $target_category;
}
}
}
}
array_pop($parts);
}
}
}
}

View File

@ -200,6 +200,21 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
'1' => array('next' => 3)
)
),
array(
array(
'0/1',
'0/1/6',
'0/1/2',
'0/1/2/4',
'0/1/2/5',
'0/1/3',
),
5,
array(
'2' => array('previous' => 4),
'1' => array('previous' => 6, 'next' => 3),
)
),
);
}