Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Jun 15, 2022
2 parents 396938a + 59dc1f0 commit ad498f2
Show file tree
Hide file tree
Showing 25 changed files with 489 additions and 388 deletions.
4 changes: 2 additions & 2 deletions application/config/version.php
Expand Up @@ -12,9 +12,9 @@
*/

$config['versionnumber'] = '5.4.0-dev';
$config['dbversionnumber'] = 487;
$config['dbversionnumber'] = 488;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['templateapiversion'] = 3;
$config['assetsversionnumber'] = '30280';
$config['assetsversionnumber'] = '30281';
return $config;
8 changes: 8 additions & 0 deletions application/controllers/QuestionAdministrationController.php
Expand Up @@ -2437,6 +2437,10 @@ private function storeNewQuestionData($aQuestionData = null, $subquestion = fals
}
}

if (!isset($aQuestionData['same_script'])) {
$aQuestionData['same_script'] = 0;
}

$aQuestionData = array_merge(
[
'sid' => $iSurveyId,
Expand Down Expand Up @@ -2535,6 +2539,10 @@ private function updateQuestionData(&$oQuestion, $aQuestionData)
}
}

if (!isset($aQuestionData['same_script'])) {
$aQuestionData['same_script'] = 0;
}

$originalRelevance = $oQuestion->relevance;

$oQuestion->setAttributes($aQuestionData, false);
Expand Down
2 changes: 2 additions & 0 deletions application/helpers/admin/import_helper.php
Expand Up @@ -2849,6 +2849,7 @@ function TSVImportSurvey($sFullFilePath)
$question['encrypted'] = (isset($row['encrypted']) ? $row['encrypted'] : 'N');
$lastother = $question['other'] = (isset($row['other']) ? $row['other'] : 'N'); // Keep trace of other settings for sub question
$question['same_default'] = (isset($row['same_default']) ? $row['same_default'] : 0);
$question['same_script'] = (isset($row['same_script']) ? $row['same_script'] : 0);
$question['parent_qid'] = 0;

// For multi language survey : same name, add the gid to have same name on different gid. Bad for EM.
Expand Down Expand Up @@ -2893,6 +2894,7 @@ function TSVImportSurvey($sFullFilePath)
case 'mandatory':
case 'other':
case 'same_default':
case 'same_script':
case 'default':
break;
default:
Expand Down
3 changes: 3 additions & 0 deletions application/helpers/export_helper.php
Expand Up @@ -2555,6 +2555,7 @@ function tsvSurveyExport($surveyid)
'other',
'default',
'same_default',
'same_script',
);

$survey = Survey::model()->findByPk($surveyid);
Expand Down Expand Up @@ -2890,6 +2891,7 @@ function tsvSurveyExport($surveyid)
$tsv_output['encrypted'] = !empty($question['encrypted']) ? $question['encrypted'] : 'N';
$tsv_output['other'] = $question['other'];
$tsv_output['same_default'] = $question['same_default'];
$tsv_output['same_script'] = $question['same_script'];

