<?php

/**
 * Description of FcarouselWidget
 *
 * @author Mohammed Osman  <osmancode@gmail.com>
 */
class FcarouselWidget extends ShortCodeWidget {

    protected $_options = array(
        array(
            'name' => 'slider_id',
            'type' => 'text',
            'label' => 'Slider ID',
            'value' => 0,
        ),
    );

    public function run() {
        if (isset($this->_options['slider_id'])) {
            $carousel = Slider::model()->findByPk($this->_options['slider_id']);
            if ($carousel === NULL) {
                echo '<!-- NOT FOUND -->';
                return;
            }
            if (isset($this->_options['layout']) && $this->getViewFile('fcarousel/' . $this->_options['layout'])) {
                $this->layout = $this->_options['layout'];
            } else {
                echo '<!-- LAYOUT NOT FOUND -->';
            }
            echo $this->render("fcarousel/{$this->layout}", array(
                'carousel' => $carousel,
                    ), true);
        } else {
            echo '<!--PARAM NOT SET-->';
        }
    }

}
