Skip to content

Commit

Permalink
Fixed issue #14186: Path to preview image broken when creating a cust…
Browse files Browse the repository at this point in the history
…om question theme

Dev: core use assets, the use assets
Dev: usage of assetmanager (be sure to be in public)
Dev: since userquestionthemerootdir is updatable by config , we MUST use asset
Dev: because url can be something else than upload/theme/question …
  • Loading branch information
Shnoulle authored and olleharstedt committed Jan 8, 2019
1 parent a2cdfe0 commit f4eff57
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions application/models/QuestionTemplate.php
Expand Up @@ -411,19 +411,25 @@ static public function getQuestionTemplateUserList($type)

// Get the config file and check if template is available
$oConfig = self::getTemplateConfig($sFullPathToQuestionTemplate);

if (is_object($oConfig) && isset($oConfig->engine->show_as_template) && $oConfig->engine->show_as_template) {
if (!empty($oConfig->metadata->title)){
$aQuestionTemplates[$file]['title'] = json_decode(json_encode($oConfig->metadata->title), TRUE)[0];
} else {
$templateName = $file;
$aQuestionTemplates[$file]['title'] = $templateName;
}

if (!empty($oConfig->files->preview->filename)){
$aQuestionTemplates[$file]['preview'] = json_decode(json_encode($oConfig->files->preview->filename), TRUE)[0];
} else {
$aQuestionTemplates[$file]['preview'] = \LimeSurvey\Helpers\questionHelper::getQuestionThemePreviewUrl($type);
$fileName = json_decode(json_encode($oConfig->files->preview->filename), TRUE)[0];
$previewPath = $sFullPathToQuestionTemplate."/assets/".$fileName;
if(is_file($previewPath) && LSYii_ImageValidator::validateImage($previewPath)) {
$aQuestionTemplates[$file]['preview'] = App()->getAssetManager()->publish($previewPath);
} else {
/* Log it a theme.question.$oConfig->name as error, review ? */
Yii::log("Unable to use $fileName for preview in $sFullPathToQuestionTemplate/assets/",'error','theme.question.'.$oConfig->metadata->name);
}
}
if(empty($aQuestionTemplates[$file]['preview'])) {
$aQuestionTemplates[$file]['preview'] = $aQuestionTemplates['core']['preview'];
}
}
}
Expand Down

0 comments on commit f4eff57

Please sign in to comment.