Пример #1
0
 function test_adding_node()
 {
     $n = new Navigation();
     $blog_node = (object) array('data' => 'Blog', 'attr' => (object) array('id' => 'blog', 'sort' => 0));
     /**
      * Add blog page.
      */
     $n->add($blog_node, 'index');
     /**
      * Should have second id now:
      *
      * index
      * - blog
      */
     $this->assertEquals($n->get_all_ids(), array('index', 'blog'));
     // Remove and re-add index
     $n->remove('index');
     $this->assertEquals($n->get_all_ids(), array());
     $n->add('index');
     $index_node = $n->node('index');
     $expected_index = (object) array('data' => 'Home', 'attr' => (object) array('id' => 'index', 'sort' => 0));
     /*
      * Should have index node with title 'Home' from the database.
      */
     $this->assertEquals($expected_index, $index_node);
 }
Пример #2
0
<?php

/**
 * Removes a page from the navigation. Called via a hook from
 * the page delete handler.
 */
if (!$this->internal) {
    die('Must be called by another handler');
}
$n = new Navigation();
$n->remove($this->data['page'], false);
$n->save();
require_once 'apps/navigation/lib/Functions.php';
navigation_clear_cache();
Пример #3
0
            $error = $nav->error;
        }
        break;
    case 'move':
        $id = $_POST['page'];
        $ref = $_POST['ref'];
        $pos = $_POST['pos'];
        if ($nav->move($id, $ref, $pos) && $nav->save()) {
            $out = array('msg' => sprintf('Page %s moved to %s %s.', $id, $pos, $ref), 'page' => $id, 'ref' => $ref, 'pos' => $pos);
        } else {
            $error = $nav->error;
        }
        break;
    case 'remove':
        $id = $_POST['page'];
        if ($nav->remove($id) && $nav->save()) {
            require_once 'apps/navigation/lib/Functions.php';
            $ids = $nav->get_all_ids();
            $out = array('msg' => sprintf('Page %s removed.', $id), 'page' => $id, 'other' => navigation_get_other_pages($ids));
        } else {
            $error = $nav->error;
        }
        break;
    default:
        $error = 'Unknown method';
        break;
}
if (!$error) {
    require_once 'apps/navigation/lib/Functions.php';
    navigation_clear_cache();
}
                }
                if (!empty($out)) {
                    foreach ($out as $order => $id) {
                        $order = $order + 1;
                        if (!$objNavigation->updateOrder($id, $order)) {
                            $error[] = $id;
                        }
                    }
                }
            }
            break;
        case 'remove':
            $id = $this->objUrl->get('id');
            if (!empty($id)) {
                $record = $objNavigation->getOne($id);
                if (!empty($record) && $objNavigation->remove($id)) {
                    $links = $objNavigation->getRecords($record['type']);
                    if (empty($links)) {
                        echo json_encode(array('error' => false, 'message' => '<tr><td colspan="2">' . $this->objLanguage->labels[64] . '</td></tr>'));
                    } else {
                        echo json_encode(array('error' => false));
                    }
                } else {
                    echo json_encode(array('error' => true));
                }
            } else {
                echo json_encode(array('error' => true));
            }
            break;
    }
} else {