Browse Source

Fix:Coding style

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
f8145ebaae
  1. 4
      attempt.php
  2. 70
      hiddenpicture/play.php
  3. 51
      locallib.php
  4. 2
      report/overview/report.php

4
attempt.php

@ -171,10 +171,6 @@ function game_do_attempt( $id, $game, $action, $course, $context) {
$attempt = game_getattempt( $game, $detail);
game_snakes_check_glossary( $id, $game, $attempt, $detail, $context);
break;
case 'hiddenpicturecheck': // The student tries to answer a question.
$attempt = game_getattempt( $game, $detail);
$continue = game_hiddenpicture_check_questions( $id, $game, $attempt, $detail, $finishattempt, $context);
break;
case 'hiddenpicturecheckg': // The student tries to guess a glossaryentry.
$attempt = game_getattempt( $game, $detail);
game_hiddenpicture_check_mainquestion( $id, $game, $attempt, $detail, $endofgame, $context);

70
hiddenpicture/play.php

@ -314,76 +314,8 @@ function game_hiddenpicture_showquestion_glossary( $game, $id, $query) {
echo "</form><br>\n";
}
function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpicture, $finishattempt) {
global $QTYPES, $DB;
$responses = data_submitted();
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions);
$questionlist = game_sudoku_getquestionlist( $offsetquestions);
$questions = game_sudoku_getquestions( $questionlist);
$actions = question_extract_responses($questions, $responses, QUESTION_EVENTSUBMIT);
$correct = $wrong = 0;
foreach ($questions as $question) {
if (!array_key_exists( $question->id, $actions)) {
// No answered.
continue;
}
unset( $state);
unset( $cmoptions);
$question->maxgrade = 100;
$state->responses = $actions[ $question->id]->responses;
$state->event = QUESTION_EVENTGRADE;
$cmoptions = array();
$QTYPES[$question->qtype]->grade_responses( $question, $state, $cmoptions);
unset( $query);
$select = "attemptid=$attempt->id";
$select .= " AND questionid=$question->id";
if (($query->id = $DB->get_field_select( 'game_queries', 'id', $select)) == 0) {
print_error("problem game_hiddenpicture_check_questions (select=$select)");
}
$answertext = $state->responses[ ''];
if ($answertext != '') {
$grade = $state->raw_grade;
if ($grade < 50) {
// Wrong answer.
game_update_queries( $game, $attempt, $query, $grade / 100, $answertext);
$wrong++;
} else {
// Correct answer.
game_update_queries( $game, $attempt, $query, 1, $answertext);
$correct++;
}
}
}
$hiddenpicture->correct += $correct;
$hiddenpicture->wrong += $wrong;
if (!$DB->update_record( 'game_hiddenpicture', $hiddenpicture)) {
print_error( 'game_hiddenpicture_check_questions: error updating in game_hiddenpicture');
}
$attempt->score = game_hidden_picture_computescore( $game, $hiddenpicture);
if (!$DB->update_record( 'game_attempts', $attempt)) {
print_error( 'game_hiddenpicture_check_questions: error updating in game_attempt');
}
game_sudoku_check_last( $id, $game, $attempt, $hiddenpicture, $finishattempt);
return true;
}
function game_hiddenpicture_check_mainquestion( $id, $game, &$attempt, &$hiddenpicture, $finishattempt, $context) {
global $QTYPES, $CFG, $DB;
global $CFG, $DB;
$responses = data_submitted();

51
locallib.php

@ -18,7 +18,6 @@ if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
// Include those library functions that are also used by core Moodle or other modules.
require_once($CFG->dirroot . '/mod/game/lib.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
@ -1146,52 +1145,6 @@ function game_calculate_best_attempt($game, $attempts) {
}
}
/**
* Loads the most recent state of each question session from the database
*
* For each question the most recent session state for the current attempt
* is loaded from the game_questions table and the question type specific data
*
* @return array An array of state objects representing the most recent
* states of the question sessions.
* @param array $questions The questions for which sessions are to be restored or
* created.
* @param object $cmoptions
* @param object $attempt The attempt for which the question sessions are
* to be restored or created.
* @param mixed either the id of a previous attempt, if this attmpt is
* building on a previous one, or false for a clean attempt.
*/
function game_get_question_states(&$questions, $cmoptions, $attempt, $lastattemptid = false) {
global $DB, $QTYPES;
// Get the question ids.
$ids = array_keys( $questions);
$questionlist = implode(',', $ids);
$statefields = 'questionid as question, manualcomment, score as grade';
$sql = "SELECT $statefields".
" FROM {game_questions} ".
" WHERE attemptid = '$attempt->id'".
" AND questionid IN ($questionlist)";
$states = $DB->get_records_sql($sql);
// Loops through all questions and set the last_graded states.
foreach ($ids as $i) {
// Creates the empty question type specific information.
if (!$QTYPES[$questions[$i]->qtype]->create_session_and_responses(
$questions[$i], $states[$i], $cmoptions, $attempt)) {
return false;
}
$states[$i]->last_graded = clone($states[$i]);
}
return $states;
}
function game_sudoku_getquestions( $questionlist) {
global $CFG, $DB;
@ -1536,6 +1489,10 @@ function game_grade_responses( $question, $responses, $maxgrade, &$answertext, &
return $answer->fraction * $maxgrade;
} else {
$name = "resp{$question->id}_";
if( !isset( $responses->$name)) {
$answered = false;
return 0; // Not answered this question.
}
$answertext = game_upper( $responses->$name);
foreach ($question->options->answers as $answer) {

2
report/overview/report.php

@ -31,7 +31,7 @@ class game_report extends game_default_report {
* Display the report.
*/
public function display($game, $cm, $course) {
global $CFG, $SESSION, $db, $QTYPES;
global $CFG, $SESSION, $DB;
// Define some strings.
$strreallydel = addslashes(get_string('deleteattemptcheck', 'game'));

Loading…
Cancel
Save