<?php

use \ls\menu\MenuItem;

/**
 * Mass action
 *
 * @since 2016-04-29
 * @author Olle Härstedt
 */
class ExamplePlugin extends \ls\pluginmanager\PluginBase
{
    static protected $description = 'Example on how to display admin pages';
    static protected $name = 'ExamplePlugin';
    protected $storage = 'DbStorage';

    public function init()
    {
        $this->subscribe('newDirectRequest');
    }

    /**
     * Called with this URL:
     * http://localhost/index.php/admin/pluginhelper?sa=sidebody&plugin=ExamplePlugin&method=actionIndex&surveyId=793951
     * @return string
     */
    public function actionIndex()
    {
        return '<p>Some content</p>';
    }

    /**
     * Called with this URL:
     * http://localhost/lime25/limesurvey/index.php/admin/pluginhelper?sa=fullpagewrapper&plugin=ExamplePlugin&method=actionIndexGlobal
     * @return string
     */
    public function actionIndexGlobal()
    {
        return '<p>Some global content</p>';
    }

    /**
     * @return void
     */
    public function newDirectRequest()
    {
        $event = $this->event;
        if ($event->get('target') == "ExamplePlugin")
        {
            $request = $event->get('request');
            $functionToCall = $event->get('function');
            $content = $this->$functionToCall($request);
            $event->setContent($this, $content);
        }
    }

}
