Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/LimeSurvey/LimeSurvey
Browse files Browse the repository at this point in the history
  • Loading branch information
thedirtypanda committed Jul 15, 2021
2 parents db1d413 + 203ea3e commit 468085b
Show file tree
Hide file tree
Showing 20 changed files with 41,517 additions and 41,165 deletions.
1 change: 1 addition & 0 deletions application/config/third_party.php
Expand Up @@ -283,6 +283,7 @@
'jquery-ace' => array(
'devBaseUrl' => 'third_party/jquery-ace',
'basePath' => 'third_party.jquery-ace',
'position' => CClientScript::POS_BEGIN,
'js' => array(
'jquery.ace.js',
),
Expand Down
39 changes: 38 additions & 1 deletion application/controllers/QuestionAdministrationController.php
Expand Up @@ -1638,7 +1638,7 @@ public function actionCopyQuestion()
//save the copy ...savecopy (submitbtn pressed ...)
$savePressed = Yii::app()->request->getParam('savecopy');
if (isset($savePressed) && $savePressed !== null) {
$newTitle = Yii::app()->request->getParam('title');
$newTitle = Yii::app()->request->getParam('question')['title'];
$oldQuestion = Question::model()->findByAttributes(['title' => $newTitle, 'sid' => $surveyId]);
if (!empty($oldQuestion)) {
Yii::app()->user->setFlash('error', gT("Duplicate question code"));
Expand All @@ -1651,12 +1651,25 @@ public function actionCopyQuestion()
)
);
}

$newQuestionL10n = Yii::app()->request->getParam('questionI10N');
$copyQuestionTextValues = [];
if (!empty($newQuestionL10n)) {
foreach ($newQuestionL10n as $lang => $texts) {
$questionText = isset($texts['question']) ? $texts['question'] : '';
$questionHelp = isset($texts['help']) ? $texts['help'] : '';
$copyQuestionTextValues[$lang] = new \LimeSurvey\Datavalueobjects\CopyQuestionTextValues($questionText, $questionHelp);
}
}

$copyQuestionValues = new \LimeSurvey\Datavalueobjects\CopyQuestionValues();
$copyQuestionValues->setOSurvey($oSurvey);
$copyQuestionValues->setQuestionCode($newTitle);
$copyQuestionValues->setQuestionGroupId((int)Yii::app()->request->getParam('gid'));
$copyQuestionValues->setQuestiontoCopy($oQuestion);
if (!empty($copyQuestionTextValues)) {
$copyQuestionValues->setQuestionL10nData($copyQuestionTextValues);
}
$questionPosition = Yii::app()->request->getParam('questionposition');
if ($questionPosition === '') { //this means "at the end"
$questionPosition = -1; //integer indicator for "end"
Expand Down Expand Up @@ -1700,6 +1713,30 @@ public function actionCopyQuestion()
}
}

Yii::app()->getClientScript()->registerScript(
'editorfiletype',
"editorfiletype ='javascript';",
CClientScript::POS_HEAD
);
App()->getClientScript()->registerScriptFile(
App()->getConfig('adminscripts') . 'questionEditor.js',
CClientScript::POS_END
);
PrepareEditorScript(true, $this);
App()->session['FileManagerContext'] = "edit:survey:{$surveyId}";
initKcfinder();
// Add <input> with JSON as value, used by JavaScript.
$aData['jsVariablesHtml'] = $this->renderPartial(
'/admin/survey/Question/_subQuestionsAndAnwsersJsVariables',
[
'anslangs' => $oQuestion->survey->allLanguages,
// TODO
'assessmentvisible' => false,
'scalecount' => $oQuestion->questionType->answerscales
],
true
);

$this->aData = $aData;
$this->render('copyQuestionForm', $aData);
}
Expand Down
60 changes: 60 additions & 0 deletions application/datavalueobjects/CopyQuestionTextValues.php
@@ -0,0 +1,60 @@
<?php

namespace LimeSurvey\Datavalueobjects;

/**
* Class CopyQuestionTextValues
*
* This class represents the texts values to use when copying a question
*
* @package LimeSurvey\Datavalueobjects
*/
class CopyQuestionTextValues
{
/** @var string the question text */
private $questionText;

/** @var string the question help text */
private $help;

/**
* @param string $question
* @param string $help
*/
public function __construct($questionText = '', $help = '') {
$this->questionText = $questionText;
$this->help = $help;
}

/**
* @return string
*/
public function getQuestionText(): string
{
return $this->questionText;
}

/**
* @param string $questionText
*/
public function setQuestionText(string $questionText): void
{
$this->questionText = $questionText;
}

/**
* @return string
*/
public function getHelp(): string
{
return $this->help;
}

/**
* @param string $help
*/
public function setHelp(string $help): void
{
$this->help = $help;
}
}
19 changes: 19 additions & 0 deletions application/datavalueobjects/CopyQuestionValues.php
Expand Up @@ -26,6 +26,9 @@ class CopyQuestionValues
/** @var int the position for the question on the left menu group */
private $questionPositionInGroup;

/** @var array<string,CopyQuestionTextValues> the new question texts */
private $questionL10nData;

/**
* @return int
*/
Expand Down Expand Up @@ -105,4 +108,20 @@ public function setQuestiontoCopy(\Question $questiontoCopy): void
{
$this->questiontoCopy = $questiontoCopy;
}

/**
* @return array<string,CopyQuestionTextValues>
*/
public function getQuestionL10nData(): array
{
return $this->questionL10nData;
}

/**
* @param array<string,CopyQuestionTextValues> $questiontoCopy
*/
public function setQuestionL10nData(array $questionL10nData): void
{
$this->questionL10nData = $questionL10nData;
}
}
Expand Up @@ -18,7 +18,7 @@

const sid = $('input[name=surveyId]').val();
const qid = 0;
const code = $('input[name=title]').val();
const code = $('input[name=question\\[title\\]]').val();

$.ajax({
url: "<?= Yii::app()->createUrl('questionAdministration/checkQuestionCodeUniqueness'); ?>",
Expand Down
13 changes: 11 additions & 2 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -6208,10 +6208,19 @@ function ($sqRankAnwsers) {
}
break;
case Question::QT_R_RANKING_STYLE:
if (count($unansweredSQs) > 0) {
$qattr = isset($LEM->qattr[$qid]) ? $LEM->qattr[$qid] : array();
// If min_answers or max_answers is set, we check that at least one answer is ranked.
// But, if no limit is set, then all answers must be ranked.
if (!empty($qattr['min_answers']) || !empty($qattr['max_answers'])) {
$maxUnrankedAnswers = count($relevantSQs) - 1;
$sMandatoryText = $LEM->gT('Please rank the items.');
} else {
$maxUnrankedAnswers = 0;
$sMandatoryText = $LEM->gT('Please rank all items.');
}
if (count($unansweredSQs) > $maxUnrankedAnswers) {
$qmandViolation = true; // TODO - what about 'other'?
}
$sMandatoryText = $LEM->gT('Please rank all items.');
$mandatoryTip .= App()->twigRenderer->renderPartial(
'/survey/questions/question_help/mandatory_tip.twig',
[
Expand Down
13 changes: 9 additions & 4 deletions application/models/services/CopyQuestion.php
Expand Up @@ -56,7 +56,7 @@ public function copyQuestion($copyOptions)
);
if ($copySuccessful) {
//copy question languages
$this->copyQuestionLanguages($this->copyQuestionValues->getQuestiontoCopy());
$this->copyQuestionLanguages($this->copyQuestionValues->getQuestiontoCopy(), $this->copyQuestionValues->getQuestionL10nData());

//copy subquestions
if ($copyOptions['copySubquestions']) {
Expand Down Expand Up @@ -107,22 +107,27 @@ public function createNewCopiedQuestion($questionCode, $groupId, $questionToCopy
* Copies the languages of a question.
*
* @param \Question $oQuestion old question from where to copy the languages (see table questions_l10ns)
* @param array<string,\LimeSurvey\Datavalueobjects\CopyQuestionTextValues> $newQuestionL10nData the text values to override
*
* @before $this->newQuestion must exist and should not be null
*
* @return bool true if all languages could be copied,
* false if no language was copied or save failed for one language
*/
private function copyQuestionLanguages($oQuestion)
private function copyQuestionLanguages($oQuestion, $newQuestionL10nData = [])
{
$allLanguagesAreCopied = false;
if ($oQuestion !== null) {
$allLanguagesAreCopied = true;
foreach ($oQuestion->questionl10ns as $sLanguage) {
foreach ($oQuestion->questionl10ns as $questionl10n) {
$copyLanguage = new \QuestionL10n();
$copyLanguage->attributes = $sLanguage->attributes;
$copyLanguage->attributes = $questionl10n->attributes;
$copyLanguage->id = null; //new id needed
$copyLanguage->qid = $this->newQuestion->qid;
if (isset($newQuestionL10nData[$questionl10n->language])) {
$copyLanguage->question = $newQuestionL10nData[$questionl10n->language]->getQuestionText();
$copyLanguage->help = $newQuestionL10nData[$questionl10n->language]->getHelp();
}
$allLanguagesAreCopied = $allLanguagesAreCopied && $copyLanguage->save();
}
}
Expand Down
Expand Up @@ -8,60 +8,30 @@
* @var Question $oQuestion
*/
?>
<?php PrepareEditorScript(true, $this); ?>
<?php if ($oQuestion->title) {
$sPattern = "^([a-zA-Z][a-zA-Z0-9]*|{$oQuestion->title})$";
} else {
$sPattern = "^[a-zA-Z][a-zA-Z0-9]*$";
} ?>

<!-- Question Code -->
<div class="form-group">
<label class=" control-label" for='title'><?php eT("Code:"); ?></label>
<div class="">
<?php echo CHtml::textField(
"title",
$oQuestion->title . 'Copy',
array('class'=>'form-control','size'=>"20",'maxlength'=>'20','pattern'=>$sPattern,"autofocus"=>"autofocus",'id'=>"title")
);
?>
<span class='text-warning'><?php eT("Required"); ?> </span>
<p id="question-code-unique-warning" class="hidden text-warning"><?= gT('Question codes must be unique.'); ?></p>
</div>
<div class="row">
<!-- Question code -->
<?php $this->renderPartial(
"questionCode",
[
'question' => $oQuestion,
'newTitle' => $oQuestion->title . "Copy",
]
); ?>
<!-- Language selector -->
<?php $this->renderPartial("languageselector", ['oSurvey' => $oSurvey]); ?>
</div>

<!-- New question language tabs -->
<ul class="nav nav-tabs" style="margin-right: 8px;" >
<li role="presentation" class="active">
<a role="tab" data-toggle="tab" href="#<?php echo $oSurvey->language; ?>">
<?php echo getLanguageNameFromCode($oSurvey->language,false); ?> (<?php eT("Base language"); ?>)
</a>
</li>
</ul>

<!-- Editors for each languages -->
<div class="tab-content" >

<!-- Base Language tab-pane -->
<div id="<?php echo $oSurvey->language; ?>" class="tab-pane fade in active">

<div class="panel-body">
<div class="col-12 ls-space margin all-5 scope-contains-ckeditor">
<div class="ls-flex-row">
<div class="ls-flex-item grow-2 text-left">
<label class="col-sm-12"><?= gT('Question'); ?></label>
</div>
</div>
<div class="htmleditor input-group">
<?= CHtml::textArea(
"question_{$oSurvey->language}",
$oQuestion->questionl10ns[$oSurvey->language]->question,
array('class'=>'form-control','cols'=>'60','rows'=>'5','id'=>"question_{$oSurvey->language}",
'disabled' => "disabled")
); ?>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<!-- Text elements -->
<?php $this->renderPartial(
"textElements",
[
'oSurvey' => $oSurvey,
'question' => $oQuestion,
'showScriptField' => false,
]
); ?>
</div>
</div>

Expand Down
3 changes: 3 additions & 0 deletions application/views/questionAdministration/copyQuestionForm.php
Expand Up @@ -10,6 +10,8 @@

<div id='edit-question-body' class='side-body <?php echo getSideBodyClass(false); ?>'>

<?= $jsVariablesHtml; ?>

<!-- Page Title-->
<div class="pagetitle h3">
<?php
Expand All @@ -22,6 +24,7 @@
<?php echo CHtml::form(array("questionAdministration/copyQuestion"), 'post',
array('class' => 'form30 ', 'id' => 'form_copy_question', 'name' => 'frmeditquestion')); ?>
<?php /** this btn is trigger by save&close topbar button in copyQuestiontobar_view */ ?>
<input type="hidden" name="sid" value="<?= $oSurvey->sid; ?>" />
<input
type='submit'
style="display:none"
Expand Down
2 changes: 1 addition & 1 deletion application/views/questionAdministration/create.php
Expand Up @@ -114,7 +114,7 @@ class="btn navbar-btn button white btn-success"
[
'oSurvey' => $oSurvey,
'question' => $oQuestion,
'aStructureArray' => $aQuestionTypeGroups,
//'aStructureArray' => $aQuestionTypeGroups,
'showScriptField' => $showScriptField,
]
); ?>
Expand Down
2 changes: 1 addition & 1 deletion application/views/questionAdministration/questionCode.php
Expand Up @@ -14,7 +14,7 @@
class="form-control"
id="questionCode"
name="question[title]"
value="<?= $question->title; ?>"
value="<?= !empty($newTitle) ? $newTitle : $question->title; ?>"
required="true"
maxlength="20"
onfocusout="LS.questionEditor.checkQuestionCodeUniqueness($(this).val(), <?= $question->qid; ?>)"
Expand Down
8 changes: 6 additions & 2 deletions application/views/questionAdministration/summary.php
Expand Up @@ -216,8 +216,12 @@
</td>
<td>
<?php
if (isset($setting['expression']) && $setting['expression'] == 2) {
LimeExpressionManager::ProcessString('{' . $setting['value'] . '}', $question->qid);
if (isset($setting['expression']) && $setting['expression'] > 0) {
if ($setting['expression'] == 1) {
LimeExpressionManager::ProcessString($setting['value'], $question->qid);
} else {
LimeExpressionManager::ProcessString('{' . $setting['value'] . '}', $question->qid);
}
echo LimeExpressionManager::GetLastPrettyPrintExpression();
} else {
if (($setting['i18n'] ==null) || ($setting['i18n'] == false)) {
Expand Down

0 comments on commit 468085b

Please sign in to comment.