Skip to content

Commit

Permalink
Fixed issue #16730: A lot of attribute can not be translated in admin…
Browse files Browse the repository at this point in the history
… GUI
  • Loading branch information
olleharstedt committed Mar 5, 2021
1 parent d382c51 commit d6d4cf3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion application/models/Question.php
Expand Up @@ -298,7 +298,8 @@ public function getAdvancedSettingsWithValues($sLanguage = null)
}
$aAttributeValues = QuestionAttribute::model()->getQuestionAttributes($this->qid, $sLanguage);
// TODO: move getQuestionAttributesSettings() to QuestionAttribute model to avoid code duplication
$aAttributeNames = QuestionAttribute::getQuestionAttributesSettings($this->type);
$advancedOnly = true;
$aAttributeNames = QuestionAttribute::getQuestionAttributesSettings($this->type, $advancedOnly);

// If the question has a custom template, we first check if it provides custom attributes
$aAttributeNames = self::getQuestionTemplateAttributes($aAttributeNames, $aAttributeValues, $this);
Expand Down
18 changes: 11 additions & 7 deletions application/models/QuestionAttribute.php
Expand Up @@ -425,19 +425,23 @@ public static function getDefaultSettings()
/**
* Return the question attribute settings for the passed type (parameter)
*
* @param $sType : type of question (this is the attribute 'question_type' in table question_theme)
*
* @param string $sType : type of question (this is the attribute 'question_type' in table question_theme)
* @param boolean $advancedOnly If true, only fetch advanced attributes
* @return array : the attribute settings for this question type
* returns values from getGeneralAttributesFromXml and getAdvancedAttributesFromXml if this fails
* getAttributesDefinition and getDefaultSettings are returned
*
* @throws CException
*/
public static function getQuestionAttributesSettings($sType)
public static function getQuestionAttributesSettings($sType, $advancedOnly = false)
{
$sXmlFilePath = QuestionTheme::getQuestionXMLPathForBaseType($sType);
// get attributes from config.xml
$generalAttributes = self::getGeneralAttibutesFromXml($sXmlFilePath);
if ($advancedOnly) {
$generalAttributes = [];
} else {
// Get attributes from config.xml
$generalAttributes = self::getGeneralAttibutesFromXml($sXmlFilePath);
}
$advancedAttributes = self::getAdvancedAttributesFromXml($sXmlFilePath);
self::$questionAttributesSettings[$sType] = array_merge($generalAttributes, $advancedAttributes);

Expand Down Expand Up @@ -565,7 +569,7 @@ protected static function getGeneralAttibutesFromXml($sXmlFilePath)
// load xml file
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader(false);
}
}
$xml_config = simplexml_load_file($sXmlFilePath);
$aXmlAttributes = json_decode(json_encode((array)$xml_config->generalattributes), true);
// if only one attribute, then it doesn't return numeric index
Expand All @@ -576,7 +580,7 @@ protected static function getGeneralAttibutesFromXml($sXmlFilePath)
}
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader(true);
}
}
} else {
return null;
}
Expand Down
Expand Up @@ -39,8 +39,7 @@
role="tab"
data-toggle="tab"
>
<!-- TODO: Localization -->
<?= $category; ?>
<?= gT($category); ?>
</a>
</li>
<?php endforeach; ?>
Expand Down

0 comments on commit d6d4cf3

Please sign in to comment.