Skip to content

Instantly share code, notes, and snippets.

@Shnoulle
Last active September 29, 2017 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shnoulle/8b2c361b19bbf75f8058aacac62f15c5 to your computer and use it in GitHub Desktop.
Save Shnoulle/8b2c361b19bbf75f8058aacac62f15c5 to your computer and use it in GitHub Desktop.
<?php
/**
* Description
*
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2017 Denis Chenu <http://www.sondages.pro>
* @license WTFPL
* @version 0.0.1
*
*/
class menuPlugin extends \LimeSurvey\PluginManager\PluginBase {
protected $storage = 'DbStorage';
static protected $description = 'A plugin for testing usage';
static protected $name = 'menuPlugin';
public function init() {
$this->subscribe('onPluginRegistration');
$this->subscribe('afterPluginLoad');
}
public function afterPluginLoad() {
$pluginName = get_class();
tracevar($pluginName); // This happen
$thisMenu = Surveymenu::model()->find("title = :pluginName",array(":pluginName"=>$pluginName));
tracevar($thisMenu);// Always NULL
}
public function onPluginRegistration(){
$pluginName = get_class();
tracevar($pluginName); // This don't see to happen
$thisMenu = Surveymenu::model()->find("title = :pluginName",array(":pluginName"=>$pluginName));
if(!$thisMenu){
//Check if the menu/menu entries are already created use yii database methods for that
$menuArray = array(
"parent_id" => 1, //1 -> main surveymenu, 2-> quickemenu, NULL -> new base menu in sidebar
"title" => $pluginName,
"position" => "side", // possible positions are "side" and "collapsed" state 3.0.0.beta-2
"description" => "[your plugins menu description]"
);
$newMenuId = Surveymenu::staticAddMenu($menuArray);
// repeat this as often as you need it
$menuEntryArray = array(
"name" => "[name of the action]",
"title" => "[title for the action]",
"menu_title" => "[title for the action]",
"menu_description" => "[description for the action]",
"menu_icon" => "[icon for action]", //it is either the fontawesome classname withot the fa- prefix, or the iconclass classname, or a src link
"menu_icon_type" => "fontawesome", // either 'fontawesome', 'iconclass' or 'image'
"menu_link" => "[admin/]controller/sa/action", //the link will be parsed through yii's createURL method
"addSurveyId" => true, //add the surveyid parameter to the url
"addQuestionGroupId" => true, //add gid parameter to url
"addQuestionId" => true, //add qid parameter to url
"linkExternal" => false, //open link in a new tab/window
"hideOnSurveyState" => null, //possible values are "active", "inactive" and null
"manualParams" => "" //please read up on this setting as it may render the link useless
);
SurveymenuEntries::staticAddMenuEntry($newMenuId, $menuEntryArray);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment