Пример #1
0
function pages_tools_register_navigation_tree_children(ElggObject $parent_entity, $depth = 0)
{
    $result = false;
    if (pages_tools_is_valid_page($parent_entity)) {
        if ($children = pages_tools_get_ordered_children($parent_entity)) {
            $result = true;
            foreach ($children as $order => $child) {
                $class = "";
                if (!$child->canEdit()) {
                    $class = "no-edit";
                }
                $params = array("name" => "page_" . $child->getGUID(), "text" => $child->title, "title" => $child->title, "href" => $child->getURL(), "rel" => $child->getGUID(), "item_class" => $class, "parent_name" => "page_" . $parent_entity->getGUID(), "priority" => $order);
                if ($depth < 4) {
                    $params["class"] = "pages-tools-wrap";
                }
                // register this item to the menu
                elgg_register_menu_item("pages_nav", $params);
                // register child elements
                pages_tools_register_navigation_tree_children($child, $depth + 1);
            }
        }
    }
    return $result;
}
Пример #2
0
/**
 * Get the children selector options for the edit form
 *
 * @param ElggEntity $entity              the page entity to get the children options for
 * @param int        $current_entity_guid the current edited page GUID
 * @param int        $depth               depth of the tree
 *
 * @return array
 */
function pages_tools_get_parent_selector_children(ElggEntity $entity, $current_entity_guid, $depth = 0)
{
    if (!pages_tools_is_valid_page($entity)) {
        return array();
    }
    $current_entity_guid = sanitise_int($current_entity_guid, false);
    $children = pages_tools_get_ordered_children($entity);
    if (empty($children)) {
        return array();
    }
    $result = array();
    foreach ($children as $child) {
        if ($child->getGUID() === $current_entity_guid) {
            continue;
        }
        $result[$child->getGUID()] = str_repeat('-', $depth + 1) . ' ' . $child->title;
        $result += pages_tools_get_parent_selector_children($child, $current_entity_guid, $depth + 1);
    }
    return $result;
}