Admin: Add config survey_duplicate_order_by_name see BT#18183

Survey duplicate: Order survey questions by student name
// $_configuration['survey_duplicate_order_by_name'] = true;
pull/3694/head
Julio Montoya 5 years ago
parent eac5245528
commit ebf7c28ddd
  1. 3
      main/install/configuration.dist.php
  2. 18
      main/survey/survey.lib.php

@ -1796,6 +1796,9 @@ $_configuration['auth_password_links'] = [
// For a student: Shows only the list of teachers from my courses in the Chamilo inbox.
// $_configuration['send_only_messages_to_teachers'] = true;
// Survey duplicate: Order survey questions by student name
// $_configuration['survey_duplicate_order_by_name'] = true;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

@ -2471,16 +2471,29 @@ class SurveyManager
$classTag = '{{class_name}}';
$studentTag = '{{student_full_name}}';
$classCounter = 0;
$newQuestionList = [];
foreach ($questions as $question) {
$newQuestionList[$question['sort']] = $question;
}
ksort($newQuestionList);
$order = api_get_configuration_value('survey_duplicate_order_by_name');
foreach ($itemList as $class) {
$className = $class['name'];
$users = $class['users'];
$userInfoList = [];
foreach ($users as $userId) {
$userInfoList[] = api_get_user_info($userId);
}
if ($order) {
usort(
$userInfoList,
function ($a, $b) {
return $a['lastname'] > $b['lastname'];
}
);
}
foreach ($newQuestionList as $question) {
$text = $question['question'];
@ -2503,8 +2516,7 @@ class SurveyManager
continue;
}
foreach ($users as $userId) {
$userInfo = api_get_user_info($userId);
foreach ($userInfoList as $userInfo) {
if (false !== strpos($text, $studentTag)) {
$replacedText = str_replace($studentTag, $userInfo['complete_name'], $text);
$values = [

Loading…
Cancel
Save