Merge branch '7170' of https://github.com/ilosada/chamilo-lms into ilosada-7170

1.10.x
Yannick Warnier 11 years ago
commit f23eb45f59
  1. 10
      main/css/base.css
  2. 13
      main/survey/reporting.php
  3. 243
      main/survey/survey.lib.php

@ -5066,23 +5066,23 @@ i.size-32.icon-new-work{
.title-question{ .title-question{
font-size: 22px; 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; background-color:#666;
text-align: center; text-align: center;
font-size: 14px; font-size: 14px;
color: #FFFFFF; color: #FFFFFF;
} }
#display-survey .total{ .display-survey .total{
background-color: #EBF3F5; background-color: #EBF3F5;
text-align: center; text-align: center;
} }
#display-survey .center{ .display-survey .center{
text-align: center; text-align: center;
} }
#display-survey{ .display-survey{
border: 1px solid #ddd; 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; background-color: none;
} }
.answered-people{ .answered-people{

@ -129,7 +129,8 @@ if (!isset($_GET['action']) || isset($_GET['action']) && $_GET['action'] == 'ove
); );
switch ($_GET['action']) { switch ($_GET['action']) {
case 'questionreport': 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; break;
case 'userreport': case 'userreport':
$tool_name = get_lang('DetailedReportByUser'); $tool_name = get_lang('DetailedReportByUser');
@ -161,13 +162,15 @@ if (!isset($_GET['action']) ||
$_GET['action'] == 'overview' $_GET['action'] == 'overview'
) { ) {
$myweb_survey_id = $survey_id; $myweb_survey_id = $survey_id;
echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'&'.api_get_cidreq().'">'. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'&amp;'.$cidReq.'&amp;single_page=1">'.
Display::return_icon('survey_reporting_question.gif',get_lang('QuestionsOverallReport')).' '.get_lang('QuestionsOverallReport').'</a></div><div class="sectioncomment">'.get_lang('QuestionsOverallReportDetail').' </div>';
echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>'; Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>';
echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'&'.api_get_cidreq().'">'. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
Display::return_icon('survey_reporting_user.gif',get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>'; Display::return_icon('survey_reporting_user.gif',get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>';
echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'&'.api_get_cidreq().'">'. echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
Display::return_icon('survey_reporting_comparative.gif',get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>'; Display::return_icon('survey_reporting_comparative.gif',get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>';
echo '<div class="sectiontitle"><a href="reporting.php?action=completereport&amp;survey_id='.$myweb_survey_id.'&'.api_get_cidreq().'">'. echo '<div class="sectiontitle"><a href="reporting.php?action=completereport&amp;survey_id='.$myweb_survey_id.'&'.$cidReq.'">'.
Display::return_icon('survey_reporting_complete.gif',get_lang('CompleteReport')).' '.get_lang('CompleteReport').'</a></div><div class="sectioncomment">'.get_lang('CompleteReportDetail').'</div>'; Display::return_icon('survey_reporting_complete.gif',get_lang('CompleteReport')).' '.get_lang('CompleteReport').'</a></div><div class="sectioncomment">'.get_lang('CompleteReportDetail').'</div>';
} }

@ -1957,6 +1957,7 @@ class SurveyUtil
*/ */
public static function display_question_report($survey_data) 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(); $course_id = api_get_course_int_id();
// Database table definitions // Database table definitions
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
@ -1966,7 +1967,7 @@ class SurveyUtil
// Determining the offset of the sql statement (the n-th question of the survey) // Determining the offset of the sql statement (the n-th question of the survey)
$offset = !isset($_GET['question']) ? 0 : intval($_GET['question']); $offset = !isset($_GET['question']) ? 0 : intval($_GET['question']);
$currentQuestion = isset($_GET['question']) ? intval($_GET['question']) : 0; $currentQuestion = isset($_GET['question']) ? intval($_GET['question']) : 0;
$question = array(); $questions = array();
$surveyId = intval($_GET['survey_id']); $surveyId = intval($_GET['survey_id']);
$action = Security::remove_XSS($_GET['action']); $action = Security::remove_XSS($_GET['action']);
@ -1976,12 +1977,14 @@ class SurveyUtil
echo '</div>'; echo '</div>';
if ($survey_data['number_of_questions'] > 0) { if ($survey_data['number_of_questions'] > 0) {
echo '<div id="question_report_questionnumbers" class="pagination">'; $limitStatement = null;
/* echo '<ul><li class="disabled"><a href="#">'.get_lang('Question').'</a></li>'; */ if (!$singlePage) {
echo '<div id="question_report_questionnumbers" class="pagination">';
/* echo '<ul><li class="disabled"><a href="#">'.get_lang('Question').'</a></li>'; */
if ($currentQuestion != 0 ) { if ($currentQuestion != 0) {
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.$action.'&amp;'.api_get_cidreq().'&amp;survey_id='.$surveyId.'&amp;question='.($offset-1).'">'.get_lang('PreviousQuestion').'</a></li>'; echo '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?action=' . $action . '&amp;' . api_get_cidreq() . '&amp;survey_id=' . $surveyId . '&amp;question=' . ($offset - 1) . '">' . get_lang('PreviousQuestion') . '</a></li>';
} }
for ($i = 1; $i <= $survey_data['number_of_questions']; $i++) { for ($i = 1; $i <= $survey_data['number_of_questions']; $i++) {
if ($offset != $i - 1) { if ($offset != $i - 1) {
@ -1993,11 +1996,13 @@ class SurveyUtil
echo ' | '; echo ' | ';
}*/ }*/
} }
if ($currentQuestion < ($survey_data['number_of_questions'] - 1)) { if ($currentQuestion < ($survey_data['number_of_questions'] - 1)) {
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.$action.'&amp;'.api_get_cidreq().'&amp;survey_id='.$surveyId.'&amp;question='.($offset+1).'">'.get_lang('NextQuestion').'</li></a>'; echo '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?action=' . $action . '&amp;' . api_get_cidreq() . '&amp;survey_id=' . $surveyId . '&amp;question=' . ($offset + 1) . '">' . get_lang('NextQuestion') . '</li></a>';
}
echo '</ul>';
echo '</div>';
$limitStatement = " LIMIT $offset, 1";
} }
echo '</ul>';
echo '</div>';
// Getting the question information // Getting the question information
$sql = "SELECT * FROM $table_survey_question $sql = "SELECT * FROM $table_survey_question
@ -2006,9 +2011,13 @@ class SurveyUtil
survey_id='".Database::escape_string($_GET['survey_id'])."' AND survey_id='".Database::escape_string($_GET['survey_id'])."' AND
type<>'pagebreak' AND type<>'comment' type<>'pagebreak' AND type<>'comment'
ORDER BY sort ASC ORDER BY sort ASC
LIMIT ".$offset.",1"; $limitStatement";
$result = Database::query($sql); $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) // Navigate through the questions (next and previous)
/*if ($currentQuestion != 0 ) { /*if ($currentQuestion != 0 ) {
@ -2024,124 +2033,132 @@ class SurveyUtil
echo get_lang('NextQuestion').' '.Display::return_icon('action_next.png', get_lang('NextQuestion'), array('align' => 'middle')); echo get_lang('NextQuestion').' '.Display::return_icon('action_next.png', get_lang('NextQuestion'), array('align' => 'middle'));
}*/ }*/
} }
echo '<div class="title-question">';
$htmlHeadXtra[] = '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
foreach ($questions as $question) {
$chartData = array();
$options = array();
echo '<div class="title-question">';
echo strip_tags(isset($question['survey_question']) ? $question['survey_question'] : null); echo strip_tags(isset($question['survey_question']) ? $question['survey_question'] : null);
echo '</div>'; echo '</div>';
if ($question['type'] == 'score') {
/** @todo This function should return the options as this is needed further in the code */ if ($question['type'] == 'score') {
$options = SurveyUtil::display_question_report_score($survey_data, $question, $offset); /** @todo This function should return the options as this is needed further in the code */
} elseif ($question['type'] == 'open') { $options = SurveyUtil::display_question_report_score($survey_data, $question, $offset);
/** @todo Also get the user who has answered this */ } elseif ($question['type'] == 'open') {
$sql = "SELECT * FROM $table_survey_answer /** @todo Also get the user who has answered this */
$sql = "SELECT * FROM $table_survey_answer
WHERE WHERE
c_id = $course_id AND c_id = $course_id AND
survey_id='".Database::escape_string($_GET['survey_id'])."' AND survey_id='" . Database::escape_string($_GET['survey_id']) . "' AND
question_id = '".Database::escape_string($question['question_id'])."'"; question_id = '" . Database::escape_string($question['question_id']) . "'";
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
echo $row['option_id'].'<hr noshade="noshade" size="1" />'; echo $row['option_id'] . '<hr noshade="noshade" size="1" />';
} }
} else { } else {
// Getting the options // Getting the options ORDER BY sort ASC
$sql = "SELECT * FROM $table_survey_question_option $sql = "SELECT * FROM $table_survey_question_option
WHERE WHERE
c_id = $course_id AND survey_id='".Database::escape_string($_GET['survey_id'])."' AND c_id = $course_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']) . "'
ORDER BY sort ASC"; ORDER BY sort ASC";
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
$options[$row['question_option_id']] = $row; $options[$row['question_option_id']] = $row;
} }
// Getting the answers // Getting the answers
$sql = "SELECT *, count(answer_id) as total FROM $table_survey_answer $sql = "SELECT *, count(answer_id) as total FROM $table_survey_answer
WHERE WHERE
c_id = $course_id AND c_id = $course_id AND
survey_id='".Database::escape_string($_GET['survey_id'])."' AND survey_id='" . Database::escape_string($_GET['survey_id']) . "'
question_id = '".Database::escape_string($question['question_id'])."' AND question_id = '" . Database::escape_string($question['question_id']) . "'
GROUP BY option_id, value"; GROUP BY option_id, value";
$result = Database::query($sql); $result = Database::query($sql);
$number_of_answers = 0; $number_of_answers = array();
$data = array(); $data = array();
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
$number_of_answers += $row['total']; if (!isset($number_of_answers[$row['question_id']])) {
$data[$row['option_id']] = $row; $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) {
foreach ($options as $option) { $optionText = strip_tags($option['option_text']);
$optionText = strip_tags($option['option_text']); $optionText = html_entity_decode($optionText);
$optionText = html_entity_decode($optionText); $votes = isset($data[$option['question_option_id']]['total']) ?
$votes = $data[$option['question_option_id']]['total']; $data[$option['question_option_id']]['total'] :
if (empty($votes)) { '0';
$votes = '0'; array_push($chartData, array('option' => $optionText, 'votes' => $votes));
} }
array_push($chartData, array('option' => $optionText, 'votes' => $votes)); $chartContainerId = 'chartContainer'.$question['question_id'];
} echo '<div id="'.$chartContainerId.'" class="span12">';
echo '<div id="chartContainer" class="span12">'; echo self::drawChart($chartData, false, $chartContainerId);
echo self::drawChart($chartData);
echo '</div>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>'; // displaying the table: headers
// displaying the table: headers echo '<table class="display-survey table">';
echo ' <tr>';
echo ' <th>&nbsp;</th>';
echo ' <th>' . get_lang('AbsoluteTotal') . '</th>';
echo ' <th>' . get_lang('Percentage') . '</th>';
echo ' <th>' . get_lang('VisualRepresentation') . '</th>';
echo ' <tr>';
echo '<table id="display-survey" class="table">'; // Displaying the table: the content
echo ' <tr>'; if (is_array($options)) {
echo ' <th>&nbsp;</th>'; foreach ($options as $key => & $value) {
echo ' <th>'.get_lang('AbsoluteTotal').'</th>'; $absolute_number = null;
echo ' <th>'.get_lang('Percentage').'</th>'; if (isset($data[$value['question_option_id']])) {
echo ' <th>'.get_lang('VisualRepresentation').'</th>'; $absolute_number = $data[$value['question_option_id']]['total'];
echo ' <tr>'; }
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 ' <tr>';
echo ' <td class="center">' . $value['option_text'] . '</td>';
echo ' <td class="center">';
if ($absolute_number != 0) {
echo '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?action=' . $action . '&amp;survey_id=' . $surveyId . '&amp;question=' . $offset . '&amp;viewoption=' . $value['question_option_id'] . '">' . $absolute_number . '</a>';
} else {
echo '0';
}
// Displaying the table: the content echo ' </td>';
if (is_array($options)) { echo ' <td class="center">' . round($answers_number, 2) . ' %</td>';
foreach ($options as $key => & $value) { echo ' <td class="center">';
$absolute_number = null; $size = $answers_number * 2;
if (isset($data[$value['question_option_id']])) { if ($size > 0) {
$absolute_number = $data[$value['question_option_id']]['total']; echo '<div style="border:1px solid #264269; background-color:#aecaf4; height:10px; width:' . $size . 'px">&nbsp;</div>';
} } else {
if ($question['type'] == 'percentage' && empty($absolute_number)) { echo '<div style="text-align: left;">' . get_lang("NoDataAvailable") . '</div>';
continue; }
} echo ' </td>';
if ($number_of_answers == 0) { echo ' </tr>';
$answers_number = 0;
} else {
$answers_number = $absolute_number/$number_of_answers*100;
}
echo ' <tr>';
echo ' <td class="center">'.$value['option_text'].'</td>';
echo ' <td class="center">';
if ($absolute_number!=0){
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action='.$action.'&amp;survey_id='.$surveyId.'&amp;question='.$offset.'&amp;viewoption='.$value['question_option_id'].'">'.$absolute_number.'</a>';
}else{
echo '0';
}
echo ' </td>';
echo ' <td class="center">'.round($answers_number, 2).' %</td>';
echo ' <td class="center">';
$size = $answers_number*2;
if ($size > 0) {
echo '<div style="border:1px solid #264269; background-color:#aecaf4; height:10px; width:'.$size.'px">&nbsp;</div>';
}else{
echo '<div style="text-align: left;">'.get_lang("NoDataAvailable").'</div>';
} }
echo ' </td>';
echo ' </tr>';
} }
} // displaying the table: footer (totals)
// displaying the table: footer (totals) echo ' <tr>';
echo ' <tr>'; echo ' <td class="total"><b>' . get_lang('Total') . '</b></td>';
echo ' <td class="total"><b>'.get_lang('Total').'</b></td>'; echo ' <td class="total"><b>' . ($number_of_answers[$option['question_id']] == 0 ? '0' : $number_of_answers[$option['question_id']]) . '</b></td>';
echo ' <td class="total"><b>'.($number_of_answers==0?'0':$number_of_answers).'</b></td>'; echo ' <td class="total">&nbsp;</td>';
echo ' <td class="total">&nbsp;</td>'; echo ' <td class="total">&nbsp;</td>';
echo ' <td class="total">&nbsp;</td>'; echo ' </tr>';
echo ' </tr>';
echo '</table>'; echo '</table>';
echo '</div>';
}
} }
if (isset($_GET['viewoption'])) { if (isset($_GET['viewoption'])) {
echo '<div class="answered-people">'; echo '<div class="answered-people">';
@ -4394,14 +4411,14 @@ class SurveyUtil
* @param boolean Tells if the chart has a serie. False by default * @param boolean Tells if the chart has a serie. False by default
* @return void (direct output) * @return void (direct output)
*/ */
public static function drawChart($chartData, $hasSerie = false) public static function drawChart($chartData, $hasSerie = false, $chartContainerId = 'chartContainer')
{ {
$htmlChart = ''; $htmlChart = '';
if (api_browser_support("svg")) { if (api_browser_support("svg")) {
$htmlChart .= api_get_js("d3/d3.v3.5.4.min.js"); $htmlChart .= api_get_js("d3/d3.v3.5.4.min.js");
$htmlChart .= api_get_js("dimple.v2.1.2.min.js") . ' $htmlChart .= api_get_js("dimple.v2.1.2.min.js") . '
<script type="text/javascript"> <script type="text/javascript">
var svg = dimple.newSvg("#chartContainer", "100%", 400); var svg = dimple.newSvg("#'.$chartContainerId.'", "100%", 400);
var data = ['; var data = [';
$serie = array(); $serie = array();
$order = array(); $order = array();

Loading…
Cancel
Save