Fix survey question counter + add a page break when multiplying

BT#15033
pull/2729/head
Julio Montoya 8 years ago
parent 5ba578d4ee
commit b1143a0ef8
  1. 23
      main/survey/fillsurvey.php
  2. 55
      main/survey/preview.php
  3. 27
      main/survey/survey.lib.php
  4. 9
      main/survey/surveyUtil.class.php
  5. 3
      main/survey/survey_list.php

@ -663,6 +663,7 @@ if (
if (empty($paged_questions)) {
$sql = "SELECT * FROM $table_survey_question
WHERE
survey_question NOT LIKE '%{{%' AND
c_id = $course_id AND
survey_id = '".intval($survey_invitation['survey_id'])."'
ORDER BY sort ASC";
@ -1027,6 +1028,7 @@ if (
ON survey_question.question_id = survey_question_option.question_id AND
survey_question_option.c_id = $course_id
WHERE
survey_question NOT LIKE '%{{%' AND
survey_question.survey_id = '".$my_survey_id."' AND
survey_question.c_id = $course_id AND
survey_question.question_id IN (".implode(',', $paged_questions_sec[$val]).")
@ -1137,6 +1139,7 @@ if (
ON survey_question.question_id = survey_question_option.question_id AND
survey_question_option.c_id = $course_id
WHERE
survey_question NOT LIKE '%{{%' AND
survey_question.survey_id = '".intval($survey_invitation['survey_id'])."' AND
survey_question.c_id = $course_id AND
survey_question.question_id IN (".$imploded.")
@ -1183,7 +1186,7 @@ if (
$sql = "SELECT * FROM $table_survey_question
WHERE
c_id = $course_id AND
type = '".Database::escape_string('pagebreak')."' AND
type = 'pagebreak' AND
survey_id='".intval($survey_invitation['survey_id'])."'";
$result = Database::query($sql);
$numberofpages = Database::num_rows($result) + 1;
@ -1235,12 +1238,27 @@ $form = new FormValidator(
$form->addHidden('language', $p_l);
if (isset($questions) && is_array($questions)) {
$originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0;
$questionCounter = 1;
if (!empty($originalShow)) {
$before = 0;
foreach ($paged_questions as $keyQuestion => $list) {
if ($originalShow > $keyQuestion) {
$before += count($list);
}
}
$questionCounter = $before + 1;
}
foreach ($questions as $key => &$question) {
$ch_type = 'ch_'.$question['type'];
//$questionNumber = $question['sort'];
$questionNumber = $questionCounter;
$display = new $ch_type();
// @todo move this in a function.
$form->addHtml('<div class="survey_question '.$ch_type.'">');
$form->addHtml('<h5 class="title">'.$question['sort'].'. '.strip_tags($question['survey_question']).'</h5>');
$form->addHtml('<h5 class="title">'.$questionNumber.'. '.strip_tags($question['survey_question']).'</h5>');
$userAnswerData = SurveyUtil::get_answers_of_question_by_user($question['survey_id'], $question['question_id']);
$finalAnswer = null;
@ -1267,6 +1285,7 @@ if (isset($questions) && is_array($questions)) {
}
$display->render($form, $question, $finalAnswer);
$form->addHtml('</div>');
$questionCounter++;
}
}

@ -83,7 +83,7 @@ if ($surveyAnonymous == 0 && api_is_anonymous()) {
api_not_allowed(true);
}
}
// Header
Display::display_header(get_lang('SurveyPreview'));
// We exit here is the first or last question is a pagebreak (which causes errors)
@ -144,6 +144,16 @@ if (api_is_course_admin() ||
$questions_exists = false;
}
$sql = "SELECT count(survey_question.question_id) as count
FROM $table_survey_question survey_question
WHERE
survey_question.survey_id = '".$surveyId."' AND
survey_question.c_id = $course_id AND
survey_question LIKE '%{{%' ";
$result = Database::query($sql);
$sourceQuestions = Database::fetch_array($result, 'ASSOC');
$sourceQuestions = $sourceQuestions['count'];
if (array_key_exists($_GET['show'], $paged_questions)) {
$sql = "SELECT
survey_question.question_id,
@ -165,23 +175,24 @@ if (api_is_course_admin() ||
survey_question.survey_id = '".$surveyId."' AND
survey_question.question_id IN (".Database::escape_string(implode(',', $paged_questions[$_GET['show']]), null, false).") AND
survey_question.c_id = $course_id AND
survey_question NOT LIKE '%{{%'
survey_question NOT LIKE '%{{%'
ORDER BY survey_question.sort, survey_question_option.sort ASC";
$result = Database::query($sql);
$question_counter_max = Database::num_rows($result);
$limit = 0;
while ($row = Database::fetch_array($result)) {
// If the type is not a pagebreak we store it in the $questions array
if ($row['type'] != 'pagebreak') {
$questions[$row['sort']]['question_id'] = $row['question_id'];
$questions[$row['sort']]['survey_id'] = $row['survey_id'];
$questions[$row['sort']]['survey_question'] = $row['survey_question'];
$questions[$row['sort']]['display'] = $row['display'];
$questions[$row['sort']]['type'] = $row['type'];
$questions[$row['sort']]['options'][intval($row['option_sort'])] = $row['option_text'];
$questions[$row['sort']]['maximum_score'] = $row['max_value'];
$sort = $row['sort'];
$questions[$sort]['question_id'] = $row['question_id'];
$questions[$sort]['survey_id'] = $row['survey_id'];
$questions[$sort]['survey_question'] = $row['survey_question'];
$questions[$sort]['display'] = $row['display'];
$questions[$sort]['type'] = $row['type'];
$questions[$sort]['options'][intval($row['option_sort'])] = $row['option_text'];
$questions[$sort]['maximum_score'] = $row['max_value'];
} else {
// If the type is a pagebreak we are finished loading the questions for this page
break;
@ -191,22 +202,27 @@ if (api_is_course_admin() ||
}
}
$before = 0;
if (isset($paged_questions[$_GET['show'] -1])) {
$before = count($paged_questions[$_GET['show'] -1]);
}
// Selecting the maximum number of pages
$sql = "SELECT * FROM $table_survey_question
WHERE
survey_question NOT LIKE '%{{%' AND
c_id = $course_id AND
type = '".Database::escape_string('pagebreak')."' AND
type = 'pagebreak' AND
survey_id = '".$surveyId."'";
$result = Database::query($sql);
$numberofpages = Database::num_rows($result) + 1;
// Displaying the form with the questions
$show = 0;
if (isset($_GET['show'])) {
$show = (int) $_GET['show'] + 1;
} else {
$show = 0;
}
$originalShow = isset($_GET['show']) ? (int) $_GET['show'] : 0;
$url = api_get_self().'?survey_id='.$surveyId.'&show='.$show.'&'.api_get_cidreq();
$form = new FormValidator(
@ -219,14 +235,25 @@ if (api_is_course_admin() ||
);
if (is_array($questions) && count($questions) > 0) {
$counter = 1;
if (!empty($originalShow)) {
$before = 0;
foreach ($paged_questions as $keyQuestion => $list) {
if ($originalShow > $keyQuestion) {
$before += count($list);
}
}
$counter = $before + 1;
}
foreach ($questions as $key => &$question) {
$ch_type = 'ch_'.$question['type'];
/** @var survey_question $display */
$display = new $ch_type();
$form->addHtml('<div class="survey_question '.$ch_type.'">');
$form->addHtml('<h5 class="title">'.$key.'. '.strip_tags($question['survey_question']).'</h5>');
$form->addHtml('<h5 class="title">'.$counter.'. '.strip_tags($question['survey_question']).'</h5>');
$display->render($form, $question);
$form->addHtml('</div>');
$counter++;
}
}
$form->addHtml('<div class="start-survey">');

@ -2138,10 +2138,15 @@ class SurveyManager
$classTag = '{{class_name}}';
$studentTag = '{{student_full_name}}';
$classCounter = 0;
foreach ($classList as $class) {
$className = $class['name'];
foreach ($questions as $question) {
$users = $obj->get_users_by_usergroup($class['id']);
if (empty($users)) {
continue;
}
$text = $question['question'];
if (strpos($text, $classTag) !== false) {
$replacedText = str_replace($classTag, $className, $text);
@ -2156,10 +2161,10 @@ class SurveyManager
'shared_question_id' => 0,
];
self::save_question($surveyData, $values);
$classCounter++;
continue;
}
$users = $obj->get_users_by_usergroup($class['id']);
//var_dump($question);
foreach ($users as $userId) {
$userInfo = api_get_user_info($userId);
@ -2188,6 +2193,22 @@ class SurveyManager
self::save_question($surveyData, $values);
}
}
if ($classCounter < count($classList)) {
// Add end page
$values = [
'c_id' => $courseId,
'question_comment' => 'generated',
'type' => 'pagebreak',
'display' => 'horizontal',
'question' => get_lang('QuestionForNextClass'),
'survey_id' => $surveyId,
'question_id' => 0,
'shared_question_id' => 0,
];
self::save_question($surveyData, $values);
}
}
}
}

@ -2893,8 +2893,9 @@ class SurveyUtil
$actions[] = Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
$codePath.'survey/create_new_survey.php?'
.http_build_query($params + ['action' => 'edit', 'survey_id' => $survey_id])
.http_build_query($params + ['action' => 'edit', 'survey_id' => $survey_id])
);
if (SurveyManager::survey_generation_hash_available()) {
$actions[] = Display::url(
Display::return_icon('new_link.png', get_lang('GenerateSurveyAccessLink')),
@ -2937,12 +2938,14 @@ class SurveyUtil
);
}
}
if ($type != 3) {
$actions[] = Display::url(
Display::return_icon('preview_view.png', get_lang('Preview')),
$codePath.'survey/preview.php?'.http_build_query($params + ['survey_id' => $survey_id])
);
}
$actions[] = Display::url(
Display::return_icon('mail_send.png', get_lang('Publish')),
$codePath.'survey/survey_invite.php?'.http_build_query($params + ['survey_id' => $survey_id])
@ -2959,9 +2962,9 @@ class SurveyUtil
$actions[] = Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
$codePath.'survey/survey_list.php?'
.http_build_query($params + ['action' => 'delete', 'survey_id' => $survey_id]),
.http_build_query($params + ['action' => 'delete', 'survey_id' => $survey_id]),
[
'onclick' => "javascript: if(!confirm('".$warning."')) return false;",
'onclick' => "javascript: if (!confirm('".$warning."')) return false;",
]
);
}

@ -81,7 +81,7 @@ switch ($action) {
$surveyData = SurveyManager::get_survey($surveyId);
if (!empty($surveyData)) {
SurveyManager::removeMultiplicateQuestions($surveyData);
Display::addFlash(Display::return_message(get_lang('Removed'), 'confirmation', false));
Display::addFlash(Display::return_message(get_lang('Updated'), 'confirmation', false));
}
header('Location: '.$listUrl);
exit;
@ -90,6 +90,7 @@ 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);

Loading…
Cancel
Save