We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24067
    • 16 Posts
    Thank you for your ideas.

    Implemented following hierarchical view of the available pages:

    $e = &$modx->Event;
    $output = '';
    
    function myChildren ($children){
        $list = '<ul>';
        foreach ($children as $id => $child){
            $list .= '<li><a href="index.php?a=27&id='.$child['self']['id'].'">'.$child['self']['pagetitle'].'</a>';
            $list .= ' <a href="index.php?a=4&pid='.$child['self']['id'].'"><img src="/manager/media/style/MODxCarbon/images/icons/page_white_add.png"></a>';
            if (isset($child['children'])){
                $list .= myChildren($child['children']);
            }
            $list .= '</li>';
        }
        $list .= '</ul>';
        return $list;
    }
    
    if ($e->name == 'OnManagerWelcomeHome') {
        $member = $modx->db->escape($_SESSION['mgrInternalKey']);
        $query  = <<<EOQ
            select distinct c.id, c.pagetitle, ifnull(c.parent, '0') parent
            from modx_member_groups      g 
            join modx_membergroup_access a ON g.user_group = a.membergroup
            join modx_document_groups    d ON d.document_group = a.documentgroup
            join modx_site_content       c ON d.document = c.id
            where g.member = $member
            order by c.pagetitle
    EOQ;
        $result = $modx->db->query( $query );
    
        $tree = array();
        while( $row = $modx->db->getRow( $result ) ) {
            if (!isset($tree[$row['id']])){
                $tree[$row['id']] = array();
            }        
            if (!isset($tree[$row['parent']])){
                $tree[$row['parent']] = array();
            }
            if (!isset($tree[$row['parent']]['children'])){
                $tree[$row['parent']]['children'] = array();
            }
            $tree[$row['id']]['self'] = $row;
        	$tree[$row['parent']]['children'][] = &$tree[$row['id']];
        }
    
        foreach ($tree as $id => $branch){
            if (!isset($branch['self']) && isset($branch['children'])){
               $output .= myChildren($branch['children']);
            }
        }
    }
    
    $e->output($output);
    
    return;