<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.limesurvey.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sparkbird</id>
	<title>LimeSurvey Manual - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.limesurvey.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sparkbird"/>
	<link rel="alternate" type="text/html" href="https://www.limesurvey.org/manual/Special:Contributions/Sparkbird"/>
	<updated>2026-08-16T08:56:51Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://www.limesurvey.org/manual/index.php?title=Plugin_system_architecture&amp;diff=62265</id>
		<title>Plugin system architecture</title>
		<link rel="alternate" type="text/html" href="https://www.limesurvey.org/manual/index.php?title=Plugin_system_architecture&amp;diff=62265"/>
		<updated>2014-08-20T20:47:19Z</updated>

		<summary type="html">&lt;p&gt;Sparkbird: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Table of contents:{toc}&lt;br /&gt;
&lt;br /&gt;
Some random stuff on plugin architecture.&lt;br /&gt;
&lt;br /&gt;
A plugin can extend functionality of LimeSurvey. The plugin registers on what events it wants to extend. This could be adding a button to the menu, do something when a respondent starts or finishes the survey... the possibilities are endless.&lt;br /&gt;
&lt;br /&gt;
For the plugin to be able to do it&#039;s magic it might need some special configuration. Below is the &#039;lifetime of a plugin&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;beforeInstall&#039;&#039;&#039; When the plugin is added to the system, this event is fired on the plugin. This way the plugin can set a default config, of check for dependencies. The method can return success or failure and an optional message. This method is also fired when a new version of the plugin is uploaded. This way the plugin can handle upgrades when neccessary.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;beforeActivate&#039;&#039;&#039; Like the beforeInstall event, but this time it is fired when the plugin is activated.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;beforeDeactivate&#039;&#039;&#039; You guessed right, on deactivation. Might show a warning about dependencies of other plugins, lost functionaity etc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;beforeDeinstall&#039;&#039;&#039; This should handle cleanup of extra tables, config etc.&lt;br /&gt;
&lt;br /&gt;
The plugins will extend a base class.&lt;br /&gt;
&lt;br /&gt;
The base plugin class will initialize a storage interface and create wrapper functions for the get and set implemented in the interface.&lt;br /&gt;
&lt;br /&gt;
Code below might contain mistakes, textarea doesnt have syntax checking :p&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;interface PluginStorage {&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
&lt;br /&gt;
 Returns plugin data.&lt;br /&gt;
&lt;br /&gt;
 @param object $plugin The plugin object getting its data.&lt;br /&gt;
&lt;br /&gt;
 @param string | null $key The storage key, if null will return all data for the plugin.&lt;br /&gt;
&lt;br /&gt;
 @param string $model Name of a model in case its model specific plugin data, like for a specific question or survey.&lt;br /&gt;
&lt;br /&gt;
 @param int $id Id of the model for which the data is retreived&lt;br /&gt;
&lt;br /&gt;
 @return mixed The data stored.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
public function get($plugin, $key = null, $model = null, $id = null);&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
&lt;br /&gt;
 Stores plugin data.&lt;br /&gt;
&lt;br /&gt;
 @param object $plugin The plugin object getting its data.&lt;br /&gt;
&lt;br /&gt;
 @param string $key The storage key to identify the data.&lt;br /&gt;
&lt;br /&gt;
 @param mixed $data The data to be stored, serialized using serialize.&lt;br /&gt;
&lt;br /&gt;
 @param string $model Name of a model in case its model specific plugin data, like for a specific question or survey.&lt;br /&gt;
&lt;br /&gt;
 @param int $id Id of the model for which the data is retreived&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
public function set ($plugin, $key, $data, $model = null, $id = null);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class PluginBase {&lt;br /&gt;
&lt;br /&gt;
   protected $storage = &#039;PluginStorage&#039;;&lt;br /&gt;
&lt;br /&gt;
   private $store = null;&lt;br /&gt;
&lt;br /&gt;
   public function &#039;&#039;&#039;construct()&lt;br /&gt;
&lt;br /&gt;
   {&lt;br /&gt;
&lt;br /&gt;
       $this-&amp;gt;store = Plugin::getStore($this-&amp;gt;storage);&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   /**&lt;br /&gt;
&lt;br /&gt;
     This function stores plugin data.&lt;br /&gt;
&lt;br /&gt;
   */&lt;br /&gt;
&lt;br /&gt;
   protected function set($key, $data, $model = null, $id = null)&lt;br /&gt;
&lt;br /&gt;
   {&lt;br /&gt;
&lt;br /&gt;
       if (isset($this-&amp;gt;store))&lt;br /&gt;
&lt;br /&gt;
       {&lt;br /&gt;
&lt;br /&gt;
           return $this-&amp;gt;store-&amp;gt;set($this, $key, $model, $id);&lt;br /&gt;
&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
       return false;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   /**&lt;br /&gt;
&lt;br /&gt;
     This function retrieves plugin data. Do not cache this data; the plugin storage&lt;br /&gt;
&lt;br /&gt;
     engine will handling caching. After the first call to this function, subsequent&lt;br /&gt;
&lt;br /&gt;
     calls will only consist of a few function calls and array lookups.&lt;br /&gt;
&lt;br /&gt;
   */&lt;br /&gt;
&lt;br /&gt;
   protected function get($key = null, $model = null, $id = null)&lt;br /&gt;
&lt;br /&gt;
   {&lt;br /&gt;
&lt;br /&gt;
       if (isset($this-&amp;gt;store))&lt;br /&gt;
&lt;br /&gt;
       {&lt;br /&gt;
&lt;br /&gt;
           return $this-&amp;gt;store-&amp;gt;get($this, $key, $model, $id);&lt;br /&gt;
&lt;br /&gt;
       }&lt;br /&gt;
&lt;br /&gt;
       return false;&lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To see how to add a new menu item and display a page when the menu item is clicked see [[Add_new_menu_and_view_by_a_plugin]]&lt;/div&gt;</summary>
		<author><name>Sparkbird</name></author>
	</entry>
	<entry>
		<id>https://www.limesurvey.org/manual/index.php?title=Add_new_menu_and_view_by_a_plugin&amp;diff=62264</id>
		<title>Add new menu and view by a plugin</title>
		<link rel="alternate" type="text/html" href="https://www.limesurvey.org/manual/index.php?title=Add_new_menu_and_view_by_a_plugin&amp;diff=62264"/>
		<updated>2014-08-20T20:41:41Z</updated>

		<summary type="html">&lt;p&gt;Sparkbird: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;How to write a plugin that adds a menu to the admin menubar &amp;amp; when clicked renders some content &lt;br /&gt;
&lt;br /&gt;
1. Create a new plugin. let us call it Rewards&lt;br /&gt;
&lt;br /&gt;
2. register for events afterAdminMenuLoad and newDirectRequest in the constructor&lt;br /&gt;
&lt;br /&gt;
3. implement the above methods methods in the new plugin class&lt;br /&gt;
&lt;br /&gt;
4. In the method afterAdminMenuLoad, add a new menu item and link it to &lt;br /&gt;
    admin/plugins/direct?plugin=&amp;lt;plugin_name&amp;gt;&amp;amp;function=&amp;lt;plugin_action&amp;gt;&lt;br /&gt;
    e.g&lt;br /&gt;
    admin/plugins/direct?plugin=rewards&amp;amp;function=assignRewards&lt;br /&gt;
&lt;br /&gt;
5. implement the method newDirectRequest &lt;br /&gt;
&lt;br /&gt;
    public function newDirectRequest(){&lt;br /&gt;
        $event = $this-&amp;gt;event;&lt;br /&gt;
        &lt;br /&gt;
        // you can get other params from the request object&lt;br /&gt;
        $request = $event-&amp;gt;get(&#039;request&#039;);&lt;br /&gt;
        &lt;br /&gt;
        //get the function name to call and use the method call_user_func&lt;br /&gt;
        $functionToCall = $event-&amp;gt;get(&#039;function&#039;);        &lt;br /&gt;
        $content = call_user_func(array($this,$functionToCall)); &lt;br /&gt;
        //set the content on the event      &lt;br /&gt;
        $event-&amp;gt;setContent($this, $content);        &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. implement the method plugin_action, in our case it is assignRewards(). &lt;br /&gt;
In this method currently i am just trying to return some dummy content, you can have sophisticated page rendered. &lt;br /&gt;
&lt;br /&gt;
    &amp;lt;nowiki&amp;gt;public function assignRewards() {&lt;br /&gt;
        $content = &amp;quot;&amp;lt;h1&amp;gt; plugin content set succesfully &amp;lt;/h1&amp;gt;&amp;quot;;&lt;br /&gt;
        return $content;        &lt;br /&gt;
    }&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
7. The full Rewards.php &lt;br /&gt;
[[File:Rewards1.zip]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. This is how the UI looks now.&lt;br /&gt;
[[File:Screenshot_2014-08-21_01.34.05.png]]&lt;/div&gt;</summary>
		<author><name>Sparkbird</name></author>
	</entry>
	<entry>
		<id>https://www.limesurvey.org/manual/index.php?title=File:Rewards1.zip&amp;diff=62263</id>
		<title>File:Rewards1.zip</title>
		<link rel="alternate" type="text/html" href="https://www.limesurvey.org/manual/index.php?title=File:Rewards1.zip&amp;diff=62263"/>
		<updated>2014-08-20T20:40:57Z</updated>

		<summary type="html">&lt;p&gt;Sparkbird: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sparkbird</name></author>
	</entry>
	<entry>
		<id>https://www.limesurvey.org/manual/index.php?title=Add_new_menu_and_view_by_a_plugin&amp;diff=62262</id>
		<title>Add new menu and view by a plugin</title>
		<link rel="alternate" type="text/html" href="https://www.limesurvey.org/manual/index.php?title=Add_new_menu_and_view_by_a_plugin&amp;diff=62262"/>
		<updated>2014-08-20T20:40:24Z</updated>

		<summary type="html">&lt;p&gt;Sparkbird: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;How to write a plugin that adds a menu to the admin menubar &amp;amp; when clicked renders some content &lt;br /&gt;
&lt;br /&gt;
1. Create a new plugin. let us call it Rewards&lt;br /&gt;
&lt;br /&gt;
2. register for events afterAdminMenuLoad and newDirectRequest in the constructor&lt;br /&gt;
&lt;br /&gt;
3. implement the above methods methods in the new plugin class&lt;br /&gt;
&lt;br /&gt;
4. In the method afterAdminMenuLoad, add a new menu item and link it to &lt;br /&gt;
    admin/plugins/direct?plugin=&amp;lt;plugin_name&amp;gt;&amp;amp;function=&amp;lt;plugin_action&amp;gt;&lt;br /&gt;
    e.g&lt;br /&gt;
    admin/plugins/direct?plugin=rewards&amp;amp;function=assignRewards&lt;br /&gt;
&lt;br /&gt;
5. implement the method newDirectRequest &lt;br /&gt;
&lt;br /&gt;
    public function newDirectRequest(){&lt;br /&gt;
        $event = $this-&amp;gt;event;&lt;br /&gt;
        &lt;br /&gt;
        // you can get other params from the request object&lt;br /&gt;
        $request = $event-&amp;gt;get(&#039;request&#039;);&lt;br /&gt;
        &lt;br /&gt;
        //get the function name to call and use the method call_user_func&lt;br /&gt;
        $functionToCall = $event-&amp;gt;get(&#039;function&#039;);        &lt;br /&gt;
        $content = call_user_func(array($this,$functionToCall)); &lt;br /&gt;
        //set the content on the event      &lt;br /&gt;
        $event-&amp;gt;setContent($this, $content);        &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. implement the method plugin_action, in our case it is assignRewards(). &lt;br /&gt;
In this method currently i am just trying to return some dummy content, you can have sophisticated page rendered. &lt;br /&gt;
&lt;br /&gt;
    &amp;lt;nowiki&amp;gt;public function assignRewards() {&lt;br /&gt;
        $content = &amp;quot;&amp;lt;h1&amp;gt; plugin content set succesfully &amp;lt;/h1&amp;gt;&amp;quot;;&lt;br /&gt;
        return $content;        &lt;br /&gt;
    }&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
7. The full Rewards.php &lt;br /&gt;
[[File:Rewards.zip]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. This is how the UI looks now.&lt;br /&gt;
[[File:Screenshot_2014-08-21_01.34.05.png]]&lt;/div&gt;</summary>
		<author><name>Sparkbird</name></author>
	</entry>
	<entry>
		<id>https://www.limesurvey.org/manual/index.php?title=File:Screenshot_2014-08-21_01.34.05.png&amp;diff=62261</id>
		<title>File:Screenshot 2014-08-21 01.34.05.png</title>
		<link rel="alternate" type="text/html" href="https://www.limesurvey.org/manual/index.php?title=File:Screenshot_2014-08-21_01.34.05.png&amp;diff=62261"/>
		<updated>2014-08-20T20:39:09Z</updated>

		<summary type="html">&lt;p&gt;Sparkbird: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sparkbird</name></author>
	</entry>
	<entry>
		<id>https://www.limesurvey.org/manual/index.php?title=Add_new_menu_and_view_by_a_plugin&amp;diff=62260</id>
		<title>Add new menu and view by a plugin</title>
		<link rel="alternate" type="text/html" href="https://www.limesurvey.org/manual/index.php?title=Add_new_menu_and_view_by_a_plugin&amp;diff=62260"/>
		<updated>2014-08-20T20:38:36Z</updated>

		<summary type="html">&lt;p&gt;Sparkbird: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;How to write a plugin that adds a menu to the admin menubar &amp;amp; when clicked renders some content &lt;br /&gt;
&lt;br /&gt;
1. Create a new plugin. let us call it Rewards&lt;br /&gt;
&lt;br /&gt;
2. register for events afterAdminMenuLoad and newDirectRequest in the constructor&lt;br /&gt;
&lt;br /&gt;
3. implement the above methods methods in the new plugin class&lt;br /&gt;
&lt;br /&gt;
4. In the method afterAdminMenuLoad, add a new menu item and link it to &lt;br /&gt;
    admin/plugins/direct?plugin=&amp;lt;plugin_name&amp;gt;&amp;amp;function=&amp;lt;plugin_action&amp;gt;&lt;br /&gt;
    e.g&lt;br /&gt;
    admin/plugins/direct?plugin=rewards&amp;amp;function=assignRewards&lt;br /&gt;
&lt;br /&gt;
5. implement the method newDirectRequest &lt;br /&gt;
&lt;br /&gt;
    public function newDirectRequest(){&lt;br /&gt;
        $event = $this-&amp;gt;event;&lt;br /&gt;
        &lt;br /&gt;
        // you can get other params from the request object&lt;br /&gt;
        $request = $event-&amp;gt;get(&#039;request&#039;);&lt;br /&gt;
        &lt;br /&gt;
        //get the function name to call and use the method call_user_func&lt;br /&gt;
        $functionToCall = $event-&amp;gt;get(&#039;function&#039;);        &lt;br /&gt;
        $content = call_user_func(array($this,$functionToCall)); &lt;br /&gt;
        //set the content on the event      &lt;br /&gt;
        $event-&amp;gt;setContent($this, $content);        &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. implement the method plugin_action, in our case it is assignRewards(). &lt;br /&gt;
In this method currently i am just trying to return some dummy content, you can have sophisticated page rendered. &lt;br /&gt;
&lt;br /&gt;
    &amp;lt;nowiki&amp;gt;public function assignRewards() {&lt;br /&gt;
        $content = &amp;quot;&amp;lt;h1&amp;gt; plugin content set succesfully &amp;lt;/h1&amp;gt;&amp;quot;;&lt;br /&gt;
        return $content;        &lt;br /&gt;
    }&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
7. The full Rewards.php &lt;br /&gt;
[[File:Rewards.zip]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. This is how the UI looks now.&lt;br /&gt;
https://www.dropbox.com/s/i01sw6rb5lvhts6/Screenshot%202014-08-21%2001.34.05.png&lt;/div&gt;</summary>
		<author><name>Sparkbird</name></author>
	</entry>
	<entry>
		<id>https://www.limesurvey.org/manual/index.php?title=File:Rewards.php&amp;diff=62259</id>
		<title>File:Rewards.php</title>
		<link rel="alternate" type="text/html" href="https://www.limesurvey.org/manual/index.php?title=File:Rewards.php&amp;diff=62259"/>
		<updated>2014-08-20T20:33:41Z</updated>

		<summary type="html">&lt;p&gt;Sparkbird: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sparkbird</name></author>
	</entry>
	<entry>
		<id>https://www.limesurvey.org/manual/index.php?title=Add_new_menu_and_view_by_a_plugin&amp;diff=62258</id>
		<title>Add new menu and view by a plugin</title>
		<link rel="alternate" type="text/html" href="https://www.limesurvey.org/manual/index.php?title=Add_new_menu_and_view_by_a_plugin&amp;diff=62258"/>
		<updated>2014-08-20T20:30:06Z</updated>

		<summary type="html">&lt;p&gt;Sparkbird: plugin that adds a menu to the admin menubar &amp;amp; when clicked renders some content&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;How to write a plugin that adds a menu to the admin menubar &amp;amp; when clicked renders some content &lt;br /&gt;
&lt;br /&gt;
1. Create a new plugin. let us call it Rewards&lt;br /&gt;
&lt;br /&gt;
2. register for events afterAdminMenuLoad and newDirectRequest in the constructor&lt;br /&gt;
&lt;br /&gt;
3. implement the above methods methods in the new plugin class&lt;br /&gt;
&lt;br /&gt;
4. In the method afterAdminMenuLoad, add a new menu item and link it to &lt;br /&gt;
    admin/plugins/direct?plugin=&amp;lt;plugin_name&amp;gt;&amp;amp;function=&amp;lt;plugin_action&amp;gt;&lt;br /&gt;
    e.g&lt;br /&gt;
    admin/plugins/direct?plugin=rewards&amp;amp;function=assignRewards&lt;br /&gt;
&lt;br /&gt;
5. implement the method newDirectRequest &lt;br /&gt;
&lt;br /&gt;
    public function newDirectRequest(){&lt;br /&gt;
        $event = $this-&amp;gt;event;&lt;br /&gt;
        &lt;br /&gt;
        // you can get other params from the request object&lt;br /&gt;
        $request = $event-&amp;gt;get(&#039;request&#039;);&lt;br /&gt;
        &lt;br /&gt;
        //get the function name to call and use the method call_user_func&lt;br /&gt;
        $functionToCall = $event-&amp;gt;get(&#039;function&#039;);        &lt;br /&gt;
        $content = call_user_func(array($this,$functionToCall)); &lt;br /&gt;
        //set the content on the event      &lt;br /&gt;
        $event-&amp;gt;setContent($this, $content);        &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6. implement the method plugin_action, in our case it is assignRewards(). &lt;br /&gt;
In this method currently i am just trying to return some dummy content, you can have sophisticated page rendered. &lt;br /&gt;
&lt;br /&gt;
    &amp;lt;nowiki&amp;gt;public function assignRewards() {&lt;br /&gt;
        $content = &amp;quot;&amp;lt;h1&amp;gt; plugin content set succesfully &amp;lt;/h1&amp;gt;&amp;quot;;&lt;br /&gt;
        return $content;        &lt;br /&gt;
    }&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
7. The full Rewards.php &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8. This is how the UI looks now.&lt;br /&gt;
https://www.dropbox.com/s/i01sw6rb5lvhts6/Screenshot%202014-08-21%2001.34.05.png&lt;/div&gt;</summary>
		<author><name>Sparkbird</name></author>
	</entry>
</feed>