Survey: Update from 1.11.x + fixes

pull/3733/head
Julio Montoya 4 years ago
parent 208786053b
commit 0f74ce72d7
  1. 53
      public/main/inc/lib/api.lib.php
  2. 4
      public/main/survey/survey.lib.php
  3. 1
      public/main/survey/survey.php
  4. 10
      public/main/survey/surveyUtil.class.php
  5. 1
      public/main/survey/survey_list.php
  6. 2
      src/CoreBundle/Repository/Node/UserRepository.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 <p><span lang="en">Some string</span></p><p><span lang="fr">Une chaîne</span></p>
* @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 <p><span ..>...</span></p> but others might be like combine 2 <span> in 1 <p>
if (!preg_match('/<span.*?lang="(\w\w)">/is', $htmlString)) {
return $htmlString;
}
$matches = [];
preg_match_all('/<span.*?lang="(\w\w)">(.*?)<\/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;
}

@ -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);

@ -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 .= '<tr><td>'.$row['name'].'</td><td>'.$row['description'].'</td><td>'.
'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.

@ -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,

@ -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);

@ -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);

Loading…
Cancel
Save