From 49200655a6681632eda6191fe06b37bdd1cae871 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Sat, 15 Apr 2023 00:02:10 +1000 Subject: [PATCH] Fixed issue #17883: QueXML formatting cannot be changed (#3028) --- .../controllers/PrintanswersController.php | 1 + .../controllers/ResponsesController.php | 1 + application/controllers/admin/Export.php | 44 ++++--------------- application/libraries/admin/quexmlpdf.php | 42 ++++++++++++++++++ .../views/admin/survey/queXMLSurvey_view.php | 37 +++++++--------- 5 files changed, 68 insertions(+), 57 deletions(-) diff --git a/application/controllers/PrintanswersController.php b/application/controllers/PrintanswersController.php index 7b3e9893cf1..366f9dfd9b1 100644 --- a/application/controllers/PrintanswersController.php +++ b/application/controllers/PrintanswersController.php @@ -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); diff --git a/application/controllers/ResponsesController.php b/application/controllers/ResponsesController.php index 1702e57d09a..0f30b426f0f 100644 --- a/application/controllers/ResponsesController.php +++ b/application/controllers/ResponsesController.php @@ -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); diff --git a/application/controllers/admin/Export.php b/application/controllers/admin/Export.php index a1372dc6a05..89533aac8a8 100644 --- a/application/controllers/admin/Export.php +++ b/application/controllers/admin/Export.php @@ -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 * @@ -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, ''); } @@ -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; @@ -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); @@ -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)); } diff --git a/application/libraries/admin/quexmlpdf.php b/application/libraries/admin/quexmlpdf.php index 89228d52ee8..f64f075ed66 100644 --- a/application/libraries/admin/quexmlpdf.php +++ b/application/libraries/admin/quexmlpdf.php @@ -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 * diff --git a/application/views/admin/survey/queXMLSurvey_view.php b/application/views/admin/survey/queXMLSurvey_view.php index d60b5ffb805..cd775b2aa4b 100644 --- a/application/views/admin/survey/queXMLSurvey_view.php +++ b/application/views/admin/survey/queXMLSurvey_view.php @@ -201,17 +201,6 @@ ]); ?> -
- -
- 'btn btn-danger col-12 col-md-6', - 'data-submit-form' => 1, - 'data-use-form-id' => 1, - 'data-form-to-save' => 'quexmlclearform', - ]); ?> -
-
@@ -219,20 +208,26 @@
- - - - 'quexmlclearform']); ?> - 'submit', - 'class' => 'btn btn-danger col-12 col-md-6 d-none', - ]); - ?> +
+
+
+ +
+ 'quexmlclearform')); + echo CHtml::htmlButton(gT('Reset now'), [ + 'type' => 'submit', + 'class' => 'btn btn-danger', + ]); + ?> + +
+
+
+
getClientScript()->registerScript('QueXMLExportBSSwitcher', " LS.renderBootstrapSwitch(); ", LSYii_ClientScript::POS_POSTSCRIPT); ?> -