Commit a59656e9 authored by Chenu Denis's avatar Chenu Denis
Browse files

[feature] Allow to add menu

parent 28a76855
......@@ -8,7 +8,7 @@
<author>Denis Chenu</author>
<authorUrl>https://extensions.sondages.pro/reloadanyresponse</authorUrl>
<supportUrl>https://support.sondages.pro/</supportUrl>
<version>5.1.0</version>
<version>5.2.0</version>
<license>GNU Affero General Public License v3.0</license>
<description><![CDATA[Allow to reload any response for admin user and respondant.]]></description>
</metadata>
......
......@@ -6,7 +6,7 @@
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2018-2021 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 5.1.0
* @version 5.2.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -330,8 +330,29 @@ class reloadAnyResponse extends PluginBase
throw new CHttpException(403);
}
/* @todo translation of label and help */
$pluginSetting = parent::getPluginSettings($getValues);
return $pluginSetting;
$pluginSettings = parent::getPluginSettings($getValues);
if(version_compare(App()->getConfig("versionnumber"), "3", "<")) {
return $pluginSettings;
}
$oSurveymenuManage = SurveymenuEntries::model()->find("name = :name", array(":name" => 'ReloadAnyResponseSettings'));
$state = !empty($oSurveymenuManage);
$help = $state ? $this->translate('Menu exist, to delete : uncheck box and validate.') : $this->translate("Settings menu didnt exist, to create check box and validate.");
$pluginSettings['createReloadAnyResponseSettings'] = array(
'type' => 'checkbox',
'label' => $this->translate('Add a menu to manage token user list.'),
'default' => false,
'help' => $help,
'current' => $state,
);
if($state) {
$pluginSettings['ShowSettingMenu'] = array(
'type' => 'checkbox',
'label' => $this->translate('Add a link in tool menu for settings.'),
'default' => false,
'current' => $this->get('ShowSettingMenu'),
);
}
return $pluginSettings;
}
/** @inheritdoc **/
public function saveSettings($settings)
......@@ -340,8 +361,70 @@ class reloadAnyResponse extends PluginBase
throw new CHttpException(403);
}
parent::saveSettings($settings);
if (version_compare(App()->getConfig("versionnumber"), "3", "<")) {
return;
}
$this->rarManageNewMenu();
}
/**
* Action for create or delete a menu
* @param $string menu name
* @return void
*/
private function rarManageNewMenu() {
$oSurveymenuEntries = SurveymenuEntries::model()->find("name = :name", array(":name" => 'ReloadAnyResponseSettings'));
$createSettingMenu = App()->getRequest()->getPost('createReloadAnyResponseSettings');
if (empty($oSurveymenuEntries) && $createSettingMenu) {
$parentMenu = 1;
$order = 3;
/* Find token menu */
$oTokensMenuEntries = SurveymenuEntries::model()->find("name = :name", array(":name" => 'tokens'));
if ($oTokensMenuEntries) {
$parentMenu = $oTokensMenuEntries->menu_id;
$order = $oTokensMenuEntries->ordering;
// Add it before token
}
/* Unable to translate it currently */
$aNewMenu = array(
'name' => 'ReloadAnyResponseSettings', // staticAddMenuEntry didn't use it but parse title
'language' => 'en-GB',
'title' => "Reload any response management",
'menu_title' => "Reload any response",
'menu_description' => "Settings of reload any response plugin.",
'menu_icon' => 'refresh',
'menu_icon_type' => 'fontawesome',
'menu_link' => 'admin/pluginhelper',
'manualParams' => array(
'sa' => 'sidebody',
'plugin' => 'reloadAnyResponse',
'method' => 'actionSettings',
),
'permission' => 'surveysettings',
'permission_grade' => 'update',
'pjaxed' => false,
'hideOnSurveyState' => 'none',
'addSurveyId' => true,
'addQuestionGroupId' => false,
'addQuestionId' => false,
'linkExternal' => false,
'ordering' => $order,
);
$iMenu = SurveymenuEntries::staticAddMenuEntry($parentMenu, $aNewMenu);
$oSurveymenuEntries = SurveymenuEntries::model()->findByPk($iMenu);
if ($oSurveymenuEntries) {
$oSurveymenuEntries->ordering = $order;
$oSurveymenuEntries->name = 'ReloadAnyResponseSettings'; // SurveymenuEntries::staticAddMenuEntry cut name, then reset
$oSurveymenuEntries->save();
SurveymenuEntries::reorderMenu($parentMenu);
}
}
if (!empty($oSurveymenuEntries) && empty($createSettingMenu)) {
SurveymenuEntries::model()->deleteAll("name = :name", array(":name" => 'ReloadAnyResponseSettings'));
}
}
/** @inheritdoc
* Add some specific settings in TUMAL
**/
......@@ -1245,10 +1328,10 @@ class reloadAnyResponse extends PluginBase
$event = $this->getEvent();
$surveyId = $event->get('surveyId');
$oSurvey = Survey::model()->findByPk($surveyId);
//~ $iSurveyMenuEntries = SurveymenuEntries::model()->count("name = :name", array(":name" => 'ReloadAnyResponse'));
//~ if($iSurveyMenuEntries && !$this->get('ShowToolMenu')) {
//~ return;
//~ }
$iSurveyMenuEntries = SurveymenuEntries::model()->count("name = :name", array(":name" => 'ReloadAnyResponseSettings'));
if($iSurveyMenuEntries && !$this->get('ShowSettingMenu')) {
return;
}
if(Permission::model()->hasSurveyPermission($surveyId, 'surveysettings', 'update')) {
$aMenuItem = array(
'label' => $this->translate('Reload response settings'),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment