DEV Community

Bismark
Bismark

Posted on

5 4

LimeSurvey HelloWorld Plugin

The following code is needed to run a simple command on the command line within LimeSurvey.
Your folder structure under upload/plugins should be like this:

  • HelloWorld
    • config.xml
    • HelloWorld.php
<?xml version="1.0" encoding="UTF-8"?>
<config>
    <metadata>
        <name>HelloWorld</name>
        <type>plugin</type>
        <lastUpdate>2022-05-21</lastUpdate>
        <author>My Name</author>
        <authorEmail>My Email Address</authorEmail>
        <authorUrl>MY Homepage</authorUrl>
        <license></license>
        <version>1.0.0</version>
        <description><![CDATA[This Plugin does some magic on the command line]]></description>
    </metadata>

    <compatibility>
        <version>5.0</version>
        <version>4.0</version>
        <version>3.0</version>
    </compatibility>
</config>
Enter fullscreen mode Exit fullscreen mode
class HelloWorld extends PluginBase
{
    protected $storage = 'LimeSurvey\PluginManager\DbStorage';
    static protected $description = 'HelloWorld';
    static protected $name = 'HelloWorld';

    /**
     * subscribe to all needed events
     * @see https://manual.limesurvey.org/Plugin_events
     */
    public function init()
    {
        /** @see https://manual.limesurvey.org/Direct_(command) */
        $this->subscribe('direct');
    }

    /**
     * php application/commands/console.php plugin --target=HelloWorld
     */
    public function direct()
    {
        $event = $this->getEvent();
        $target = $event->get('target');
        if ($target != get_class()) return;

        echo 'HELLO WORLD' . PHP_EOL;
        exit;
    }

}
Enter fullscreen mode Exit fullscreen mode

In LimeSurvey's PluginManager scan files, install and activate the plugin.
Then on the command line run:
php application/commands/console.php plugin --target=HelloWorld

And hopefully you can see: Hello World

Bye!

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay