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

[feature] Add an optionnale prefix

parent 16d6abde
......@@ -12,8 +12,9 @@ See [Install and activate a plugin for LimeSurvey](https://extensions.sondages.p
- Create a short text question type
- In _Input_ set _Use this question as an unique id._ to Yes
- Use this unique id question like all other Expression Manager variables.
- Optionnaly : you can add a prefix to the generated unique ID
_tip_ You can use hidden attribute to totally hide this question to participant/
_tip_ You can use hidden attribute to totally hide this question to participant
## Contribute
......@@ -21,6 +22,6 @@ Issue and pull request are welcome on [gitlab](https://gitlab.com/SondagesPro/Qu
## Home page & Copyright
- HomePage <http://extensions.sondages.pro/>
- Copyright © 2019-2020 Denis Chenu <https://sondages.pro>
- Copyright © 2019-2021 Denis Chenu <https://sondages.pro>
Distributed under [GNU AFFERO GENERAL PUBLIC LICENSE Version 3](http://www.gnu.org/licenses/agpl.txt) licence
......@@ -3,9 +3,9 @@
* generateUniqId
*
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2019-2020 Denis Chenu <http://www.sondages.pro>
* @copyright 2019-2021 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 0.2.4
* @version 0.3.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
......@@ -43,9 +43,9 @@ class generateUniqId extends PluginBase {
$scriptAttributes = array(
'useAsUniqueId' => array(
'name' => 'useAsUniqueId',
'types' => 'S', /* Onlky for short text */
'types' => 'S', /* Only for short text */
'category' => gT('Input'),
'sortorder' => 101,
'sortorder' => 201,
'inputtype'=>'switch',
'options'=>array(
0=>gT('No'),
......@@ -55,7 +55,22 @@ class generateUniqId extends PluginBase {
'help' => $this->_translate('An unique id was generated and fill the answer of this question. This unique id can be used after in expression manager. This unique id can not be updated by user.'),
'default' => 0,
),
'uniqueIdPrefix' => array(
'name' => 'uniqueIdPrefix',
'caption' => $this->_translate('Optionnal prefix for unique id.'),
'help' => null,
'types' => 'S', /* Only for short text */
'category' => gT('Input'),
'sortorder' => 210,
'inputtype' =>'textarea',
'default' => '',
'expression' => 1
),
);
if(version_compare(App()->getConfig('versionnumber'), "3.6.0" ) < 1) {
// Remove if version is under 3.6
unset($scriptAttributes['uniqueIdPrefix']);
}
$this->getEvent()->append('questionAttributes', $scriptAttributes);
}
......@@ -161,7 +176,17 @@ class generateUniqId extends PluginBase {
$questionColumn = $oQuestionUniqueId->sid.'X'.$oQuestionUniqueId->gid.'X'.$oQuestionUniqueId->qid;
$generatedUniqId[] = $questionColumn;
if(empty($oResponse) || empty($oResponse->$questionColumn)) {
$_SESSION['survey_'.$surveyId][$questionColumn] = hash('sha256',uniqid($srid.rand(), true));
$tempUniqueId = hash('sha256',uniqid($srid.rand(), true));
if(version_compare(App()->getConfig('versionnumber'), "3.6.0" ) > 0) {
$oPrefixUniqueId = QuestionAttribute::model()->find(
"qid = :qid and attribute = :attribute",
array(':qid' => $oQuestionUniqueId->qid, ':attribute' => 'uniqueIdPrefix' )
);
if($oPrefixUniqueId && $oPrefixUniqueId->value) {
$tempUniqueId = LimeExpressionManager::ProcessStepString($oPrefixUniqueId->value, array(), 3, true) . $tempUniqueId;
}
}
$_SESSION['survey_'.$surveyId][$questionColumn] = $tempUniqueId;
if($oResponse) {
$oResponse->$questionColumn = $_SESSION['survey_'.$surveyId][$questionColumn];
}
......
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