if (array_key_exists($language, $defaultvalues) && array_key_exists($qid, $defaultvalues[$language])) {
$tsv_output['default'] = $defaultvalues[$language][$qid];
Expand Down Expand Up @@ -2954,6 +2956,7 @@ function tsvSurveyExport($surveyid)
$tsv_output['mandatory'] = !empty($subquestion['mandatory']) ? $subquestion['mandatory'] : '';
$tsv_output['other'] = $subquestion['other'];
$tsv_output['same_default'] = $subquestion['same_default'];
$tsv_output['same_script'] = $subquestion['same_script'];

if (array_key_exists($language, $defaultvalues) && array_key_exists($subquestion['qid'], $defaultvalues[$language])) {
$tsv_output['default'] = $defaultvalues[$language][$subquestion['qid']];
Expand Down
18 changes: 18 additions & 0 deletions application/helpers/update/updates/Update_488.php
@@ -0,0 +1,18 @@
<?php

namespace LimeSurvey\Helpers\Update;

class Update_488 extends DatabaseUpdateBase
{
/**
* @inheritDoc
*/
public function up()
{
$this->db->createCommand()->addColumn(
'{{questions}}',
'same_script',
"integer NOT NULL default '0'"
);
}
}
2 changes: 2 additions & 0 deletions application/models/Question.php
Expand Up @@ -33,6 +33,7 @@
* @property integer $same_default Saves if user set to use the same default value across languages in default options dialog ('Edit default answers')
* @property string $relevance Questions relevane equation
* @property string $modulename
* @property integer $same_script Whether the same script should be used for all languages
*
* @property Survey $survey
* @property QuestionGroup $groups //@TODO should be singular
Expand Down Expand Up @@ -152,6 +153,7 @@ public function rules()
array('type', 'length', 'min' => 1, 'max' => 1),
array('preg,relevance', 'safe'),
array('modulename', 'length', 'max' => 255),
array('same_script', 'numerical', 'integerOnly' => true, 'allowEmpty' => true),
);
// Always enforce unicity on Sub question code (DB issue).
if ($this->parent_qid) {
Expand Down
20 changes: 18 additions & 2 deletions application/models/QuestionBaseRenderer.php
Expand Up @@ -59,8 +59,9 @@ public function __construct($aFieldArray, $bRenderDirect = false)
$oQuestionTemplate = QuestionTemplate::getNewInstance($this->oQuestion);
$oQuestionTemplate->registerAssets(); // Register the custom assets of the question template, if needed

if (!empty($this->oQuestion->questionl10ns[$this->sLanguage]->script)) {
$sScriptRendered = LimeExpressionManager::ProcessString($this->oQuestion->questionl10ns[$this->sLanguage]->script, $this->oQuestion->qid, ['QID' => $this->oQuestion->qid]);
$questionScript = $this->getQuestionScript();
if (!empty($questionScript)) {
$sScriptRendered = LimeExpressionManager::ProcessString($questionScript, $this->oQuestion->qid, ['QID' => $this->oQuestion->qid]);
$this->addScript('QuestionStoredScript-' . $this->oQuestion->qid, $sScriptRendered, LSYii_ClientScript::POS_POSTSCRIPT);
}
}
Expand Down Expand Up @@ -417,6 +418,21 @@ public function includeKeypad()
}
}

/**
* Returns the question script to render depending on the language.
* If "Use for all languages" is set, the base language's script is used.
* @return string|null
*/
protected function getQuestionScript()
{
$language = $this->oQuestion->same_script ? $this->oQuestion->survey->language : $this->sLanguage;
$script = null;
if (!empty($this->oQuestion->questionl10ns[$language]->script)) {
$script = $this->oQuestion->questionl10ns[$language]->script;
}
return $script;
}

