previous next categories finding worked out
This commit is contained in:
parent
abcfc8ca2d
commit
9f963e1fbd
@ -379,12 +379,35 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user