Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by ReMaker ( 17 years ago )
<?php
//===================================================================================================
class CMS_MenuIterator implements Iterator
{
    private $obj;
    private $open;
    private $rs;    
    private $row;
        
    function __construct($obj)
    {
        $this->obj=$obj;
        $this->open=false;
    }
    
    public function rewind()
    {
        global $DB;
        if ($this->open) $this->rs->Free();
        $this->rs=$DB->Query("SELECT M1.id, M1.name, M1.url, COUNT(M2.id) AS submenu FROM mod_menu_punkt AS M1 LEFT JOIN mod_menu_punkt AS M2 ON M2.idfolder=M1.id WHERE M1.isfolder=0 AND M1.idfolder=%d GROUP BY M1.id", $this->obj->menu_group);
        if ($this->rs===FALSE) return;
        $this->open=true;
        $this->row=$this->rs->Fetch();
    }
    
    public function next()
    {
        $this->row=$this->rs->Fetch();
    }
    
    public function valid()
    {
        if (!$this->open) return FALSE;
        if ($this->row!==FALSE) return TRUE;
         else {$this->rs->Free(); return FALSE;}
    }
    
    public function key()
    {
        return $this->row['id'];
    }
    
    public function current()
    {
        return array('name'=>$this->row['name'], 'url'=>$this->row['url'], 'submenu'=>$this->row['submenu']>0?(new CMS_Menu($this->row['id'])):NULL);
    }   
}
//===================================================================================================

//===========================================================================
class CMS_Menu implements IteratorAggregate
{
    public $menu_group;

    function __construct($menu_group)
    {
        $this->menu_group=$menu_group;
    }
    
    public function getIterator()
    {
        return new CMS_MenuIterator($this);
    }  
}
//===========================================================================

 

Revise this Paste

Your Name: Code Language: