<?php
/**
 * Zásuvný modul, který přidává akce
 *
 * @package    MaBoBlog
 * @author     Marian Böhmer
 */
class MyWeb_Controller_Plugin_ActionSetup extends Zend_Controller_Plugin_Abstract  
{
    /**
     * ActionStack Objekt
     *
     * @var Zend_Controller_Plugin_ActionStack
     */
    protected $_actionStack = null;
    
    /**
     * Konstruktor
     */
    public function __construct()
    {
        // front controller
        $front = Zend_Controller_Front::getInstance();
        
        // otestuje registraci zásuvného modulu ActionStack
        if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack')) 
        {
            $this->_actionStack = new Zend_Controller_Plugin_ActionStack();
            $front->registerPlugin($this->_actionStack, 97);
        } 
        else 
        {
            $this->_actionStack = $front->getPlugin(
                'Zend_Controller_Plugin_ActionStack'
            );
        }    
    }
    
    /**
     * Metoda volaná před dispečerem
     *
     * @param  Zend_Controller_Request_Abstract $request
     * @return void
     */
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract 
                                        $request)
    {
        // přidá akci, která generuje postranní lištu
        $sidebarAction = clone($request);
        $sidebarAction->setActionName('sidebar');
        $sidebarAction->setControllerName('index');
        $this->_actionStack->pushStack($sidebarAction);
    }
}
