Add button to go to course homepage when finishing survey - refs BT#12915

1.10.x
Angel Fernando Quiroz Campos 8 years ago
parent 59a648fcde
commit bdc496e74a
  1. 158
      main/survey/preview.php

@ -22,6 +22,7 @@ $table_user = Database:: get_main_table(TABLE_MAIN_USER);
$table_survey_invitation = Database:: get_course_table(TABLE_SURVEY_INVITATION); $table_survey_invitation = Database:: get_course_table(TABLE_SURVEY_INVITATION);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$courseInfo = $course_id ? api_get_course_info_by_id($course_id) : [];
$userId = api_get_user_id(); $userId = api_get_user_id();
$surveyId = intval($_GET['survey_id']); $surveyId = intval($_GET['survey_id']);
$userInvited = 0; $userInvited = 0;
@ -150,87 +151,96 @@ if (api_is_course_admin() ||
survey_question.sort, survey_question.sort,
survey_question.type, survey_question.type,
survey_question.max_value, survey_question.max_value,
survey_question_option.question_option_id, survey_question_option.question_option_id,
survey_question_option.option_text, survey_question_option.option_text,
survey_question_option.sort as option_sort survey_question_option.sort as option_sort
FROM $table_survey_question survey_question FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option LEFT JOIN $table_survey_question_option survey_question_option
ON ON
survey_question.question_id = survey_question_option.question_id AND survey_question.question_id = survey_question_option.question_id AND
survey_question_option.c_id = $course_id survey_question_option.c_id = $course_id
WHERE WHERE
survey_question.survey_id = '".intval($survey_id)."' AND survey_question.survey_id = '".$survey_id."' AND
survey_question.question_id IN (".Database::escape_string(implode(',',$paged_questions[$_GET['show']]), null, false).") AND survey_question.question_id IN (".Database::escape_string(implode(',', $paged_questions[$_GET['show']]), null, false).") AND
survey_question.c_id = $course_id survey_question.c_id = $course_id
ORDER BY survey_question.sort, survey_question_option.sort ASC"; ORDER BY survey_question.sort, survey_question_option.sort ASC";
$result = Database::query($sql); $result = Database::query($sql);
$question_counter_max = Database::num_rows($result); $question_counter_max = Database::num_rows($result);
$limit = 0; $limit = 0;
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
// If the type is not a pagebreak we store it in the $questions array // If the type is not a pagebreak we store it in the $questions array
if ($row['type'] != 'pagebreak') { if ($row['type'] != 'pagebreak') {
$questions[$row['sort']]['question_id'] = $row['question_id']; $questions[$row['sort']]['question_id'] = $row['question_id'];
$questions[$row['sort']]['survey_id'] = $row['survey_id']; $questions[$row['sort']]['survey_id'] = $row['survey_id'];
$questions[$row['sort']]['survey_question'] = $row['survey_question']; $questions[$row['sort']]['survey_question'] = $row['survey_question'];
$questions[$row['sort']]['display'] = $row['display']; $questions[$row['sort']]['display'] = $row['display'];
$questions[$row['sort']]['type'] = $row['type']; $questions[$row['sort']]['type'] = $row['type'];
$questions[$row['sort']]['options'][intval($row['option_sort'])] = $row['option_text']; $questions[$row['sort']]['options'][intval($row['option_sort'])] = $row['option_text'];
$questions[$row['sort']]['maximum_score'] = $row['max_value']; $questions[$row['sort']]['maximum_score'] = $row['max_value'];
} else { } else {
// If the type is a pagebreak we are finished loading the questions for this page // If the type is a pagebreak we are finished loading the questions for this page
break; break;
} }
$counter_question++; $counter_question++;
} }
} }
} }
// Selecting the maximum number of pages
$sql = "SELECT * FROM $table_survey_question
WHERE
c_id = $course_id AND
type='".Database::escape_string('pagebreak')."' AND
survey_id='".intval($survey_id)."'";
$result = Database::query($sql);
$numberofpages = Database::num_rows($result) + 1;
// Displaying the form with the questions // Selecting the maximum number of pages
if (isset($_GET['show'])) { $sql = "SELECT * FROM $table_survey_question
$show = (int)$_GET['show'] + 1; WHERE
} else { c_id = $course_id AND
$show = 0; type='".Database::escape_string('pagebreak')."' AND
} survey_id='".$survey_id."'";
$result = Database::query($sql);
$numberofpages = Database::num_rows($result) + 1;
// Displaying the form with the questions
if (isset($_GET['show'])) {
$show = (int) $_GET['show'] + 1;
} else {
$show = 0;
}
$url = api_get_self().'?survey_id='.Security::remove_XSS($survey_id).'&show='.$show; $url = api_get_self().'?survey_id='.$survey_id.'&show='.$show;
$form = new FormValidator('question', 'post', $url); $form = new FormValidator('question-survey', 'post', $url, null, null, FormValidator::LAYOUT_INLINE);
if (is_array($questions) && count($questions) > 0) { if (is_array($questions) && count($questions) > 0) {
foreach ($questions as $key => & $question) { foreach ($questions as $key => & $question) {
$ch_type = 'ch_'.$question['type']; $ch_type = 'ch_'.$question['type'];
/** @var survey_question $display */ /** @var survey_question $display */
$display = new $ch_type; $display = new $ch_type;
$form->addHtml('<div class="survey_question_wrapper"><div class="survey_question">'); $form->addHtml('<div class="survey_question_wrapper"><div class="survey_question">');
$form->addHtml($question['survey_question']); $form->addHtml($question['survey_question']);
$display->render($form, $question); $display->render($form, $question);
$form->addHtml('</div></div>'); $form->addHtml('</div></div>');
} }
} }
if (($show < $numberofpages) || (!$_GET['show'] && count($questions) > 0)) { if (($show < $numberofpages) || (!$_GET['show'] && count($questions) > 0)) {
if ($show == 0) { if ($show == 0) {
$form->addButton('next_survey_page', get_lang('StartSurvey'), 'arrow-right', 'success', 'large'); $form->addButton('next_survey_page', get_lang('StartSurvey'), 'arrow-right', 'success', 'large');
} else { } else {
$form->addButton('next_survey_page', get_lang('NextQuestion'), 'arrow-right'); $form->addButton('next_survey_page', get_lang('NextQuestion'), 'arrow-right');
} }
} }
if ($show >= $numberofpages && $_GET['show'] || (isset($_GET['show']) && count($questions) == 0)) {
if ($questions_exists == false) { if ($show >= $numberofpages && $_GET['show'] || (isset($_GET['show']) && count($questions) == 0)) {
echo '<p>'.get_lang('ThereAreNotQuestionsForthisSurvey').'</p>'; if ($questions_exists == false) {
echo '<p>'.get_lang('ThereAreNotQuestionsForthisSurvey').'</p>';
} }
$form->addButton('finish_survey', get_lang('FinishSurvey'), 'arrow-right'); $form->addButton('finish_survey', get_lang('FinishSurvey'), 'arrow-right', 'success');
} }
$form->display(); $form->display();
if ($courseInfo) {
echo '<br><p>'.Display::toolbarButton(
get_lang('ReturnToCourseHomepage'),
api_get_course_url($courseInfo['code']),
'home'
).'</p>';
}
} else { } else {
Display :: display_error_message(get_lang('NotAllowed'), false); Display :: display_error_message(get_lang('NotAllowed'), false);
} }

Loading…
Cancel
Save