abstract public function getMainView();
abstract public function getRows();
abstract public function render();
Expand Down
123 changes: 67 additions & 56 deletions application/views/questionAdministration/textElements.php
Expand Up @@ -31,28 +31,30 @@
<div role="tabpanel" class="tab-pane active" id="question-tab">
<?php foreach($oSurvey->allLanguages as $lang): ?>
<div class="lang-hide lang-<?= $lang; ?>" style="<?= $lang != $oSurvey->language ? 'display: none;' : '' ?>">
<div class="form-group scope-contains-ckeditor">
<?= CHtml::textArea(
"questionI10N[$lang][question]",
$question->questionl10ns[$lang]->question ?? '',
[
'class' => 'form-control',
'cols' => '60',
'rows' => '8',
'id' => "question_{$lang}",
'data-contents-dir' => getLanguageRTL($lang) ? 'rtl' : 'ltr',
'placeholder' => gT('Enter your question here...'),
]
); ?>
<?= getEditor(
'question-text',//"question_" . $lang, //this is important for LimereplacementfieldsController function getReplacementFields(...)!
"question_" . $lang,
"[".gT("Question:","js")."](".$lang.")",
$oSurvey->sid,
$question->gid ?? 0,
$question->qid ?? 0,
'editquestion');
?>
<div class="form-group">
<div class="input-group w-100">
<?= CHtml::textArea(
"questionI10N[$lang][question]",
$question->questionl10ns[$lang]->question ?? '',
[
'class' => 'form-control',
'cols' => '60',
'rows' => '8',
'id' => "question_{$lang}",
'data-contents-dir' => getLanguageRTL($lang) ? 'rtl' : 'ltr',
'placeholder' => gT('Enter your question here...'),
]
); ?>
<?= getEditor(
'question-text',//"question_" . $lang, //this is important for LimereplacementfieldsController function getReplacementFields(...)!
"question_" . $lang,
"[".gT("Question:","js")."](".$lang.")",
$oSurvey->sid,
$question->gid ?? 0,
$question->qid ?? 0,
'editquestion');
?>
</div>
</div>
</div>
<?php endforeach; ?>
Expand All @@ -62,28 +64,30 @@
<div role="tabpanel" class="tab-pane" id="question-help-tab">
<?php foreach($oSurvey->allLanguages as $lang): ?>
<div class="lang-hide lang-<?= $lang; ?>" style="<?= $lang != $oSurvey->language ? 'display: none;' : '' ?>">
<div class="form-group scope-contains-ckeditor">
<?= CHtml::textArea(
"questionI10N[$lang][help]",
$question->questionl10ns[$lang]->help ?? '',
[
'class' => 'form-control',
'cols' => '60',
'rows' => '4',
'id' => "help_{$lang}",
'data-contents-dir' => getLanguageRTL($lang) ? 'rtl' : 'ltr',
'placeholder' => gT('Enter some help text if your question needs some explanation here...'),
]
); ?>
<?= getEditor(
"help_".$lang,
"help_".$lang,
"[".gT("Help:", "js")."](".$lang.")",
$oSurvey->sid,
$question->gid ?? 0,
$question->qid ?? 0,
$action = ''
); ?>
<div class="form-group">
<div class="input-group w-100">
<?= CHtml::textArea(
"questionI10N[$lang][help]",
$question->questionl10ns[$lang]->help ?? '',
[
'class' => 'form-control',
'cols' => '60',
'rows' => '4',
'id' => "help_{$lang}",
'data-contents-dir' => getLanguageRTL($lang) ? 'rtl' : 'ltr',
'placeholder' => gT('Enter some help text if your question needs some explanation here...'),
]
); ?>
<?= getEditor(
"help_".$lang,
"help_".$lang,
"[".gT("Help:", "js")."](".$lang.")",
$oSurvey->sid,
$question->gid ?? 0,
$question->qid ?? 0,
$action = ''
); ?>
</div>
</div>
</div>
<?php endforeach; ?>
Expand All @@ -94,19 +98,26 @@
<?php foreach($oSurvey->allLanguages as $lang): ?>
<div class="lang-hide lang-<?= $lang; ?>" style="<?= $lang != $oSurvey->language ? 'display: none;' : '' ?>">
<div class="form-group">
<div class="row">
<div class="col-sm-12 text-right">
<input
type="checkbox"
name="scriptForAllLanguages"
id="selector--scriptForAllLanguages"
v-model="scriptForAllLanugages"
/>&nbsp;
<label for="selector--scriptForAllLanguages">
<?= gT('Set for all languages'); ?>
</label>
<?php if ($lang == $oSurvey->language): ?>
<div class="row">
<div class="col-sm-12 text-right">
<input
type="checkbox"
name="question[same_script]"
id="same_script"
value=1
<?php if($question->same_script): ?>
checked = 'checked'
<?php endif; ?>
/>&nbsp;
<label for="same_script">
<?= gT('Use for all languages'); ?>
</label>
</div>
</div>
</div>
<?php else: ?>
<div class="alert alert-warning same-script-alert hidden"><?= gT('The script for this language will not be used because "Use for all languages" is set on the base language\'s script.') ?></div>
<?php endif; ?>

<?= CHtml::textArea(
"questionI10N[$lang][script]",
Expand Down

0 comments on commit ad498f2

Please sign in to comment.