Skip to content

Commit

Permalink
Fixed issue #17883: QueXML formatting cannot be changed (#3028)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamzammit committed Apr 14, 2023
1 parent d61c00b commit 4920065
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 57 deletions.
1 change: 1 addition & 0 deletions application/controllers/PrintanswersController.php
Expand Up @@ -184,6 +184,7 @@ public function actionView($surveyid, $printableexport = false)
Yii::import("application.libraries.admin.quexmlpdf", true);

$quexmlpdf = new quexmlpdf();
$quexmlpdf->applyGlobalSettings();

// Setting the selected language for printout
App()->setLanguage($sLanguage);
Expand Down
1 change: 1 addition & 0 deletions application/controllers/ResponsesController.php
Expand Up @@ -90,6 +90,7 @@ public function actionViewquexmlpdf(int $surveyId, int $id, string $browseLang =
$sBrowseLanguage = $aData['language'];
Yii::import("application.libraries.admin.quexmlpdf", true);
$quexmlpdf = new quexmlpdf();
$quexmlpdf->applyGlobalSettings();
// Setting the selected language for printout
App()->setLanguage($sBrowseLanguage);
$quexmlpdf->setLanguage($sBrowseLanguage);
Expand Down
44 changes: 8 additions & 36 deletions application/controllers/admin/Export.php
Expand Up @@ -1213,34 +1213,6 @@ private function surveyexport(string $action, int $iSurveyID)
}
}

/**
* Return a list of queXML settings
*
* @return string[] queXML settings
*/
private function quexmlsettings(): array
{
return array(
'queXMLBackgroundColourQuestion',
'queXMLPageFormat',
'queXMLPageOrientation',
'queXMLEdgeDetectionFormat',
'queXMLBackgroundColourSection',
'queXMLSectionHeight',
'queXMLResponseLabelFontSize',
'queXMLResponseLabelFontSizeSmall',
'queXMLResponseTextFontSize',
'queXMLQuestionnaireInfoMargin',
'queXMLSingleResponseHorizontalHeight',
'queXMLSingleResponseAreaHeight',
'queXMLStyle',
'queXMLAllowSplittingVas',
'queXMLAllowSplittingMatrixText',
'queXMLAllowSplittingSingleChoiceVertical',
'queXMLAllowSplittingSingleChoiceHorizontal'
);
}

