Commit 138d840a authored by Chenu Denis's avatar Chenu Denis
Browse files

[feature] 5.X version

parent f3ee3764
<?xml version="1.0" encoding="UTF-8"?>
<config>
<metadata>
<name>unicityOnSingleChoice</name>
<type>plugin</type>
<creationDate>2020-01-09</creationDate>
<lastUpdate>2022-09-21</lastUpdate>
<author>Denis Chenu</author>
<authorUrl>https://www.sondages.pro/</authorUrl>
<supportUrl>https://support.sondages.pro/</supportUrl>
<version>0.5.0</version>
<license>GNU Affero General Public License v3.0</license>
<description><![CDATA[LimeSurvey plugin to allow only one answer choosen in a dropdown question type.]]></description>
</metadata>
<compatibility>
<version>3</version>
<version>5</version>
</compatibility>
</config>
<?php
/**
* singleAnswerOnSingleChoice : a LimeSurvey plugin to allow only one answer choosen in a dropdown question type
* unicityOnSingleChoice : a LimeSurvey plugin to allow only one answer choosen in a dropdown question type
*
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2019-2020 Denis Chenu <http://www.sondages.pro>
* @copyright 2019-2022 Denis Chenu <http://www.sondages.pro>
* @license GPL v3
* @version 0.4.1
* @version 0.5.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
......@@ -97,19 +97,26 @@ class unicityOnSingleChoice extends PluginBase
$unicityOnChoiceCheckEmpty = $aAttributes['unicityOnChoiceCheckEmpty'];
$unicityOnChoiceAltColumn = $aAttributes['unicityOnChoiceAltColumn'];
$unicityOnChoiceExtra = $aAttributes['unicityOnChoiceExtra'];
$unicityOnChoiceOthers = null;
if(!empty($aAttributes['unicityOnChoiceOthers'])) {
$unicityOnChoiceOthers = $aAttributes['unicityOnChoiceOthers'];
}
$token = null;
if ($unicityOnChoiceToken && !$oSurvey->getIsAnonymized()) {
// If not empty : survey is not anonymous and have token. Adding control on Survey in case of future issue
$token = \LimeExpressionManager::ProcessStepString("{TOKEN}");
$tokenList = null;
if ($unicityOnChoiceToken == 'group' && Yii::getPathOfAlias('responseListAndManage')) {
$tokenList = \responseListAndManage\helpers\tokensList::getTokensList($surveyId, $token);
if ($unicityOnChoiceToken == 'group' && App()->getConfig('TokenUsersListAndManageAPI')) {
$tokenList = \TokenUsersListAndManagePlugin\Utilities::getTokensList($surveyId, $token);
}
}
$baseId = $oEvent->get('surveyId')."X".$oEvent->get('gid')."X".$oEvent->get('qid');
/* get the answers */
$oAnswers = Answer::model()->findAll("qid = :qid AND language = :language", array(":qid" => $qid, ":language" => App()->getLanguage()));
if (intval(App()->getConfig('versionnumber')) < 4 ) {
$oAnswers = Answer::model()->findAll("qid = :qid AND language = :language", array(":qid" => $qid, ":language" => App()->getLanguage()));
} else {
$oAnswers = Answer::model()->findAll("qid = :qid ", array(":qid" => $qid));
}
/* Extra to be removed */
$aAnswerCodesExtra = $this->_getExtraAnswers($unicityOnChoiceExtra);
$aAnswerCodesExtra = array_intersect($aAnswerCodesExtra, CHtml::listData($oAnswers,'code','code'));
......@@ -123,6 +130,18 @@ class unicityOnSingleChoice extends PluginBase
$oCriteria->condition = "$getColumnFilter IS NOT NULL AND $getColumnFilter <>'' ";
}
$oCriteria->compare('id', "<>{$srid}");
if(!empty($unicityOnChoiceOthers)) {
$extraFilters = \getQuestionInformation\Utilities::getFinalOtherFilter($surveyId, $unicityOnChoiceOthers);
foreach($extraFilters as $column => $value) {
$quotedColumn = Yii::app()->db->quoteColumnName($column);
if(empty($value)) {
$oCriteria->addCondition("$quotedColumn IS NULL OR $quotedColumn =''");
} else {
$value = \LimeExpressionManager::ProcessStepString($value, array(), 3, true);
$oCriteria->compare($quotedColumn, $value);
}
}
}
$altColumn = $this->_getColumnFilter($surveyId, $unicityOnChoiceAltColumn);
if($altColumn) {
$oCriteria->compare(Yii::app()->db->quoteColumnName($altColumn), $oAnswer->code);
......@@ -272,7 +291,7 @@ class unicityOnSingleChoice extends PluginBase
'sortorder' => 220,
'inputtype' =>'text',
'expression'=> 1,
'caption' => $this->gT('Alternate colun to find choice already done'),
'caption' => $this->gT('Alternate column to find choice already done'),
'help' => $this->gT('By default use the column of this question,. To use another question : you can use <code>{QCode.sgqa}</code>.'),
'default' => '',
),
......@@ -287,8 +306,19 @@ class unicityOnSingleChoice extends PluginBase
'help' => $this->gT('You can remove any extra answer from current questionaire, Expression allowed.'),
'default' => '',
),
'unicityOnChoiceOthers' => array(
'name' => 'unicityOnChoiceOthers',
'types' => "!",
'category' => gT('Unicity'),
'sortorder' => 240,
'inputtype' =>'textarea',
'expression'=> 1,
'caption' => $this->gT('Other question fields added as filter.'),
'help' => $this->gT('One field by line, field must be a valid question code (single question only). Field and value are separated by colon (<code>:</code>), you can use Expressiona Manager in value. If value is an empty string (before expression), filter use empty for value.'),
'default' => '',
),
);
if (!Yii::getPathOfAlias('responseListAndManage')) {
if (!App()->getConfig('TokenUsersListAndManageAPI')) {
unset($addFilterHtmlAttribute['unicityOnChoiceToken']['options']['group']);
}
if (method_exists($this->getEvent(), 'append')) {
......@@ -312,13 +342,7 @@ class unicityOnSingleChoice extends PluginBase
if(is_null($string)) {
return $default;
}
if (intval(Yii::app()->getConfig('versionnumber'))<3) {
$string = trim(\LimeExpressionManager::ProcessString($string, null, array(), false, 3, 0, false, false, true));
} elseif (version_compare(Yii::app()->getConfig('versionnumber'), "3.6.2", "<")) {
$string = trim(\LimeExpressionManager::ProcessString($string, null, array(), 3, 0, false, false, true));
} else {
$string = trim(\LimeExpressionManager::ProcessStepString($string, array() ,3 , true ));
}
$string = trim(\LimeExpressionManager::ProcessStepString($string, array() ,3 , true ));
if(empty($string)) {
return $default;
}
......@@ -340,13 +364,7 @@ class unicityOnSingleChoice extends PluginBase
if(empty($string)) {
return array();
}
if (intval(Yii::app()->getConfig('versionnumber'))<3) {
$string = trim(\LimeExpressionManager::ProcessString($string, null, array(), false, 3, 0, false, false, true));
} elseif (version_compare(Yii::app()->getConfig('versionnumber'), "3.6.2", "<")) {
$string = trim(\LimeExpressionManager::ProcessString($string, null, array(), 3, 0, false, false, true));
} else {
$string = trim(\LimeExpressionManager::ProcessStepString($string, array() ,3 , true ));
}
$string = trim(\LimeExpressionManager::ProcessStepString($string, array() ,3 , true ));
if(empty($string)) {
return array();
}
......
Supports Markdown
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