Minor - format code + fix variable name

pull/2487/head
jmontoyaa 9 years ago
parent 76c9db0d80
commit 4f9f410ded
  1. 2
      main/exercise/oral_expression.class.php
  2. 163
      main/exercise/stats.php

@ -36,7 +36,7 @@ class OralExpression extends Question
* function which redefine Question::createAnswersForm * function which redefine Question::createAnswersForm
* @param FormValidator $form * @param FormValidator $form
*/ */
function createAnswersForm($form) public function createAnswersForm($form)
{ {
$form->addText( $form->addText(
'weighting', 'weighting',

@ -12,16 +12,23 @@ $objExercise = new Exercise();
$result = $objExercise->read($exercise_id); $result = $objExercise->read($exercise_id);
if (!$result) { if (!$result) {
api_not_allowed(true); api_not_allowed(true);
} }
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$courseCode = api_get_course_id(); $courseCode = api_get_course_id();
if (empty($sessionId)) { if (empty($sessionId)) {
$students = CourseManager :: get_student_list_from_course_code($courseCode, false); $students = CourseManager:: get_student_list_from_course_code(
$courseCode,
false
);
} else { } else {
$students = CourseManager :: get_student_list_from_course_code($courseCode, true, $sessionId); $students = CourseManager:: get_student_list_from_course_code(
$courseCode,
true,
$sessionId
);
} }
$count_students = count($students); $count_students = count($students);
$question_list = $objExercise->get_validated_question_list(); $question_list = $objExercise->get_validated_question_list();
@ -29,17 +36,17 @@ $question_list = $objExercise->get_validated_question_list();
$data = array(); $data = array();
// Question title # of students who tool it Lowest score Average Highest score Maximum score // Question title # of students who tool it Lowest score Average Highest score Maximum score
$headers = array( $headers = array(
get_lang('Question'), get_lang('Question'),
get_lang('QuestionType'), get_lang('QuestionType'),
get_lang('NumberStudentWhoSelectedIt'), get_lang('NumberStudentWhoSelectedIt'),
get_lang('LowestScore'), get_lang('LowestScore'),
get_lang('AverageScore'), get_lang('AverageScore'),
get_lang('HighestScore'), get_lang('HighestScore'),
get_lang('Weighting') get_lang('Weighting'),
); );
if (!empty($question_list)) { if (!empty($question_list)) {
foreach ($question_list as $question_id) { foreach ($question_list as $question_id) {
$question_obj = Question::read($question_id); $question_obj = Question::read($question_id);
$exercise_stats = ExerciseLib::get_student_stats_by_question( $exercise_stats = ExerciseLib::get_student_stats_by_question(
@ -73,7 +80,7 @@ if (!empty($question_list)) {
$data[$question_id]['average_score'] = round($exercise_stats['average'], 2); $data[$question_id]['average_score'] = round($exercise_stats['average'], 2);
$data[$question_id]['highest_score'] = round($exercise_stats['max'], 2); $data[$question_id]['highest_score'] = round($exercise_stats['max'], 2);
$data[$question_id]['max_score'] = round($question_obj->weighting, 2); $data[$question_id]['max_score'] = round($question_obj->weighting, 2);
} }
} }
// Format A table // Format A table
@ -81,37 +88,37 @@ $table = new HTML_Table(array('class' => 'data_table'));
$row = 0; $row = 0;
$column = 0; $column = 0;
foreach ($headers as $header) { foreach ($headers as $header) {
$table->setHeaderContents($row, $column, $header); $table->setHeaderContents($row, $column, $header);
$column++; $column++;
} }
$row++; $row++;
foreach ($data as $row_table) { foreach ($data as $row_table) {
$column = 0; $column = 0;
foreach ($row_table as $cell) { foreach ($row_table as $cell) {
$table->setCellContents($row, $column, $cell); $table->setCellContents($row, $column, $cell);
$table->updateCellAttributes($row, $column, 'align="center"'); $table->updateCellAttributes($row, $column, 'align="center"');
$column++; $column++;
} }
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true); $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
$row++; $row++;
} }
$content = $table->toHtml(); $content = $table->toHtml();
// Format B // Format B
$headers = array( $headers = array(
get_lang('Question'), get_lang('Question'),
get_lang('Answer'), get_lang('Answer'),
get_lang('Correct'), get_lang('Correct'),
get_lang('NumberStudentWhoSelectedIt') get_lang('NumberStudentWhoSelectedIt')
); );
$data = array(); $data = array();
if (!empty($question_list)) { if (!empty($question_list)) {
$id = 0; $id = 0;
foreach ($question_list as $question_id) { foreach ($question_list as $question_id) {
$question_obj = Question::read($question_id); $question_obj = Question::read($question_id);
$exercise_stats = ExerciseLib::get_student_stats_by_question( $exercise_stats = ExerciseLib::get_student_stats_by_question(
$question_id, $question_id,
$exercise_id, $exercise_id,
@ -120,7 +127,7 @@ if (!empty($question_list)) {
); );
$answer = new Answer($question_id); $answer = new Answer($question_id);
$answer_count = $answer->selectNbrAnswers(); $answer_count = $answer->selectNbrAnswers();
for ($answer_id = 1; $answer_id <= $answer_count; $answer_id++) { for ($answer_id = 1; $answer_id <= $answer_count; $answer_id++) {
$answer_info = $answer->selectAnswer($answer_id); $answer_info = $answer->selectAnswer($answer_id);
@ -130,7 +137,7 @@ if (!empty($question_list)) {
// Overwriting values depending of the question // Overwriting values depending of the question
switch ($question_obj->type) { switch ($question_obj->type) {
case FILL_IN_BLANKS : case FILL_IN_BLANKS:
$answer_info_db = $answer_info; $answer_info_db = $answer_info;
$answer_info = substr($answer_info, 0, strpos($answer_info, '::')); $answer_info = substr($answer_info, 0, strpos($answer_info, '::'));
$correct_answer = $is_correct; $correct_answer = $is_correct;
@ -142,23 +149,26 @@ if (!empty($question_list)) {
} else { } else {
$data[$id]['name'] = '-'; $data[$id]['name'] = '-';
} }
$data[$id]['answer'] = $answer_item; $data[$id]['answer'] = $answer_item;
$answer_item = api_substr($answer_item, 1); $answer_item = api_substr($answer_item, 1);
$answer_item = api_substr($answer_item, 0, api_strlen($answer_item) -1); $answer_item = api_substr($answer_item, 0, api_strlen($answer_item) -1);
$data[$id]['answer'] = $answer_item; $data[$id]['answer'] = $answer_item;
$data[$id]['correct'] = '-';
$data[$id]['correct'] = '-';
$count = ExerciseLib::getNumberStudentsFillBlanksAnwserCount($question_id, $exercise_id); $count = ExerciseLib::getNumberStudentsFillBlanksAnwserCount($question_id, $exercise_id);
$count = $count[$counter]; $count = isset($count[$counter]) ? $count[$counter] : 0;
$percentange = 0; $percentage = 0;
if (!empty($count_students)) { if (!empty($count_students)) {
$percentange = $count/$count_students*100; $percentage = $count/$count_students*100;
} }
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students); $data[$id]['attempts'] = Display::bar_progress(
$percentage,
false,
$count.' / '.$count_students
);
$id++; $id++;
$counter++; $counter++;
} }
@ -173,13 +183,12 @@ if (!empty($question_list)) {
$data[$id]['name'] = '-'; $data[$id]['name'] = '-';
} }
$correct = ''; $correct = '';
for ($i = 1; $i <= $answer_count; $i++) { for ($i = 1; $i <= $answer_count; $i++) {
$is_correct_i = $answer->isCorrect($i); $is_correct_i = $answer->isCorrect($i);
if ($is_correct_i != 0 && $is_correct_i == $answer_id) { if ($is_correct_i != 0 && $is_correct_i == $answer_id) {
$correct = $answer->selectAnswer($i); $correct = $answer->selectAnswer($i);
break; break;
} }
} }
$data[$id]['answer'] = $correct; $data[$id]['answer'] = $correct;
$data[$id]['correct'] = $answer_info; $data[$id]['correct'] = $answer_info;
@ -192,11 +201,15 @@ if (!empty($question_list)) {
$sessionId, $sessionId,
MATCHING MATCHING
); );
$percentange = 0; $percentage = 0;
if (!empty($count_students)) { if (!empty($count_students)) {
$percentange = $count/$count_students*100; $percentage = $count/$count_students*100;
} }
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students); $data[$id]['attempts'] = Display::bar_progress(
$percentage,
false,
$count.' / '.$count_students
);
} }
break; break;
case HOT_SPOT: case HOT_SPOT:
@ -215,11 +228,15 @@ if (!empty($question_list)) {
$courseCode, $courseCode,
$sessionId $sessionId
); );
$percentange = 0; $percentage = 0;
if (!empty($count_students)) { if (!empty($count_students)) {
$percentange = $count/$count_students*100; $percentage = $count/$count_students*100;
} }
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students); $data[$id]['attempts'] = Display::bar_progress(
$percentage,
false,
$count.' / '.$count_students
);
break; break;
default: default:
if ($answer_id == 1) { if ($answer_id == 1) {
@ -237,15 +254,19 @@ if (!empty($question_list)) {
$courseCode, $courseCode,
$sessionId $sessionId
); );
$percentange = 0; $percentage = 0;
if (!empty($count_students)) { if (!empty($count_students)) {
$percentange = $count/$count_students*100; $percentage = $count/$count_students*100;
} }
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students); $data[$id]['attempts'] = Display::bar_progress(
$percentage,
false,
$count.' / '.$count_students
);
} }
$id++; $id++;
} }
} }
} }
// Format A table // Format A table
@ -253,28 +274,40 @@ $table = new HTML_Table(array('class' => 'data_table'));
$row = 0; $row = 0;
$column = 0; $column = 0;
foreach ($headers as $header) { foreach ($headers as $header) {
$table->setHeaderContents($row, $column, $header); $table->setHeaderContents($row, $column, $header);
$column++; $column++;
} }
$row++; $row++;
foreach ($data as $row_table) { foreach ($data as $row_table) {
$column = 0; $column = 0;
foreach ($row_table as $cell) { foreach ($row_table as $cell) {
$table->setCellContents($row, $column, $cell); $table->setCellContents($row, $column, $cell);
$table->updateCellAttributes($row, $column, 'align="center"'); $table->updateCellAttributes($row, $column, 'align="center"');
$column++; $column++;
} }
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true); $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
$row++; $row++;
} }
$content .= $table->toHtml(); $content .= $table->toHtml();
$interbreadcrumb[] = array("url" => "exercise.php?gradebook=$gradebook&".api_get_cidreq(), "name" => get_lang('Exercises')); $interbreadcrumb[] = array(
$interbreadcrumb[] = array("url" => "admin.php?exerciseId=$exercise_id&".api_get_cidreq(), "name" => $objExercise->name); "url" => "exercise.php?gradebook=$gradebook&".api_get_cidreq(),
"name" => get_lang('Exercises'),
);
$interbreadcrumb[] = array(
"url" => "admin.php?exerciseId=$exercise_id&".api_get_cidreq(),
"name" => $objExercise->name,
);
$tpl = new Template(get_lang('ReportByQuestion')); $tpl = new Template(get_lang('ReportByQuestion'));
$actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'&'.api_get_cidreq().'">' . $actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'&'.api_get_cidreq().'">' .
Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>'; Display:: return_icon(
'back.png',
get_lang('GoBackToQuestionList'),
'',
ICON_SIZE_MEDIUM
)
.'</a>';
$actions = Display::div($actions, array('class'=> 'actions')); $actions = Display::div($actions, array('class'=> 'actions'));
$content = $actions.$content; $content = $actions.$content;
$tpl->assign('content', $content); $tpl->assign('content', $content);

Loading…
Cancel
Save