From 48db928b14f0552e75cc125a6f32965dfa4dc8d4 Mon Sep 17 00:00:00 2001 From: Imanol Losada Date: Thu, 12 Mar 2015 11:17:33 -0500 Subject: [PATCH] Add 'Questions overall report' to survey reports list - refs #7170 --- main/css/base.css | 10 +- main/survey/reporting.php | 6 +- main/survey/survey.lib.php | 243 ++++++++++++++++++++----------------- 3 files changed, 139 insertions(+), 120 deletions(-) diff --git a/main/css/base.css b/main/css/base.css index 6f436db91b..b0beb14edc 100755 --- a/main/css/base.css +++ b/main/css/base.css @@ -5277,23 +5277,23 @@ i.size-32.icon-new-work{ .title-question{ font-size: 22px; } -#display-survey.table tbody tr th, #display-survey.table tbody tr:hover th{ +.display-survey.table tbody tr th, .display-survey.table tbody tr:hover th{ background-color:#666; text-align: center; font-size: 14px; color: #FFFFFF; } -#display-survey .total{ +.display-survey .total{ background-color: #EBF3F5; text-align: center; } -#display-survey .center{ +.display-survey .center{ text-align: center; } -#display-survey{ +.display-survey{ border: 1px solid #ddd; } -#display-survey.table tbody tr:hover td,#display-survey.table tbody tr:hover th{ +.display-survey.table tbody tr:hover td,.display-survey.table tbody tr:hover th{ background-color: none; } .answered-people{ diff --git a/main/survey/reporting.php b/main/survey/reporting.php index f30ac6cc18..7261fc95a1 100755 --- a/main/survey/reporting.php +++ b/main/survey/reporting.php @@ -124,7 +124,8 @@ if (!isset($_GET['action']) || isset($_GET['action']) && $_GET['action'] == 'ove ); switch ($_GET['action']) { case 'questionreport': - $tool_name = get_lang('DetailedReportByQuestion'); + $singlePage = isset($_GET['single_page']) ? intval($_GET['single_page']) : 0; + $tool_name = $singlePage ? get_lang('QuestionsOverallReport') : get_lang('DetailedReportByQuestion'); break; case 'userreport': $tool_name = get_lang('DetailedReportByUser'); @@ -154,7 +155,8 @@ echo ''; if (!isset($_GET['action']) || isset($_GET['action']) && $_GET['action'] == 'overview') { $myweb_survey_id = $survey_id; - echo '
'.Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'
'.get_lang('DetailedReportByQuestionDetail').'
'; + echo '
'.Display::return_icon('survey_reporting_question.gif',get_lang('QuestionsOverallReport')).' '.get_lang('QuestionsOverallReport').'
'.get_lang('QuestionsOverallReportDetail').'
'; + echo '
'.Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'
'.get_lang('DetailedReportByQuestionDetail').'
'; echo '
'.Display::return_icon('survey_reporting_user.gif',get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'
'.get_lang('DetailedReportByUserDetail').'.
'; echo '
'.Display::return_icon('survey_reporting_comparative.gif',get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'
'.get_lang('ComparativeReportDetail').'.
'; echo '
'.Display::return_icon('survey_reporting_complete.gif',get_lang('CompleteReport')).' '.get_lang('CompleteReport').'
'.get_lang('CompleteReportDetail').'
'; diff --git a/main/survey/survey.lib.php b/main/survey/survey.lib.php index 5fab3e4373..2fa7f5b93c 100755 --- a/main/survey/survey.lib.php +++ b/main/survey/survey.lib.php @@ -1955,6 +1955,7 @@ class SurveyUtil */ public static function display_question_report($survey_data) { + $singlePage = isset($_GET['single_page']) ? intval($_GET['single_page']) : 0; $course_id = api_get_course_int_id(); // Database table definitions $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); @@ -1964,7 +1965,7 @@ class SurveyUtil // Determining the offset of the sql statement (the n-th question of the survey) $offset = !isset($_GET['question']) ? 0 : intval($_GET['question']); $currentQuestion = isset($_GET['question']) ? intval($_GET['question']) : 0; - $question = array(); + $questions = array(); $surveyId = intval($_GET['survey_id']); $action = Security::remove_XSS($_GET['action']); @@ -1974,12 +1975,14 @@ class SurveyUtil echo ''; if ($survey_data['number_of_questions'] > 0) { - echo ''; // Getting the question information $sql = "SELECT * FROM $table_survey_question @@ -2004,9 +2009,13 @@ class SurveyUtil survey_id='".Database::escape_string($_GET['survey_id'])."' AND type<>'pagebreak' AND type<>'comment' ORDER BY sort ASC - LIMIT ".$offset.",1"; + $limitStatement"; $result = Database::query($sql); - $question = Database::fetch_array($result); + //$question = Database::fetch_array($result); + + while ($row = Database::fetch_array($result)) { + $questions[$row['question_id']] = $row; + } // Navigate through the questions (next and previous) /*if ($currentQuestion != 0 ) { @@ -2022,124 +2031,132 @@ class SurveyUtil echo get_lang('NextQuestion').' '.Display::return_icon('action_next.png', get_lang('NextQuestion'), array('align' => 'middle')); }*/ } - echo '
'; + + $htmlHeadXtra[] = ''; + + foreach ($questions as $question) { + $chartData = array(); + $options = array(); + echo '
'; echo strip_tags(isset($question['survey_question']) ? $question['survey_question'] : null); - echo '
'; - if ($question['type'] == 'score') { - /** @todo This function should return the options as this is needed further in the code */ - $options = SurveyUtil::display_question_report_score($survey_data, $question, $offset); - } elseif ($question['type'] == 'open') { - /** @todo Also get the user who has answered this */ - $sql = "SELECT * FROM $table_survey_answer + echo '
'; + + if ($question['type'] == 'score') { + /** @todo This function should return the options as this is needed further in the code */ + $options = SurveyUtil::display_question_report_score($survey_data, $question, $offset); + } elseif ($question['type'] == 'open') { + /** @todo Also get the user who has answered this */ + $sql = "SELECT * FROM $table_survey_answer WHERE c_id = $course_id AND - survey_id='".Database::escape_string($_GET['survey_id'])."' AND - question_id = '".Database::escape_string($question['question_id'])."'"; - $result = Database::query($sql); - while ($row = Database::fetch_array($result)) { - echo $row['option_id'].'
'; - } - } else { - // Getting the options - $sql = "SELECT * FROM $table_survey_question_option + survey_id='" . Database::escape_string($_GET['survey_id']) . "' AND + question_id = '" . Database::escape_string($question['question_id']) . "'"; + $result = Database::query($sql); + while ($row = Database::fetch_array($result)) { + echo $row['option_id'] . '
'; + } + } else { + // Getting the options ORDER BY sort ASC + $sql = "SELECT * FROM $table_survey_question_option WHERE - c_id = $course_id AND survey_id='".Database::escape_string($_GET['survey_id'])."' AND - question_id = '".Database::escape_string($question['question_id'])."' + c_id = $course_id AND + survey_id='" . Database::escape_string($_GET['survey_id']) . "' + AND question_id = '" . Database::escape_string($question['question_id']) . "' ORDER BY sort ASC"; - $result = Database::query($sql); - while ($row = Database::fetch_array($result)) { - $options[$row['question_option_id']] = $row; - } - // Getting the answers - $sql = "SELECT *, count(answer_id) as total FROM $table_survey_answer + $result = Database::query($sql); + while ($row = Database::fetch_array($result)) { + $options[$row['question_option_id']] = $row; + } + // Getting the answers + $sql = "SELECT *, count(answer_id) as total FROM $table_survey_answer WHERE c_id = $course_id AND - survey_id='".Database::escape_string($_GET['survey_id'])."' AND - question_id = '".Database::escape_string($question['question_id'])."' + survey_id='" . Database::escape_string($_GET['survey_id']) . "' + AND question_id = '" . Database::escape_string($question['question_id']) . "' GROUP BY option_id, value"; - $result = Database::query($sql); - $number_of_answers = 0; - $data = array(); - while ($row = Database::fetch_array($result)) { - $number_of_answers += $row['total']; - $data[$row['option_id']] = $row; - } + $result = Database::query($sql); + $number_of_answers = array(); + $data = array(); + while ($row = Database::fetch_array($result)) { + if (!isset($number_of_answers[$row['question_id']])) { + $number_of_answers[$row['question_id']] = 0; + } + $number_of_answers[$row['question_id']] += $row['total']; + $data[$row['option_id']] = $row; + } - $chartData = array(); - foreach ($options as $option) { - $optionText = strip_tags($option['option_text']); - $optionText = html_entity_decode($optionText); - $votes = $data[$option['question_option_id']]['total']; - if (empty($votes)) { - $votes = '0'; + foreach ($options as $option) { + $optionText = strip_tags($option['option_text']); + $optionText = html_entity_decode($optionText); + $votes = isset($data[$option['question_option_id']]['total']) ? + $data[$option['question_option_id']]['total'] : + '0'; + array_push($chartData, array('option' => $optionText, 'votes' => $votes)); } - array_push($chartData, array('option' => $optionText, 'votes' => $votes)); - } - echo '
'; - echo self::drawChart($chartData); - echo '
'; + $chartContainerId = 'chartContainer'.$question['question_id']; + echo '
'; + echo self::drawChart($chartData, false, $chartContainerId); - $htmlHeadXtra[] = ''; + // displaying the table: headers - // displaying the table: headers + echo ''; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; - echo '
 ' . get_lang('AbsoluteTotal') . '' . get_lang('Percentage') . '' . get_lang('VisualRepresentation') . '
'; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; + // Displaying the table: the content + if (is_array($options)) { + foreach ($options as $key => & $value) { + $absolute_number = null; + if (isset($data[$value['question_option_id']])) { + $absolute_number = $data[$value['question_option_id']]['total']; + } + if ($question['type'] == 'percentage' && empty($absolute_number)) { + continue; + } + if ($number_of_answers[$option['question_id']] == 0) { + $answers_number = 0; + } else { + $answers_number = $absolute_number / $number_of_answers[$option['question_id']] * 100; + } + echo ' '; + echo ' '; + echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; + echo ' '; + echo ' '; + echo ' '; } - echo ' '; - echo ' '; } - } - // displaying the table: footer (totals) - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; + // displaying the table: footer (totals) + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; - echo '
 '.get_lang('AbsoluteTotal').''.get_lang('Percentage').''.get_lang('VisualRepresentation').'
' . $value['option_text'] . ''; + if ($absolute_number != 0) { + echo '' . $absolute_number . ''; + } else { + echo '0'; + } - // Displaying the table: the content - if (is_array($options)) { - foreach ($options as $key => & $value) { - $absolute_number = null; - if (isset($data[$value['question_option_id']])) { - $absolute_number = $data[$value['question_option_id']]['total']; - } - if ($question['type'] == 'percentage' && empty($absolute_number)) { - continue; - } - if ($number_of_answers == 0) { - $answers_number = 0; - } else { - $answers_number = $absolute_number/$number_of_answers*100; - } - echo '
'.$value['option_text'].''; - if ($absolute_number!=0){ - echo ''.$absolute_number.''; - }else{ - echo '0'; - } - - echo ' '.round($answers_number, 2).' %'; - $size = $answers_number*2; - if ($size > 0) { - echo '
 
'; - }else{ - echo '
'.get_lang("NoDataAvailable").'
'; + echo '
' . round($answers_number, 2) . ' %'; + $size = $answers_number * 2; + if ($size > 0) { + echo '
 
'; + } else { + echo '
' . get_lang("NoDataAvailable") . '
'; + } + echo '
'.get_lang('Total').''.($number_of_answers==0?'0':$number_of_answers).'  
' . get_lang('Total') . '' . ($number_of_answers[$option['question_id']] == 0 ? '0' : $number_of_answers[$option['question_id']]) . '  
'; + echo ''; + echo '
'; + } } - if (isset($_GET['viewoption'])) { echo '
'; @@ -4392,14 +4409,14 @@ class SurveyUtil * @param boolean Tells if the chart has a serie. False by default * @return void (direct output) */ - public static function drawChart($chartData, $hasSerie = false) + public static function drawChart($chartData, $hasSerie = false, $chartContainerId = 'chartContainer') { $htmlChart = ''; if (api_browser_support("svg")) { $htmlChart .= api_get_js("d3/d3.v3.5.4.min.js"); $htmlChart .= api_get_js("dimple.v2.1.2.min.js") . '