From 0f74ce72d740ce11807cf940c6065df2e9c6ff77 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 23 Dec 2020 14:25:29 +0100 Subject: [PATCH] Survey: Update from 1.11.x + fixes --- public/main/inc/lib/api.lib.php | 53 +++++++++++++++++++ public/main/survey/survey.lib.php | 4 +- public/main/survey/survey.php | 1 + public/main/survey/surveyUtil.class.php | 10 ++-- public/main/survey/survey_list.php | 1 - .../Repository/Node/UserRepository.php | 2 +- 6 files changed, 63 insertions(+), 8 deletions(-) diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index 6c7e592267..db70903c8e 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -8594,3 +8594,56 @@ function api_get_language_translate_html() }); '; } + +/** + * Filter a multi-language HTML string (for the multi-language HTML + * feature) into the given language (strip the rest). + * + * @param string $htmlString The HTML string to "translate". Usually

Some string

Une chaƮne

+ * @param string $language The language in which we want to get the + * + * @throws Exception + * + * @return string The filtered string in the given language, or the full string if no translated string was identified + */ +function api_get_filtered_multilingual_HTML_string($htmlString, $language = null) +{ + if (api_get_configuration_value('translate_html') != true) { + return $htmlString; + } + $userInfo = api_get_user_info(); + $languageId = 0; + if (!empty($language)) { + $languageId = api_get_language_id($language); + } elseif (!empty($userInfo['language'])) { + $languageId = api_get_language_id($userInfo['language']); + } + $languageInfo = api_get_language_info($languageId); + $isoCode = 'en'; + + if (!empty($languageInfo)) { + $isoCode = $languageInfo['isocode']; + } + + // Split HTML in the separate language strings + // Note: some strings might look like

...

but others might be like combine 2 in 1

+ if (!preg_match('//is', $htmlString)) { + return $htmlString; + } + $matches = []; + preg_match_all('/(.*?)<\/span>/is', $htmlString, $matches); + if (!empty($matches)) { + // matches[0] are the full string + // matches[1] are the languages + // matches[2] are the strings + foreach ($matches[1] as $id => $match) { + if ($match == $isoCode) { + return $matches[2][$id]; + } + } + // Could find the pattern but could not find our language. Return the first language found. + return $matches[2][0]; + } + // Could not find pattern. Just return the whole string. We shouldn't get here. + return $htmlString; +} diff --git a/public/main/survey/survey.lib.php b/public/main/survey/survey.lib.php index 3cd1212d1c..f5db1fd31d 100644 --- a/public/main/survey/survey.lib.php +++ b/public/main/survey/survey.lib.php @@ -673,13 +673,13 @@ class SurveyManager self::delete_all_survey_questions($survey_id, $shared); // Update into item_property (delete) - api_item_property_update( + /*api_item_property_update( $course_info, TOOL_SURVEY, $survey_id, 'SurveyDeleted', api_get_user_id() - ); + );*/ Skill::deleteSkillsFromItem($survey_id, ITEM_TYPE_SURVEY); diff --git a/public/main/survey/survey.php b/public/main/survey/survey.php index 7a4364a472..f3f90dbd30 100644 --- a/public/main/survey/survey.php +++ b/public/main/survey/survey.php @@ -447,6 +447,7 @@ if ($is_survey_type_1) { ORDER BY name'; $rs = Database::query($sql); + $grouplist = ''; while ($row = Database::fetch_array($rs, 'ASSOC')) { $grouplist .= ''.$row['name'].''.$row['description'].''. ''. diff --git a/public/main/survey/surveyUtil.class.php b/public/main/survey/surveyUtil.class.php index c671fcc283..b4b37a8568 100644 --- a/public/main/survey/surveyUtil.class.php +++ b/public/main/survey/surveyUtil.class.php @@ -1938,9 +1938,11 @@ class SurveyUtil ); // this is to display the last user - foreach ($return as $elem) { - $list[$line][$column] = $elem; - $column++; + if (!empty($return)) { + foreach ($return as $elem) { + $list[$line][$column] = $elem; + $column++; + } } Export::arrayToXls($list, $filename); @@ -1956,7 +1958,7 @@ class SurveyUtil * @param mixed User ID or user details as string - Used as a string in the result string * @param bool Whether to display user fields or not * - * @return string One line of the csv file + * @return array */ public static function export_complete_report_row_xls( $survey_data, diff --git a/public/main/survey/survey_list.php b/public/main/survey/survey_list.php index 2de2c6fc3d..1bd6f1068d 100644 --- a/public/main/survey/survey_list.php +++ b/public/main/survey/survey_list.php @@ -476,7 +476,6 @@ switch ($action) { $surveyData = SurveyManager::get_survey($surveyId); if (!empty($surveyData)) { SurveyManager::multiplicateQuestions($surveyData); - Display::cleanFlashMessages(); Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false)); } header('Location: '.$listUrl); diff --git a/src/CoreBundle/Repository/Node/UserRepository.php b/src/CoreBundle/Repository/Node/UserRepository.php index 267f0cef60..862b4551e9 100644 --- a/src/CoreBundle/Repository/Node/UserRepository.php +++ b/src/CoreBundle/Repository/Node/UserRepository.php @@ -1122,7 +1122,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface, /** @var CSurveyAnswer $item */ foreach ($result as $item) { $list = [ - 'Answer # '.$item->getAnswerId(), + 'Answer # '.$item->getIid(), 'Value: '.$item->getValue(), ]; $cSurveyAnswer[] = implode(', ', $list);