/**
* Clear queXML settings from settings table
*
Expand All @@ -1249,7 +1221,10 @@ private function quexmlsettings(): array
*/
public function quexmlclear(int $iSurveyID)
{
$queXMLSettings = $this->quexmlsettings();
Yii::import("application.libraries.admin.quexmlpdf", true);
$defaultquexmlpdf = new quexmlpdf();

$queXMLSettings = $defaultquexmlpdf->_quexmlsettings();
foreach ($queXMLSettings as $s) {
SettingGlobal::setSetting($s, '');
}
Expand All @@ -1267,7 +1242,6 @@ public function quexml(int $iSurveyID)
$iSurveyID = (int) $iSurveyID;
$survey = Survey::model()->findByPk($iSurveyID);

$queXMLSettings = $this->quexmlsettings();
$aData = array();
$aData['surveyid'] = $iSurveyID;
$aData['slangs'] = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
Expand All @@ -1281,7 +1255,8 @@ public function quexml(int $iSurveyID)
array_unshift($aData['slangs'], $aData['baselang']);

Yii::import("application.libraries.admin.quexmlpdf", true);
$defaultquexmlpdf = new quexmlpdf($this->getController());
$defaultquexmlpdf = new quexmlpdf();
$queXMLSettings = $defaultquexmlpdf->_quexmlsettings();

foreach ($queXMLSettings as $s) {
$aData[$s] = getGlobalSetting($s);
Expand All @@ -1295,14 +1270,11 @@ public function quexml(int $iSurveyID)
if (empty($_POST['ok'])) {
$this->renderWrappedTemplate('survey', 'queXMLSurvey_view', $aData);
} else {
$quexmlpdf = new quexmlpdf($this->getController());
$quexmlpdf = new quexmlpdf();

//Save settings globally and generate queXML document
foreach ($queXMLSettings as $s) {
if ($s !== 'queXMLStyle') {
SettingGlobal::setSetting($s, Yii::app()->request->getPost($s));
}

SettingGlobal::setSetting($s, Yii::app()->request->getPost($s));
$method = str_replace("queXML", "set", $s);
$quexmlpdf->$method(Yii::app()->request->getPost($s));
}
Expand Down
42 changes: 42 additions & 0 deletions application/libraries/admin/quexmlpdf.php
Expand Up @@ -2260,6 +2260,48 @@ public function create($questionnaire)
$this->fillLastPageBackground();
}

/**
* Apply global settings from LimeSurvey application
*
*/
public function applyGlobalSettings()
{
foreach ($this->_quexmlsettings() as $s) {
$setting = App()->getConfig($s);
if ($setting !== null && trim($setting) !== '') {
$method = str_replace("queXML", "set", $s);
$this->$method($setting);
}
}
}

/**
* Return a list of queXML settings
*
* @access public
* @return string[] queXML settings
*/
public function _quexmlsettings()
{
return array('queXMLBackgroundColourQuestion',
'queXMLPageFormat',
'queXMLPageOrientation',
'queXMLEdgeDetectionFormat',
'queXMLBackgroundColourSection',
'queXMLSectionHeight',
'queXMLResponseLabelFontSize',
'queXMLResponseLabelFontSizeSmall',
'queXMLResponseTextFontSize',
'queXMLQuestionnaireInfoMargin',
'queXMLSingleResponseHorizontalHeight',
'queXMLSingleResponseAreaHeight',
'queXMLStyle',
'queXMLAllowSplittingVas',
'queXMLAllowSplittingMatrixText',
'queXMLAllowSplittingSingleChoiceVertical',
'queXMLAllowSplittingSingleChoiceHorizontal');
}

/**
* Import the settings/styles set from XML
*
Expand Down
37 changes: 16 additions & 21 deletions application/views/admin/survey/queXMLSurvey_view.php
Expand Up @@ -201,38 +201,33 @@
]); ?>
</div>
</div>
<div class="mb-3 row">
<label class="form-label"><?php eT("Reset to default settings:"); ?></label>
<div>
<?php echo CHtml::htmlButton(gT('Reset now'), [
'class' => 'btn btn-danger col-12 col-md-6',
'data-submit-form' => 1,
'data-use-form-id' => 1,
'data-form-to-save' => 'quexmlclearform',
]); ?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 ">
<input type='hidden' name='ok' value='Y'/>
</div>
</div>

<?= CHtml::endForm() ?>
<?php // Form for "Reset" action. Submitted when clicking the "Reset now" button (inside the main form) ?>
<?= CHtml::form(["admin/export/sa/quexmlclear/surveyid/{$surveyid}/"], 'post', ['id' => 'quexmlclearform']); ?>
<?= CHtml::htmlButton(gT('Reset now'), [
'type' => 'submit',
'class' => 'btn btn-danger col-12 col-md-6 d-none',
]);
?>
<?= CHtml::endForm() ?>
<div class="row">
<div class="col-12">
<div class="row">
<label class="form-label"><?php eT("Reset to default settings:"); ?></label>
<div>
<?php echo CHtml::form(array("admin/export/sa/quexmlclear/surveyid/{$surveyid}/"), 'post', array('id'=>'quexmlclearform'));
echo CHtml::htmlButton(gT('Reset now'), [
'type' => 'submit',
'class' => 'btn btn-danger',
]);
?>
<?= CHtml::endForm() ?>
</div>
</div>
</div>
</div>
</div>
<?php
App()->getClientScript()->registerScript('QueXMLExportBSSwitcher', "
LS.renderBootstrapSwitch();
", LSYii_ClientScript::POS_POSTSCRIPT);
?>

0 comments on commit 4920065

Please sign in to comment.