Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue #18381: PluginSetting type date must be saved as a common…
… datetime string (#2753) Dev: use saveformat option Dev: Can be set by default to "Y-m-d H:i" ? Dev: send array of settings, check if datetime and datetimesaveformat is set in array Co-authored-by: Lapiu Dev <devgit@lapiu.biz>
- Loading branch information
1 parent
6875b22
commit aef1090
Showing
9 changed files
with
449 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<?php | ||
|
||
/** | ||
* DemoDateSetting Plugin for LimeSurvey | ||
* @author : Denis Chenu | ||
* @copyright: LimeSurvey <https://community.limesurvey.org/> | ||
* @version:; 0.2.0 | ||
* @licence MIT Licence | ||
*/ | ||
class DemoDateSetting extends PluginBase | ||
{ | ||
/** @inheritdoc **/ | ||
protected static $name = 'DemoDateSetting'; | ||
/** @inheritdoc **/ | ||
protected static $description = 'Plugin to show saveformat function in date setting.'; | ||
/** @inheritdoc **/ | ||
protected $storage = 'DbStorage'; | ||
/** @inheritdoc **/ | ||
protected $settings = [ | ||
'checkDateDate' => array( | ||
'type' => 'date', | ||
'saveformat' => "Y-m-d", | ||
), | ||
'checkDateYear' => array( | ||
'type' => 'date', | ||
'saveformat' => "Y", | ||
), | ||
'checkDateFalse' => array( | ||
'type' => 'date', | ||
'saveformat' => false, | ||
), | ||
'checkDateDefault' => array( | ||
'type' => 'date', | ||
), | ||
]; | ||
|
||
/** @inheritdoc **/ | ||
public function init() | ||
{ | ||
$this->subscribe('beforeSurveySettings'); | ||
$this->subscribe('newSurveySettings'); | ||
} | ||
|
||
/** Event to register the survey settings */ | ||
public function beforeSurveySettings() | ||
{ | ||
$oEvent = $this->event; | ||
$surveyId = $oEvent->get('survey'); | ||
$oEvent->set( | ||
"surveysettings.{$this->id}", | ||
array( | ||
'name' => get_class($this), | ||
'settings' => array( | ||
'checkSurveyDateDate' => array( | ||
'type' => 'date', | ||
'label' => $this->gT('Save date only'), | ||
'help' => sprintf( | ||
$this->gT('Save format is set as Y-m-d, you have only the date when get the settings (“%s“ currently)'), | ||
"<code>" . $this->get('checkSurveyDateDate', 'Survey', $surveyId, '') . "</code>" | ||
), | ||
'saveformat' => "Y-m-d", | ||
'current' => $this->get('checkSurveyDateDate', 'Survey', $surveyId, ''), | ||
), | ||
'checkSurveyDateYear' => array( | ||
'type' => 'date', | ||
'label' => $this->gT('Save year only'), | ||
'help' => sprintf( | ||
$this->gT('Save format is set as Y, you have only the year when get the settings (“%s“ currently)'), | ||
"<code>" . $this->get('checkSurveyDateYear', 'Survey', $surveyId, '') . "</code>" | ||
), | ||
'saveformat' => "Y", | ||
'current' => $this->get('checkSurveyDateYear', 'Survey', $surveyId, ''), | ||
), | ||
'checkSurveyDateFalse' => array( | ||
'type' => 'date', | ||
'label' => $this->gT('Save as shown'), | ||
'help' => sprintf( | ||
$this->gT('Save format is set to false, you have the settings like it shown to the user when get it (“%s“ currently).'), | ||
"<code>" . $this->get('checkSurveyDateFalse', 'Survey', $surveyId, '') . "</code>" | ||
), | ||
'saveformat' => false, | ||
'current' => $this->get('checkSurveyDateFalse', 'Survey', $surveyId, ''), | ||
), | ||
'checkSurveyDateDefault' => array( | ||
'type' => 'date', | ||
'label' => $this->gT('Default save'), | ||
'help' => sprintf( | ||
$this->gT('Save format is not set, you have the settings like it shown to the user when get it (“%s“ currently).'), | ||
"<code>" . $this->get('checkSurveyDateDefault', 'Survey', $surveyId, '') . "</code>" | ||
), | ||
'current' => $this->get('checkSurveyDateDefault', 'Survey', $surveyId, ''), | ||
), | ||
) | ||
) | ||
); | ||
} | ||
|
||
/** Event to save the survey settings **/ | ||
public function newSurveySettings() | ||
{ | ||
$event = $this->event; | ||
/** | ||
* If you don't use same settings in Survey and global : you have to set it before saving | ||
* then when save current saveformat can be used (we don't set it for Default) | ||
**/ | ||
$this->settings = [ | ||
'checkSurveyDateDate' => array( | ||
'type' => 'date', | ||
'saveformat' => "Y-m-d", | ||
), | ||
'checkSurveyDateYear' => array( | ||
'type' => 'date', | ||
'saveformat' => "Y", | ||
), | ||
'checkSurveyDateFalse' => array( | ||
'type' => 'date', | ||
), | ||
'checkSurveyDateFalse' => array( | ||
'type' => 'date', | ||
'saveformat' => false, | ||
), | ||
]; | ||
foreach ($event->get('settings') as $name => $value) { | ||
$this->set($name, $value, 'Survey', $event->get('survey')); | ||
} | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* Update language strings and help | ||
**/ | ||
public function getPluginSettings($getValues = true) | ||
{ | ||
$pluginSettings = parent::getPluginSettings($getValues); | ||
if (!$getValues) { | ||
return $pluginSettings; | ||
} | ||
$pluginSettings['checkDateDate']['label'] = $this->gT("Save date only"); | ||
$pluginSettings['checkDateDate']['help'] = sprintf( | ||
$this->gT("Save format is set as Y-m-d, you have only the date when get the settings (“%s” currently)."), | ||
'<code>' . strval($pluginSettings['checkDateDate']['current']) . "</code>" | ||
); | ||
$pluginSettings['checkDateYear']['label'] = $this->gT("Save year only"); | ||
$pluginSettings['checkDateYear']['help'] = sprintf( | ||
$this->gT("Save format is set as Y, you have only the year when get the settings (“%s” currently)."), | ||
'<code>' . strval($pluginSettings['checkDateYear']['current']) . "</code>" | ||
); | ||
$pluginSettings['checkDateDefault']['label'] = $this->gT("Save as shown"); | ||
$pluginSettings['checkDateDefault']['help'] = sprintf( | ||
$this->gT("Save format is not set, you save the settings like it shown to the user (“%s” currently)."), | ||
'<code>' . strval($pluginSettings['checkDateDefault']['current']) . "</code>" | ||
); | ||
$pluginSettings['checkDateFalse']['label'] = $this->gT("Default save"); | ||
$pluginSettings['checkDateFalse']['help'] = sprintf( | ||
$this->gT("Save format is set to false, you save the settings like it shown to the user (“%s” currently)."), | ||
'<code>' . strval($pluginSettings['checkDateFalse']['current']) . "</code>" | ||
); | ||
return $pluginSettings; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022-2023 LimeSurvey / Denis Chenu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<config> | ||
<metadata> | ||
<name>DemoDateSetting</name> | ||
<type>plugin</type> | ||
<creationDate>2022-12-01</creationDate> | ||
<lastUpdate>2023-03-06</lastUpdate> | ||
<author>Denis Chenu</author> | ||
<authorUrl>https://community.limesurvey.org/</authorUrl> | ||
<version>0.1.0</version> | ||
<license>MIT</license> | ||
<description><![CDATA[Way to save date settings.]]></description> | ||
</metadata> | ||
<compatibility> | ||
<version>5</version> | ||
</compatibility> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.