<?php

class CMenuWidget extends ShortCodeWidget {

    protected $_options = array(
        array(
            'name' => 'model_id',
            'label' => 'Menu ID',
            'value' => 0,
        ),
    );
    public $modelClass = "Menu";
    public $shortCode = 'cmenu';

    public function init() {
        
    }

    public function run() {
        if (!isset($this->_options['model_id'])) {
            echo '<!--PARAM NOT SET-->';
        } else {
            $menu = CActiveRecord::model($this->modelClass)->findByPk($this->_options['model_id']);
            if ($menu !== NULL) {

                $this->widget('ext.widgets.FMenu', array_merge($menu->getOptions(), array(
                    'items' => $menu->getItems(),
                                )
                        )
                );
            } else {
                echo '<!-- NOT FOUND -->';
                return;
            }
        }
    }

}
