Пример #1
0
function build_all_pages()
{
    global $pages;
    global $pagesParents;
    global $dbPages;
    $list = $dbPages->getAll();
    unset($list['error']);
    foreach ($list as $key => $db) {
        $Page = build_page($key);
        if ($Page !== false) {
            // Generate all posible parents.
            if ($Page->parentKey() === false) {
                $dbPages->addParentKey($Page->key());
                $pagesParents[NO_PARENT_CHAR][$Page->key()] = $Page;
            } else {
                $pagesParents[$Page->parentKey()][$Page->key()] = $Page;
            }
            // $pages array
            $pages[$Page->key()] = $Page;
        }
    }
    // ======== Order pages ========
    // DEBUG: No me gusta esta forma de ordenar
    // Order children
    $tmp = array();
    foreach ($pagesParents as $parentKey => $childrenPages) {
        $tmp[$parentKey] = $childrenPages;
        uasort($tmp[$parentKey], 'orderChildren');
    }
    if (isset($tmp[NO_PARENT_CHAR])) {
        $tmpNoParents = $tmp[NO_PARENT_CHAR];
        unset($tmp[NO_PARENT_CHAR]);
    }
    $pagesParents = $tmp;
    // Order parents.
    foreach ($pagesParents as $parentKey => $childrenPages) {
        $tmp = orderParent($tmp, array($parentKey => $childrenPages), $pages[$parentKey]->position());
    }
    $pagesParents = array(NO_PARENT_CHAR => $tmpNoParents) + $tmp;
}
Пример #2
0
function build_all_pages()
{
    global $pages;
    global $pagesParents;
    global $dbPages;
    $list = $dbPages->getAll();
    unset($list['error']);
    foreach ($list as $key => $db) {
        $Page = build_page($key);
        if ($Page !== false) {
            // --- Order pages by parents ---
            // Generate all posible parents.
            if ($Page->parentKey() === false) {
                // Add the parent key in the dbPages
                $dbPages->addParentKey($Page->key());
                $pagesParents[NO_PARENT_CHAR][$Page->key()] = $Page;
            } else {
                $pagesParents[$Page->parentKey()][$Page->key()] = $Page;
            }
            // --- All pages in 1 array ---
            $pages[$Page->key()] = $Page;
        }
    }
    // ======== Sort pages ========
    $tmpNoParents = $pagesParents[NO_PARENT_CHAR];
    unset($pagesParents[NO_PARENT_CHAR]);
    // Sort children
    $tmpPageWithParent = array();
    foreach ($pagesParents as $parentKey => $childrenPages) {
        $tmpPageWithParent[$parentKey] = $childrenPages;
        uasort($tmpPageWithParent[$parentKey], 'orderChildren');
    }
    // Sort parents
    $tmp = array();
    foreach ($tmpNoParents as $parentKey => $childrenPages) {
        // DEBUG: Workaround, Esto es un bug, cuando se usa el Cli mode
        // DEBUG: Se genera un padre sin index.txt y adentro hay un hijo
        if (isset($pages[$parentKey])) {
            $tmp = orderParent($tmp, array($parentKey => $childrenPages), $pages[$parentKey]->position());
        }
    }
    $pagesParents = array(NO_PARENT_CHAR => $tmp) + $tmpPageWithParent;
}