Browse Source

Fix:Coding style

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
b5f11fca18
  1. 81
      lang/en/game.php
  2. 483
      millionaire/play.php
  3. 66
      report/default.php
  4. 320
      report/overview/report.php
  5. 310
      snakes/createboard.php
  6. 239
      snakes/play.php

81
lang/en/game.php

@ -1,31 +1,46 @@
<?php // $Id: game.php,v 1.22 2012/07/26 05:38:59 bdaloukas Exp $ <?php
// translated by Vasilis Daloukas // This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
//bookquiz/importodt.php // Translated by Vasilis Daloukas.
// File bookquiz/importodt.php.
$string[ 'bookquiz_import_odt'] = 'Import from an OpenOffice file (odt)'; $string[ 'bookquiz_import_odt'] = 'Import from an OpenOffice file (odt)';
$string[ 'bookquiz_not_select_book'] = 'You have not select book'; $string[ 'bookquiz_not_select_book'] = 'You have not select book';
$string[ 'bookquiz_subchapter'] = 'Create subchapters'; $string[ 'bookquiz_subchapter'] = 'Create subchapters';
//bookquiz/play.php // File bookquiz/play.php.
$string[ 'bookquiz_empty'] = 'The book is empty'; $string[ 'bookquiz_empty'] = 'The book is empty';
$string[ 'sudoku_submit'] = 'Grade answers'; $string[ 'sudoku_submit'] = 'Grade answers';
//bookquiz/questions.php // File bookquiz/questions.php.
$string[ 'bookquiz_categories'] = 'Categories'; $string[ 'bookquiz_categories'] = 'Categories';
$string[ 'bookquiz_chapters'] = 'Chapters'; $string[ 'bookquiz_chapters'] = 'Chapters';
$string[ 'bookquiz_numquestions'] = 'Questions'; $string[ 'bookquiz_numquestions'] = 'Questions';
//classes // Classes.
$string[ 'eventgamecreated'] = 'Game created'; $string[ 'eventgamecreated'] = 'Game created';
$string[ 'eventgamedeleted'] = 'Game deleted'; $string[ 'eventgamedeleted'] = 'Game deleted';
$string[ 'eventgamesupdated'] = 'Game updated'; $string[ 'eventgamesupdated'] = 'Game updated';
$string[ 'eventgameviewed'] = 'Game viewed'; $string[ 'eventgameviewed'] = 'Game viewed';
$string[ 'eventgameplayed'] = 'Game played'; $string[ 'eventgameplayed'] = 'Game played';
//cross/cross_class.php // File cross/cross_class.php.
$string[ 'lettersall'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $string[ 'lettersall'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
//cross/crossdb_class.php // File cross/crossdb_class.php.
$string[ 'and'] = 'and'; $string[ 'and'] = 'and';
$string[ 'cross_correct'] = 'corrert character'; $string[ 'cross_correct'] = 'corrert character';
$string[ 'cross_corrects'] = 'correct characters'; $string[ 'cross_corrects'] = 'correct characters';
@ -36,7 +51,7 @@ $string[ 'cross_found_one'] = 'Found';
$string[ 'grade'] = 'Grade'; $string[ 'grade'] = 'Grade';
$string[ 'cross_disabletransformuppercase'] = 'Disables text-transform:uppercase in CSS'; $string[ 'cross_disabletransformuppercase'] = 'Disables text-transform:uppercase in CSS';
//cross/play.php // File cross/play.php.
$string[ 'cross_across'] = 'Across'; $string[ 'cross_across'] = 'Across';
$string[ 'cross_checkbutton'] = 'Check crossword'; $string[ 'cross_checkbutton'] = 'Check crossword';
$string[ 'cross_down'] = 'Down'; $string[ 'cross_down'] = 'Down';
@ -53,10 +68,10 @@ $string[ 'no_words'] = 'There are no words';
$string[ 'print'] = 'Print'; $string[ 'print'] = 'Print';
$string[ 'win'] = 'Congratulations !!!'; $string[ 'win'] = 'Congratulations !!!';
//cryptex/play.php // File cryptex/play.php.
$string[ 'finish'] = 'End of game'; $string[ 'finish'] = 'End of game';
//db/access.php // File db/access.php.
$string[ 'game:attempt'] = 'Play game'; $string[ 'game:attempt'] = 'Play game';
$string[ 'game:deleteattempts'] = 'Delete attempts'; $string[ 'game:deleteattempts'] = 'Delete attempts';
$string[ 'game:grade'] = 'Grade games manually'; $string[ 'game:grade'] = 'Grade games manually';
@ -67,7 +82,7 @@ $string[ 'game:reviewmyattempts'] = 'reviewmyattempts';
$string[ 'game:view'] = 'view'; $string[ 'game:view'] = 'view';
$string[ 'game:viewreports'] = 'viewreports'; $string[ 'game:viewreports'] = 'viewreports';
//hangman/play.php // File hangman/play.php.
$string[ 'hangman_correct_phrase'] = 'The correct phrase was: '; $string[ 'hangman_correct_phrase'] = 'The correct phrase was: ';
$string[ 'hangman_correct_word'] = 'The correct word was: '; $string[ 'hangman_correct_word'] = 'The correct word was: ';
$string[ 'hangman_gradeinstance'] = 'Grade in whole game'; $string[ 'hangman_gradeinstance'] = 'Grade in whole game';
@ -77,7 +92,7 @@ $string[ 'hangman_restletters_one'] = 'You have <b>ONLY 1</b> try';
$string[ 'hangman_wrongnum'] = 'Wrong: %d out of %d'; $string[ 'hangman_wrongnum'] = 'Wrong: %d out of %d';
$string[ 'nextword'] = 'Next word'; $string[ 'nextword'] = 'Next word';
//hiddenpicture/play.php // File hiddenpicture/play.php.
$string[ 'hiddenpicture_mainsubmit'] = 'Grade main answer'; $string[ 'hiddenpicture_mainsubmit'] = 'Grade main answer';
$string[ 'hiddenpicture_nocols'] = 'Have to specify the number of cols horizontaly'; $string[ 'hiddenpicture_nocols'] = 'Have to specify the number of cols horizontaly';
$string[ 'hiddenpicture_nomainquestion'] = 'There are no glossary entries on glossary {$a->name} with an attached picture'; $string[ 'hiddenpicture_nomainquestion'] = 'There are no glossary entries on glossary {$a->name} with an attached picture';
@ -86,11 +101,11 @@ $string[ 'must_select_glossary'] = 'You must select a glossary';
$string[ 'no_questions'] = "There are no questions"; $string[ 'no_questions'] = "There are no questions";
$string[ 'noglossaryentriesfound'] = 'No glossary entries found'; $string[ 'noglossaryentriesfound'] = 'No glossary entries found';
//millionaire/play.php // File millionaire/play.php.
$string[ 'millionaire_must_select_questioncategory'] = 'You must select one question category'; $string[ 'millionaire_must_select_questioncategory'] = 'You must select one question category';
$string[ 'millionaire_must_select_quiz'] = 'You must select one quiz'; $string[ 'millionaire_must_select_quiz'] = 'You must select one quiz';
//report/overview/report.php // File report/overview/report.php.
$string[ 'allattempts'] = 'Show all tries'; $string[ 'allattempts'] = 'Show all tries';
$string[ 'allstudents'] = 'Show all $a'; $string[ 'allstudents'] = 'Show all $a';
$string[ 'attemptduration'] = 'Attempt duration'; $string[ 'attemptduration'] = 'Attempt duration';
@ -111,21 +126,21 @@ $string[ 'timecompleted'] = 'Completed';
$string[ 'unfinished'] = 'open'; $string[ 'unfinished'] = 'open';
$string[ 'withselected'] = 'With selected'; $string[ 'withselected'] = 'With selected';
//snakes/play.php // File snakes/play.php.
$string[ 'snakes_dice'] = 'Dice, $a spots.'; $string[ 'snakes_dice'] = 'Dice, $a spots.';
$string[ 'snakes_player'] = 'Player, position: $a.'; $string[ 'snakes_player'] = 'Player, position: $a.';
//sudoku/create.php // File sudoku/create.php.
$string[ 'sudoku_create_count'] = 'Number of sudokus that will be created'; $string[ 'sudoku_create_count'] = 'Number of sudokus that will be created';
$string[ 'sudoku_create_start'] = 'Start creating sudokus'; $string[ 'sudoku_create_start'] = 'Start creating sudokus';
$string[ 'sudoku_creating'] = 'Creating <b>{$a}</b> sudoku'; $string[ 'sudoku_creating'] = 'Creating <b>{$a}</b> sudoku';
//sudoku/play.php // File sudoku/play.php.
$string[ 'sudoku_finishattemptbutton'] = 'End of game'; $string[ 'sudoku_finishattemptbutton'] = 'End of game';
$string[ 'sudoku_guessnumber'] = 'Guess the correct number'; $string[ 'sudoku_guessnumber'] = 'Guess the correct number';
$string[ 'sudoku_noentriesfound'] = 'No words found in glossary'; $string[ 'sudoku_noentriesfound'] = 'No words found in glossary';
//export.php // File export.php.
$string[ 'export'] = 'Export'; $string[ 'export'] = 'Export';
$string[ 'html_hascheckbutton'] = 'Has check button:'; $string[ 'html_hascheckbutton'] = 'Has check button:';
$string[ 'html_hasprintbutton'] = 'Has print button:'; $string[ 'html_hasprintbutton'] = 'Has print button:';
@ -141,11 +156,11 @@ $string[ 'javame_type'] = 'Type:';
$string[ 'javame_vendor'] = 'Vendor:'; $string[ 'javame_vendor'] = 'Vendor:';
$string[ 'javame_version'] = 'Version:'; $string[ 'javame_version'] = 'Version:';
//exporthtml_hangman.php // File exporthtml_hangman.php.
$string[ 'hangman_loose'] = '<BIG><B>Game over</B></BIG>'; $string[ 'hangman_loose'] = '<BIG><B>Game over</B></BIG>';
$string[ 'html_hangman_new'] = 'New'; $string[ 'html_hangman_new'] = 'New';
//exporthtml_millionaire.php // File exporthtml_millionaire.php.
$string[ 'millionaire_helppeople'] = 'Help of people'; $string[ 'millionaire_helppeople'] = 'Help of people';
$string[ 'millionaire_info_people'] = 'People say'; $string[ 'millionaire_info_people'] = 'People say';
$string[ 'millionaire_info_telephone'] = 'I think that the correct answer is '; $string[ 'millionaire_info_telephone'] = 'I think that the correct answer is ';
@ -156,14 +171,14 @@ $string[ 'millionaire_telephone'] = 'Help of telephone';
$string[ 'must_select_questioncategory'] = 'You must select a question category'; $string[ 'must_select_questioncategory'] = 'You must select a question category';
$string[ 'must_select_quiz'] = 'You must select a quiz'; $string[ 'must_select_quiz'] = 'You must select a quiz';
//exporthtml_snakes.php // File exporthtml_snakes.php.
$string[ 'html_snakes_check'] = 'Check'; $string[ 'html_snakes_check'] = 'Check';
$string[ 'html_snakes_correct'] = 'Correct!'; $string[ 'html_snakes_correct'] = 'Correct!';
$string[ 'html_snakes_no_selection'] = 'Have to select something!'; $string[ 'html_snakes_no_selection'] = 'Have to select something!';
$string[ 'html_snakes_wrong'] = "Your answer isn't correct. Stay on the same seat."; $string[ 'html_snakes_wrong'] = "Your answer isn't correct. Stay on the same seat.";
$string[ 'score'] = 'Score'; $string[ 'score'] = 'Score';
//index.php // File index.php.
$string[ 'helpbookquiz'] = 'When the student answers correct can go to the next chapter.'; $string[ 'helpbookquiz'] = 'When the student answers correct can go to the next chapter.';
$string[ 'helpcross'] = 'This game takes words from either a Glossary or quiz short answer questions and generates a random crossword puzzle. Teacher can set the maximum number of columns/rows or words that contains. Student can press the button “Check crossword” to check if the answers are correct. Every crossword is dynamic so it is different to every student.'; $string[ 'helpcross'] = 'This game takes words from either a Glossary or quiz short answer questions and generates a random crossword puzzle. Teacher can set the maximum number of columns/rows or words that contains. Student can press the button “Check crossword” to check if the answers are correct. Every crossword is dynamic so it is different to every student.';
$string[ 'helpcryptex'] = 'This game is like a crossword but the answers are hidden inside a random cryptex.'; $string[ 'helpcryptex'] = 'This game is like a crossword but the answers are hidden inside a random cryptex.';
@ -178,7 +193,7 @@ $string[ 'modulenameplural'] = 'Games';
$string[ 'pluginadministration'] = 'Game administration'; $string[ 'pluginadministration'] = 'Game administration';
$string[ 'pluginname'] = 'Game'; $string[ 'pluginname'] = 'Game';
//lib.php // File lib.php.
$string[ 'attempt'] = 'Attempt'; $string[ 'attempt'] = 'Attempt';
$string[ 'bookquiz_questions'] = 'Associate question categories to chapter of book'; $string[ 'bookquiz_questions'] = 'Associate question categories to chapter of book';
$string[ 'export_to_html'] = 'Export to HTML'; $string[ 'export_to_html'] = 'Export to HTML';
@ -200,7 +215,7 @@ $string[ 'results'] = 'Results';
$string[ 'showanswers'] = 'Show answers'; $string[ 'showanswers'] = 'Show answers';
$string[ 'showattempts'] = 'Show attempts'; $string[ 'showattempts'] = 'Show attempts';
//locallib.php // File locallib.php.
$string[ 'attemptfirst'] = 'First attempt'; $string[ 'attemptfirst'] = 'First attempt';
$string[ 'attemptlast'] = 'Last attempt'; $string[ 'attemptlast'] = 'Last attempt';
$string[ 'convertfrom'] = '-'; $string[ 'convertfrom'] = '-';
@ -208,7 +223,7 @@ $string[ 'convertto'] = '-';
$string[ 'gradeaverage'] = 'Average grade'; $string[ 'gradeaverage'] = 'Average grade';
$string[ 'gradehighest'] = 'Highest grade'; $string[ 'gradehighest'] = 'Highest grade';
//mod_form.php // File mod_form.php.
$string[ 'bookquiz_layout'] = 'Layout'; $string[ 'bookquiz_layout'] = 'Layout';
$string[ 'bookquiz_layout0'] = 'Question at the top of the book'; $string[ 'bookquiz_layout0'] = 'Question at the top of the book';
$string[ 'bookquiz_layout1'] = 'Question at the bottom of the book'; $string[ 'bookquiz_layout1'] = 'Question at the bottom of the book';
@ -276,11 +291,11 @@ $string[ 'sudoku_options'] = 'Sudoku options';
$string[ 'toptext'] = 'Text at the top of page'; $string[ 'toptext'] = 'Text at the top of page';
$string[ 'userdefined'] = 'User defined'; $string[ 'userdefined'] = 'User defined';
//preview.php // File preview.php.
$string[ 'only_teachers'] = 'Only teacher can see this page'; $string[ 'only_teachers'] = 'Only teacher can see this page';
$string[ 'preview'] = 'Preview'; $string[ 'preview'] = 'Preview';
//review.php // File review.php.
$string[ 'attempts'] = 'Attempts'; $string[ 'attempts'] = 'Attempts';
$string[ 'completedon'] = 'Completed on'; $string[ 'completedon'] = 'Completed on';
$string[ 'outof'] = '{$a->grade} out of a maximum of {$a->maxgrade}'; $string[ 'outof'] = '{$a->grade} out of a maximum of {$a->maxgrade}';
@ -290,7 +305,7 @@ $string[ 'showall'] = 'Show all';
$string[ 'startagain'] = 'Start again'; $string[ 'startagain'] = 'Start again';
$string[ 'timetaken'] = 'Time taken'; $string[ 'timetaken'] = 'Time taken';
//settings.php // File settings.php.
$string[ 'hangmanimagesets'] = 'Number of image sets used by hangman'; $string[ 'hangmanimagesets'] = 'Number of image sets used by hangman';
$string[ 'hidebookquiz'] = 'Hide the "Book with questions" game'; $string[ 'hidebookquiz'] = 'Hide the "Book with questions" game';
$string[ 'hidecross'] = 'Hide the Crossword game'; $string[ 'hidecross'] = 'Hide the Crossword game';
@ -310,22 +325,22 @@ $string[ 'confighidemillionaire'] = 'Configs if the Millionaire game is shown to
$string[ 'confighidesnakes'] = 'Configs if the "Snakes and Ladders" game is shown to teachers or not'; $string[ 'confighidesnakes'] = 'Configs if the "Snakes and Ladders" game is shown to teachers or not';
$string[ 'confighidesudoku'] = 'Configs if the Sudoku game is shown to teachers or not'; $string[ 'confighidesudoku'] = 'Configs if the Sudoku game is shown to teachers or not';
//showanswers.php // File showanswers.php.
$string[ 'clearrepetitions'] = 'Clear statistics'; $string[ 'clearrepetitions'] = 'Clear statistics';
$string[ 'computerepetitions'] = 'Compute statistics again'; $string[ 'computerepetitions'] = 'Compute statistics again';
$string[ 'feedbacks'] = 'Messages correct answer'; $string[ 'feedbacks'] = 'Messages correct answer';
$string[ 'repetitions'] = 'Repetitions'; $string[ 'repetitions'] = 'Repetitions';
//showattempts.php // File showattempts.php.
$string[ 'lastip'] = 'IP student'; $string[ 'lastip'] = 'IP student';
$string[ 'showsolution'] = 'solution'; $string[ 'showsolution'] = 'solution';
$string[ 'timefinish'] = 'End of game'; $string[ 'timefinish'] = 'End of game';
$string[ 'timelastattempt'] = 'Last attempt'; $string[ 'timelastattempt'] = 'Last attempt';
$string[ 'timestart'] = 'Start'; $string[ 'timestart'] = 'Start';
//tabs.php // File tabs.php.
//view.php // File view.php.
$string[ 'attemptgamenow'] = 'Attempt game now'; $string[ 'attemptgamenow'] = 'Attempt game now';
$string[ 'comment'] = 'Comment'; $string[ 'comment'] = 'Comment';
$string[ 'continueattemptgame'] = 'Continue a previous attempt of game'; $string[ 'continueattemptgame'] = 'Continue a previous attempt of game';

483
millionaire/play.php

@ -1,4 +1,19 @@
<?php // $Id: play.php,v 1.31 2012/07/25 11:16:05 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This file plays the game millionaire * This file plays the game millionaire
* *
@ -7,22 +22,22 @@
* @package game * @package game
**/ **/
function game_millionaire_continue( $id, $game, $attempt, $millionaire, $context) function game_millionaire_continue( $id, $game, $attempt, $millionaire, $context) {
{ // User must select quiz or question as a source module.
//User must select quiz or question as a source module if (($game->quizid == 0) and ($game->questioncategoryid == 0)) {
if( ($game->quizid == 0) and ($game->questioncategoryid == 0)){ if ($game->sourcemodule == 'quiz') {
if( $game->sourcemodule == 'quiz')
print_error( get_string( 'millionaire_must_select_quiz', 'game')); print_error( get_string( 'millionaire_must_select_quiz', 'game'));
else } else {
print_error( get_string( 'millionaire_must_select_questioncategory', 'game')); print_error( get_string( 'millionaire_must_select_questioncategory', 'game'));
} }
}
if( $attempt != false and $millionaire != false){ if ($attempt != false and $millionaire != false) {
//continue an existing game // Continue an existing game.
return game_millionaire_play( $id, $game, $attempt, $millionaire, $context); return game_millionaire_play( $id, $game, $attempt, $millionaire, $context);
} }
if( $attempt == false){ if ($attempt == false) {
$attempt = game_addattempt( $game); $attempt = game_addattempt( $game);
} }
@ -32,33 +47,30 @@ function game_millionaire_continue( $id, $game, $attempt, $millionaire, $context
$newrec->level = 0; $newrec->level = 0;
$newrec->state = 0; $newrec->state = 0;
if( !game_insert_record( 'game_millionaire', $newrec)){ if (!game_insert_record( 'game_millionaire', $newrec)) {
print_error( 'error inserting in game_millionaire'); print_error( 'error inserting in game_millionaire');
} }
game_millionaire_play( $id, $game, $attempt, $newrec, $context); game_millionaire_play( $id, $game, $attempt, $newrec, $context);
} }
function game_millionaire_play( $id, $game, $attempt, $millionaire, $context) {
function game_millionaire_play( $id, $game, $attempt, $millionaire, $context)
{
global $DB; global $DB;
$buttons = optional_param('buttons', 0, PARAM_INT); $buttons = optional_param('buttons', 0, PARAM_INT);
$Help5050_x = optional_param('Help5050_x', 0, PARAM_INT); $help5050x = optional_param('Help5050_x', 0, PARAM_INT);
$HelpTelephone_x = optional_param('HelpTelephone_x', 0, PARAM_INT); $helptelephonex = optional_param('HelpTelephone_x', 0, PARAM_INT);
$HelpPeople_x = optional_param('HelpPeople_x', 0, PARAM_INT); $helppeoplex = optional_param('HelpPeople_x', 0, PARAM_INT);
$Quit_x = optional_param('Quit_x', 0, PARAM_INT); $quitx = optional_param('Quit_x', 0, PARAM_INT);
if( $millionaire->queryid){ if ($millionaire->queryid) {
$query = $DB->get_record( 'game_queries', array( 'id' => $millionaire->queryid)); $query = $DB->get_record( 'game_queries', array( 'id' => $millionaire->queryid));
}else } else {
{
$query = new StdClass; $query = new StdClass;
} }
$found = 0; $found = 0;
for($i=1; $i <= $buttons; $i++){ for ($i = 1; $i <= $buttons; $i++) {
$name = 'btAnswer'.$i; $name = 'btAnswer'.$i;
$answer = optional_param($name, '', PARAM_RAW); $answer = optional_param($name, '', PARAM_RAW);
if (!empty($answer)) { if (!empty($answer)) {
@ -67,40 +79,38 @@ function game_millionaire_play( $id, $game, $attempt, $millionaire, $context)
} }
} }
if( $found == 1) if ($found == 1) {
;//nothing $found = $found; // Nothing.
else if( !empty($Help5050_x)) } else if (!empty($help5050x)) {
game_millionaire_OnHelp5050( $game, $id, $millionaire, $game, $query, $context); game_millionaire_OnHelp5050( $game, $id, $millionaire, $game, $query, $context);
else if( !empty($HelpTelephone_x)) } else if (!empty($helptelephonex)) {
game_millionaire_OnHelpTelephone( $game, $id, $millionaire, $query, $context); game_millionaire_OnHelpTelephone( $game, $id, $millionaire, $query, $context);
else if( !empty($HelpPeople_x)) } else if (!empty($helppeoplex)) {
game_millionaire_OnHelpPeople( $game, $id, $millionaire, $query, $context); game_millionaire_OnHelpPeople( $game, $id, $millionaire, $query, $context);
else if( !empty($Quit_x)) } else if (!empty($quitx)) {
game_millionaire_OnQuit( $id, $game, $attempt, $query, $context); game_millionaire_OnQuit( $id, $game, $attempt, $query, $context);
else } else {
game_millionaire_ShowNextQuestion( $id, $game, $attempt, $millionaire, $context); game_millionaire_ShowNextQuestion( $id, $game, $attempt, $millionaire, $context);
} }
}
function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, $info, $context) {
function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer, $info, $context) global $CFG, $OUTPUT;
{
global $OUTPUT;
$question = str_replace( array("\'", '\"'), array("'", '"'), $query->questiontext); $question = str_replace( array("\'", '\"'), array("'", '"'), $query->questiontext);
if( $game->param8 == '') if ($game->param8 == '') {
$color = 408080; $color = 408080;
else } else {
$color = substr( '000000'.base_convert($game->param8, 10, 16), -6); $color = substr( '000000'.base_convert($game->param8, 10, 16), -6);
}
$color1 = 'black'; $color1 = 'black';
$color2 = 'DarkOrange'; $color2 = 'DarkOrange';
$colorback="white"; $colorback = "white";
$stylequestion = "background:$colorback;color:$color1"; $stylequestion = "background:$colorback;color:$color1";
$stylequestionselected = "background:$colorback;color:$color2"; $stylequestionselected = "background:$colorback;color:$color2";
global $CFG;
$state = $millionaire->state; $state = $millionaire->state;
$level = $millionaire->level; $level = $millionaire->level;
@ -109,78 +119,79 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
echo '<form name="Form1" method="post" action="attempt.php" id="Form1">'; echo '<form name="Form1" method="post" action="attempt.php" id="Form1">';
echo "<table cellpadding=0 cellspacing=0 border=0>\r\n"; echo "<table cellpadding=0 cellspacing=0 border=0>\r\n";
echo "<tr $background>"; echo "<tr $background>";
echo '<td rowspan='.(17+count( $aAnswer)).'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>'; echo '<td rowspan='.(17 + count( $aanswer)).'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
echo "<td colspan=6>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>"; echo "<td colspan=6>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
echo '<td rowspan='.(17+count( $aAnswer)).'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>'; echo '<td rowspan='.(17 + count( $aanswer)).'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
echo "</tr>\r\n"; echo "</tr>\r\n";
echo "<tr height=10%>"; echo "<tr height=10%>";
echo "<td $background rowspan=3 colspan=2>"; echo "<td $background rowspan=3 colspan=2>";
$dirgif = 'millionaire/1/'; $dirgif = 'millionaire/1/';
if( $state & 1) if ($state & 1) {
{
$gif = "5050x"; $gif = "5050x";
$disabled = "disabled=1"; $disabled = "disabled=1";
}else } else {
{
$gif = "5050"; $gif = "5050";
$disabled = ""; $disabled = "";
} }
echo '<input type="image" '.$disabled.' name="Help5050" id="Help5050" Title="50 50" src="'.$OUTPUT->pix_url($dirgif.$gif, 'mod_game').'" alt="" border="0">&nbsp;'; echo '<input type="image" '.$disabled.' name="Help5050" id="Help5050" Title="50 50" src="'.
$OUTPUT->pix_url($dirgif.$gif, 'mod_game').'" alt="" border="0">&nbsp;';
if( $state & 2) if ($state & 2) {
{
$gif = "telephonex"; $gif = "telephonex";
$disabled = "disabled=1"; $disabled = "disabled=1";
}else } else {
{
$gif = "telephone"; $gif = "telephone";
$disabled = ""; $disabled = "";
} }
echo '<input type="image" name="HelpTelephone" '.$disabled.' id="HelpTelephone" Title="'.get_string( 'millionaire_telephone', 'game').'" src="'.$OUTPUT->pix_url($dirgif.$gif, 'mod_game').'" alt="" border="0">&nbsp;';
if( $state & 4) echo '<input type="image" name="HelpTelephone" '.$disabled.
{ ' id="HelpTelephone" Title="'.get_string( 'millionaire_telephone', 'game').
'" src="'.$OUTPUT->pix_url($dirgif.$gif, 'mod_game').'" alt="" border="0">&nbsp;';
if ($state & 4) {
$gif = "peoplex"; $gif = "peoplex";
$disabled = "disabled=1"; $disabled = "disabled=1";
}else } else {
{
$gif = "people"; $gif = "people";
$disabled = ""; $disabled = "";
} }
echo '<input type="image" name="HelpPeople" '.$disabled.' id="HelpPeople" Title="'.get_string( 'millionaire_helppeople', 'game').'" src="'.$OUTPUT->pix_url($dirgif.$gif, 'mod_game').'" alt="" border="0">&nbsp;'; echo '<input type="image" name="HelpPeople" '.$disabled.' id="HelpPeople" Title="'.
get_string( 'millionaire_helppeople', 'game').'" src="'.
$OUTPUT->pix_url($dirgif.$gif, 'mod_game').'" alt="" border="0">&nbsp;';
echo '<input type="image" name="Quit" id="Quit" Title="'.get_string( 'millionaire_quit', 'game').'" src="'.$OUTPUT->pix_url($dirgif.'x', 'mod_game').'" alt="" border="0">&nbsp;'; echo '<input type="image" name="Quit" id="Quit" Title="'.
get_string( 'millionaire_quit', 'game').'" src="'.
$OUTPUT->pix_url($dirgif.'x', 'mod_game').'" alt="" border="0">&nbsp;';
echo "\r\n"; echo "\r\n";
echo "</td>\r\n"; echo "</td>\r\n";
$styletext = ""; $styletext = "";
if( strpos( $question, 'color:') == false and strpos( $question, 'background:') == false){ if (strpos( $question, 'color:') == false and strpos( $question, 'background:') == false) {
$styletext = "style='$stylequestion'"; $styletext = "style='$stylequestion'";
} }
$aVal = array( 100, 200, 300, 400, 500, 1000, 1500, 2000, 4000, 5000, 10000, 20000, 40000, 80000, 150000); $aval = array( 100, 200, 300, 400, 500, 1000, 1500, 2000, 4000, 5000, 10000, 20000, 40000, 80000, 150000);
for( $i=15; $i >= 1; $i--) for ($i = 15; $i >= 1; $i--) {
{ $btr = false;
$bTR = false;
switch( $i) switch ($i) {
{
case 15: case 15:
echo "<td rowspan=".(16+count( $aAnswer))." $background>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\r\n"; echo "<td rowspan=".(16 + count( $aanswer)).
$bTR = true; "$background>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\r\n";
$btr = true;
break; break;
case 14: case 14:
case 13: case 13:
echo "<tr>\n"; echo "<tr>\n";
$bTR = true; $btr = true;
break; break;
case 12: case 12:
//$question = game_filterquestion($question, $query->questionid, $context->id, $game->course);
$question = game_show_query( $game, $query, $question); $question = game_show_query( $game, $query, $question);
echo "<tr>"; echo "<tr>";
echo "<td rowspan=12 colspan=2 valign=top style=\"$styletext\">$question</td>\r\n"; echo "<td rowspan=12 colspan=2 valign=top style=\"$styletext\">$question</td>\r\n";
$bTR = true; $btr = true;
break; break;
case 11: case 11:
case 10: case 10:
@ -194,65 +205,68 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
case 2: case 2:
case 1: case 1:
echo "<tr>"; echo "<tr>";
$bTR = true; $btr = true;
break; break;
default: default:
echo "<tr>"; echo "<tr>";
$bTR = true; $btr = true;
} }
if( $i == $level+1) if ($i == $level + 1) {
$style = "background:$color1;color:$color2"; $style = "background:$color1;color:$color2";
else } else {
$style = $stylequestion; $style = $stylequestion;
}
echo "<td style='$style' align=right>$i</td>"; echo "<td style='$style' align=right>$i</td>";
if( $i < $level+1) if ($i < $level + 1) {
echo "<td style='$style'>&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;</td>"; echo "<td style='$style'>&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;</td>";
else if( $i == 15 and $level <= 1) } else if ($i == 15 and $level <= 1) {
echo "<td style='$style'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>"; echo "<td style='$style'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
else } else {
echo "<td style='$style'></td>"; echo "<td style='$style'></td>";
echo "<td style='$style' align=right>".sprintf( "%10d", $aVal[ $i-1])."</td>\r\n"; }
if( $bTR) echo "<td style='$style' align=right>".sprintf( "%10d", $aval[ $i - 1])."</td>\r\n";
if ($btr) {
echo "</tr>\r\n"; echo "</tr>\r\n";
} }
}
echo "<tr $background><td colspan=10>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>\r\n"; echo "<tr $background><td colspan=10>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>\r\n";
$bFirst = true; $bfirst = true;
$letters = get_string( 'lettersall', 'game'); $letters = get_string( 'lettersall', 'game');
for( $i=1; $i <= count( $aAnswer); $i++) for ($i = 1; $i <= count( $aanswer); $i++) {
{
$name = "btAnswer".$i; $name = "btAnswer".$i;
$s = game_substr( $letters, $i-1, 1); $s = game_substr( $letters, $i - 1, 1);
$disabled = ( $state == 15 ? "disabled=1" : ""); $disabled = ( $state == 15 ? "disabled=1" : "");
$style = $stylequestion; $style = $stylequestion;
if( (strpos( $aAnswer[ $i-1], 'color:') != false) or (strpos( $aAnswer[ $i-1], 'background:') != false)){ if ((strpos( $aanswer[ $i - 1], 'color:') != false) or (strpos( $aanswer[ $i - 1], 'background:') != false)) {
$style = ''; $style = '';
} }
if( $state == 15 and $i+1 == $query->correct){ if ($state == 15 and $i + 1 == $query->correct) {
$style = $stylequestionselected; $style = $stylequestionselected;
} }
$button = '<input style="'.$style.'" '.$disabled.'type="submit" name="'.$name.'" value="'.$s.'" id="'.$name."1\"". $button = '<input style="'.$style.'" '.$disabled.'type="submit" name="'.$name.'" value="'.$s.'" id="'.$name."1\"".
" onmouseover=\"this.style.backgroundColor = '$color2';$name.style.backgroundColor = '$color2';\" ". " onmouseover=\"this.style.backgroundColor = '$color2';$name.style.backgroundColor = '$color2';\" ".
" onmouseout=\"this.style.backgroundColor = '$colorback';$name.style.backgroundColor = '$colorback';\" >"; " onmouseout=\"this.style.backgroundColor = '$colorback';$name.style.backgroundColor = '$colorback';\" >";
$text = game_filtertext($aAnswer[ $i-1],$game->course); $text = game_filtertext($aanswer[ $i - 1], $game->course);
$answer = "<span id=$name style=\"$style\" ". $answer = "<span id=$name style=\"$style\" ".
" onmouseover=\"this.style.backgroundColor = '$color2';{$name}1.style.backgroundColor = '$color2';\" ". " onmouseover=\"this.style.backgroundColor = '$color2';{$name}1.style.backgroundColor = '$color2';\" ".
" onmouseout=\"this.style.backgroundColor = '$colorback';{$name}1.style.backgroundColor = '$colorback';\" >". " onmouseout=\"this.style.backgroundColor = '$colorback';{$name}1.style.backgroundColor = '$colorback';\" >".
$text.'</span>'; $text.'</span>';
if( $aAnswer[ $i-1] != ""){ if ($aanswer[ $i - 1] != "") {
echo "<tr>\n"; echo "<tr>\n";
echo "<td style='$stylequestion'> $button</td>\n"; echo "<td style='$stylequestion'> $button</td>\n";
echo "<td $style width=100%> &nbsp; $answer</td>"; echo "<td $style width=100%> &nbsp; $answer</td>";
if( $bFirst){ if ($bfirst) {
$bFirst = false; $bfirst = false;
$info = game_filtertext($info, $game->course); $info = game_filtertext($info, $game->course);
echo "<td style=\"$style\" rowspan=".count( $aAnswer)." colspan=3>$info</td>"; echo "<td style=\"$style\" rowspan=".count( $aanswer)." colspan=3>$info</td>";
} }
echo "\r\n</tr>\r\n"; echo "\r\n</tr>\r\n";
} }
@ -260,69 +274,65 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
echo "<tr><td colspan=10 $background>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>\r\n"; echo "<tr><td colspan=10 $background>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>\r\n";
echo "<input type=hidden name=state value=\"$state\">\r\n"; echo "<input type=hidden name=state value=\"$state\">\r\n";
echo '<input type=hidden name=id value="'.$id.'">'; echo '<input type=hidden name=id value="'.$id.'">';
echo "<input type=hidden name=buttons value=\"".count( $aAnswer)."\">\r\n"; echo "<input type=hidden name=buttons value=\"".count( $aanswer)."\">\r\n";
echo "</table>\r\n"; echo "</table>\r\n";
echo "</form>\r\n"; echo "</form>\r\n";
} }
function game_millionaire_ShowNextQuestion( $id, $game, $attempt, $millionaire, $context) function game_millionaire_shownextquestion( $id, $game, $attempt, $millionaire, $context) {
{ game_millionaire_selectquestion( $aanswer, $game, $attempt, $millionaire, $query, $context);
game_millionaire_SelectQuestion( $aAnswer, $game, $attempt, $millionaire, $query, $context);
if( $game->toptext != ''){ if ($game->toptext != '') {
echo $game->toptext.'<br><br>'; echo $game->toptext.'<br><br>';
} }
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, "", $context); game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, "", $context);
if( $game->bottomtext != ''){ if ($game->bottomtext != '') {
echo '<br>'.$game->bottomtext; echo '<br>'.$game->bottomtext;
} }
} }
//updates tables: games_millionaire, game_attempts, game_questions // Updates tables: games_millionaire, game_attempts, game_questions.
function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$millionaire, &$query, $context) function game_millionaire_selectquestion( &$aanswer, $game, $attempt, &$millionaire, &$query, $context) {
{
global $DB, $USER; global $DB, $USER;
if( ($game->sourcemodule != 'quiz') and ($game->sourcemodule != 'question')){ if (($game->sourcemodule != 'quiz') and ($game->sourcemodule != 'question')) {
print_error( get_string('millionaire_sourcemodule_must_quiz_question', 'game', get_string( 'modulename', 'quiz')).' '.get_string( 'modulename', $attempt->sourcemodule)); print_error( get_string('millionaire_sourcemodule_must_quiz_question', 'game',
get_string( 'modulename', 'quiz')).' '.get_string( 'modulename', $attempt->sourcemodule));
} }
if( $millionaire->queryid != 0){ if ($millionaire->queryid != 0) {
game_millionaire_loadquestions( $game, $millionaire, $query, $aAnswer, $context); game_millionaire_loadquestions( $game, $millionaire, $query, $aanswer, $context);
return; return;
} }
if( $game->sourcemodule == 'quiz'){ if ($game->sourcemodule == 'quiz') {
if( $game->quizid == 0){ if ($game->quizid == 0) {
print_error( get_string( 'must_select_quiz', 'game')); print_error( get_string( 'must_select_quiz', 'game'));
} }
if( game_get_moodle_version() < '02.07') if (game_get_moodle_version() < '02.07') {
{
$select = "qtype='multichoice' AND quiz='$game->quizid' AND qmo.questionid=q.id". $select = "qtype='multichoice' AND quiz='$game->quizid' AND qmo.questionid=q.id".
" AND qqi.question=q.id"; " AND qqi.question=q.id";
$table = "{quiz_question_instances} qqi,{question} q, {qtype_multichoice_options} qmo"; $table = "{quiz_question_instances} qqi,{question} q, {qtype_multichoice_options} qmo";
$order = ''; $order = '';
}else } else {
{
$select = "qtype='multichoice' AND qs.quizid='$game->quizid' AND qmo.questionid=q.id". $select = "qtype='multichoice' AND qs.quizid='$game->quizid' AND qmo.questionid=q.id".
" AND qs.questionid=q.id"; " AND qs.questionid=q.id";
$table = "{quiz_slots} qs,{question} q, {qtype_multichoice_options} qmo"; $table = "{quiz_slots} qs,{question} q, {qtype_multichoice_options} qmo";
$order = 'qs.page,qs.slot'; $order = 'qs.page,qs.slot';
} }
}else } else {
{ if ($game->questioncategoryid == 0) {
if( $game->questioncategoryid == 0){
print_error( get_string( 'must_select_questioncategory', 'game')); print_error( get_string( 'must_select_questioncategory', 'game'));
} }
//include subcategories // Include subcategories.
$select = 'category='.$game->questioncategoryid; $select = 'category='.$game->questioncategoryid;
if( $game->subcategories){ if ($game->subcategories) {
$cats = question_categorylist( $game->questioncategoryid); $cats = question_categorylist( $game->questioncategoryid);
if( count( $cats)){ if (count( $cats)) {
$select = 'q.category in ('.implode(',', $cats).')'; $select = 'q.category in ('.implode(',', $cats).')';
} }
} }
@ -331,12 +341,13 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
$table = '{question} q, {qtype_multichoice_options} qmo'; $table = '{question} q, {qtype_multichoice_options} qmo';
} }
$select .= ' AND hidden=0'; $select .= ' AND hidden=0';
if( $game->shuffle or $game->quizid == 0) if ($game->shuffle or $game->quizid == 0) {
$questionid = game_question_selectrandom( $game, $table, $select, 'q.id as id', true); $questionid = game_question_selectrandom( $game, $table, $select, 'q.id as id', true);
else } else {
$questionid = game_millionaire_select_serial_question( $game, $table, $select, 'q.id as id', $millionaire->level, $order); $questionid = game_millionaire_select_serial_question( $game, $table, $select, 'q.id as id', $millionaire->level, $order);
}
if( $questionid == 0){ if ($questionid == 0) {
print_error( get_string( 'no_questions', 'game')); print_error( get_string( 'no_questions', 'game'));
} }
@ -344,34 +355,34 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
$recs = $DB->get_records( 'question_answers', array( 'question' => $questionid)); $recs = $DB->get_records( 'question_answers', array( 'question' => $questionid));
if( $recs === false){ if ($recs === false) {
print_error( get_string( 'no_questions', 'game')); print_error( get_string( 'no_questions', 'game'));
} }
$correct = 0; $correct = 0;
$ids = array(); $ids = array();
foreach( $recs as $rec){ foreach ($recs as $rec) {
$aAnswer[] = game_filterquestion_answer(str_replace( '\"', '"', $rec->answer), $rec->id, $context->id, $game->course); $aanswer[] = game_filterquestion_answer(str_replace( '\"', '"', $rec->answer), $rec->id, $context->id, $game->course);
$ids[] = $rec->id; $ids[] = $rec->id;
if( $rec->fraction == 1){ if ($rec->fraction == 1) {
$correct = $rec->id; $correct = $rec->id;
} }
} }
$count = count( $aAnswer); $count = count( $aanswer);
for($i=1; $i <= $count; $i++){ for ($i = 1; $i <= $count; $i++) {
$sel = mt_rand(0, $count-1); $sel = mt_rand(0, $count - 1);
$temp = array_splice( $aAnswer, $sel, 1); $temp = array_splice( $aanswer, $sel, 1);
$aAnswer[ ] = $temp[ 0]; $aanswer[ ] = $temp[ 0];
$temp = array_splice( $ids, $sel, 1); $temp = array_splice( $ids, $sel, 1);
$ids[ ] = $temp[ 0]; $ids[ ] = $temp[ 0];
} }
$query = new StdClass; $query = new StdClass;
$query->attemptid =$attempt->id; $query->attemptid = $attempt->id;
$query->gamekind = $game->gamekind; $query->gamekind = $game->gamekind;
$query->gameid = $game->id; $query->gameid = $game->id;
$query->userid = $USER->id; $query->userid = $USER->id;
@ -381,8 +392,7 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
$query->questiontext = addslashes( $q->questiontext); $query->questiontext = addslashes( $q->questiontext);
$query->answertext = implode( ',', $ids); $query->answertext = implode( ',', $ids);
$query->correct = array_search( $correct, $ids) + 1; $query->correct = array_search( $correct, $ids) + 1;
if( !$query->id = $DB->insert_record( 'game_queries', $query)){ if (!$query->id = $DB->insert_record( 'game_queries', $query)) {
print_object( $query);
print_error( 'error inserting to game_queries'); print_error( 'error inserting to game_queries');
} }
@ -390,7 +400,7 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
$updrec->id = $millionaire->id; $updrec->id = $millionaire->id;
$updrec->queryid = $query->id; $updrec->queryid = $query->id;
if( !$newid = $DB->update_record( 'game_millionaire', $updrec)){ if (!$newid = $DB->update_record( 'game_millionaire', $updrec)) {
print_error( 'error updating in game_millionaire'); print_error( 'error updating in game_millionaire');
} }
@ -399,51 +409,53 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
game_update_queries( $game, $attempt, $query, $score, ''); game_update_queries( $game, $attempt, $query, $score, '');
} }
function game_millionaire_select_serial_question( $game, $table, $select, $id_fields="id", $level, $order) function game_millionaire_select_serial_question( $game, $table, $select, $idfields = "id", $level, $order) {
{
global $DB, $USER; global $DB, $USER;
$sql = "SELECT $id_fields,$id_fields FROM ".$table." WHERE $select "; $sql = "SELECT $idfields,$id_fields FROM ".$table." WHERE $select ";
if( $order != '') if ($order != '') {
$sql .= " ORDER BY $order"; $sql .= " ORDER BY $order";
}
if( ($recs = $DB->get_records_sql( $sql)) == false) if (($recs = $DB->get_records_sql( $sql)) == false) {
return false; return false;
}
$questions = array(); $questions = array();
foreach( $recs as $rec) foreach ($recs as $rec) {
$questions[] = $rec->id; $questions[] = $rec->id;
}
$count = count( $questions); $count = count( $questions);
if( $count == 0) if ($count == 0) {
return false; return false;
}
$from = round($level * ($count-1) / 15); $from = round($level * ($count - 1) / 15);
$to = round(max( $from, ($level+1) * ($count-1) / 15))-1; $to = round(max( $from, ($level + 1) * ($count - 1) / 15)) - 1;
if( $to < $from) if ($to < $from) {
$to = $from; $to = $from;
}
$pos = mt_rand( round( $from), round( $to)); $pos = mt_rand( round( $from), round( $to));
return $questions[ $pos]; return $questions[ $pos];
} }
function game_millionaire_loadquestions( $game, $millionaire, &$query, &$aAnswer, $context) function game_millionaire_loadquestions( $game, $millionaire, &$query, &$aanswer, $context) {
{
global $DB; global $DB;
$query = $DB->get_record( 'game_queries', array( 'id' => $millionaire->queryid), 'id,questiontext,answertext,correct,questionid'); $query = $DB->get_record( 'game_queries', array( 'id' => $millionaire->queryid),
'id,questiontext,answertext,correct,questionid');
$aids = explode( ',', $query->answertext); $aids = explode( ',', $query->answertext);
$aAnswer = array(); $aanswer = array();
foreach( $aids as $id) foreach ($aids as $id) {
{
$rec = $DB->get_record( 'question_answers', array( 'id' => $id), 'id,answer'); $rec = $DB->get_record( 'question_answers', array( 'id' => $id), 'id,answer');
$aAnswer[] = game_filterquestion_answer(str_replace( '\"', '"', $rec->answer), $id, $context->id, $game->course); $aanswer[] = game_filterquestion_answer(str_replace( '\"', '"', $rec->answer), $id, $context->id, $game->course);
} }
} }
//flag 1:5050, 2:telephone 4:people // Flag 1:5050, 2:telephone 4:people.
function game_millionaire_setstate( &$millionaire, $mask) function game_millionaire_setstate( &$millionaire, $mask) {
{
global $DB; global $DB;
$millionaire->state |= $mask; $millionaire->state |= $mask;
@ -451,138 +463,124 @@ function game_millionaire_setstate( &$millionaire, $mask)
$updrec = new stdClass(); $updrec = new stdClass();
$updrec->id = $millionaire->id; $updrec->id = $millionaire->id;
$updrec->state = $millionaire->state; $updrec->state = $millionaire->state;
if( !$DB->update_record( 'game_millionaire', $updrec)){ if (!$DB->update_record( 'game_millionaire', $updrec)) {
print_error( 'error updating in game_millionaire'); print_error( 'error updating in game_millionaire');
} }
} }
function game_millionaire_onhelp5050( $game, $id, &$millionaire, $query, $context) {
game_millionaire_loadquestions( $game, $millionaire, $query, $aanswer, $context);
function game_millionaire_onhelp5050( $game, $id, &$millionaire, $query, $context) if (($millionaire->state & 1) != 0) {
{ game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, '', $context);
game_millionaire_loadquestions( $game, $millionaire, $query, $aAnswer, $context);
if( ($millionaire->state & 1) != 0)
{
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, '', $context);
return; return;
} }
game_millionaire_setstate( $millionaire, 1); game_millionaire_setstate( $millionaire, 1);
$n = count( $aAnswer); $n = count( $aanswer);
if( $n > 2) if ($n > 2) {
{ for (;;) {
for(;;)
{
$wrong = mt_rand( 1, $n); $wrong = mt_rand( 1, $n);
if( $wrong != $query->correct){ if ($wrong != $query->correct) {
break; break;
} }
} }
for( $i=1; $i <= $n; $i++) for ($i = 1; $i <= $n; $i++) {
{ if ($i <> $wrong and $i <> $query->correct) {
if( $i <> $wrong and $i <> $query->correct){ $aanswer[ $i - 1] = "";
$aAnswer[ $i-1] = "";
} }
} }
} }
game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer, '', $context); game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, '', $context);
} }
function game_millionaire_OnHelpTelephone( $game, $id, &$millionaire, $query, $context) function game_millionaire_onhelptelephone( $game, $id, &$millionaire, $query, $context) {
{ game_millionaire_loadquestions( $game, $millionaire, $query, $aanswer, $context);
game_millionaire_loadquestions( $game, $millionaire, $query, $aAnswer, $context);
if( ($millionaire->state & 2) != 0) if (($millionaire->state & 2) != 0) {
{ game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aanswer, '', $context);
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, '', $context);
return; return;
} }
game_millionaire_setstate( $millionaire, 2); game_millionaire_setstate( $millionaire, 2);
$n = count( $aAnswer); $n = count( $aanswer);
if( $n < 2){ if ($n < 2) {
$wrong = $query->correct; $wrong = $query->correct;
}else } else {
{ for (;;) {
for(;;)
{
$wrong = mt_rand( 1, $n); $wrong = mt_rand( 1, $n);
if( $wrong != $query->correct) if ($wrong != $query->correct) {
break; break;
} }
} }
//with 80% gives the correct answer }
if( mt_rand( 1, 10) <= 8)
// With 80% gives the correct answer.
if (mt_rand( 1, 10) <= 8) {
$response = $query->correct; $response = $query->correct;
else } else {
$response = $wrong; $response = $wrong;
}
$info = get_string( 'millionaire_info_telephone','game').'<br><b>'.$aAnswer[ $response-1].'</b>'; $info = get_string( 'millionaire_info_telephone', 'game').'<br><b>'.$aanswer[ $response - 1].'</b>';
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, $info, $context); game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, $info, $context);
} }
function game_millionaire_OnHelpPeople( $game, $id, &$millionaire, $query, $context) function game_millionaire_onhelppeople( $game, $id, &$millionaire, $query, $context) {
{ game_millionaire_loadquestions( $game, $millionaire, $query, $aanswer, $context);
game_millionaire_loadquestions( $game, $millionaire, $query, $aAnswer, $context);
if( ($millionaire->state & 4) != 0){ if (($millionaire->state & 4) != 0) {
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, '', $context); game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, '', $context);
return; return;
} }
game_millionaire_setstate( $millionaire, 4); game_millionaire_setstate( $millionaire, 4);
$n = count( $aAnswer); $n = count( $aanswer);
$sum = 0; $sum = 0;
$aPercent = array(); $apercent = array();
for( $i = 0; $i+1 < $n; $i++) for ($i = 0; $i + 1 < $n; $i++) {
{ $percent = mt_rand( 0, 100 - $sum);
$percent = mt_rand( 0, 100-$sum); $apercent[ $i] = $percent;
$aPercent[ $i] = $percent;
$sum += $percent; $sum += $percent;
} }
$aPercent[ $n-1] = 100 - $sum; $apercent[ $n - 1] = 100 - $sum;
if( mt_rand( 1, 100) <= 80) if (mt_rand( 1, 100) <= 80) {
{ // With percent 80% sets in the correct answer the biggest percent.
//with percent 80% sets in the correct answer the biggest percent $maxpos = 0;
$max_pos = 0; for ($i = 1; $i + 1 < $n; $i++) {
for( $i=1; $i+1 < $n; $i++) if ($apercent[ $i] >= $apercent[ $maxpos]) {
{ $maxpos = $i;
if( $aPercent[ $i] >= $aPercent[ $max_pos])
$max_pos = $i;
} }
$temp = $aPercent[ $max_pos]; $temp = $apercent[ $maxpos];
$aPercent[ $max_pos] = $aPercent[ $query->correct-1]; $apercent[ $maxpos] = $apercent[ $query->correct - 1];
$aPercent[ $query->correct-1] = $temp; $apercent[ $query->correct - 1] = $temp;
} }
$info = '<br>'.get_string( 'millionaire_info_people', 'game').':<br>';
for( $i=0; $i < $n; $i++){
$info .= "<br>". game_substr( get_string( 'lettersall', 'game'), $i, 1) ." : ".$aPercent[ $i]. ' %';
} }
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, game_substr( $info, 4), $context); $info = '<br>'.get_string( 'millionaire_info_people', 'game').':<br>';
for ($i = 0; $i < $n; $i++) {
$info .= "<br>". game_substr( get_string( 'lettersall', 'game'), $i, 1) ." : ".$apercent[ $i]. ' %';
} }
game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, game_substr( $info, 4), $context);
}
function game_millionaire_OnAnswer( $id, $game, $attempt, &$millionaire, $query, $answer, $context) function game_millionaire_onanswer( $id, $game, $attempt, &$millionaire, $query, $answer, $context) {
{
global $DB; global $DB;
game_millionaire_loadquestions( $game, $millionaire, $query, $aAnswer, $context); game_millionaire_loadquestions( $game, $millionaire, $query, $aanswer, $context);
if( $answer == $query->correct) if ($answer == $query->correct) {
{ if ($millionaire->level < 15) {
if( $millionaire->level < 15){
$millionaire->level++; $millionaire->level++;
} }
$finish = ($millionaire->level == 15 ? 1 : 0); $finish = ($millionaire->level == 15 ? 1 : 0);
$scorequestion = 1; $scorequestion = 1;
}else } else {
{
$finish = 1; $finish = 1;
$scorequestion = 0; $scorequestion = 0;
} }
@ -596,35 +594,30 @@ function game_millionaire_onhelp5050( $game, $id, &$millionaire, $query, $conte
$updrec->id = $millionaire->id; $updrec->id = $millionaire->id;
$updrec->level = $millionaire->level; $updrec->level = $millionaire->level;
$updrec->queryid = 0; $updrec->queryid = 0;
if( !$DB->update_record( 'game_millionaire', $updrec)){ if (!$DB->update_record( 'game_millionaire', $updrec)) {
print_error( 'error updating in game_millionaire'); print_error( 'error updating in game_millionaire');
} }
if( $answer == $query->correct) if ($answer == $query->correct) {
{ // Correct.
//correct if ($finish) {
if( $finish){
echo get_string( 'win', 'game'); echo get_string( 'win', 'game');
game_millionaire_OnQuit( $id, $game, $attempt, $query); game_millionaire_OnQuit( $id, $game, $attempt, $query);
}else } else {
{ $millionaire->queryid = 0; // So the next function select a new question.
$millionaire->queryid = 0; //so the next function select a new question
game_millionaire_ShowNextQuestion( $id, $game, $attempt, $millionaire, $context);
} }
}else game_millionaire_ShowNextQuestion( $id, $game, $attempt, $millionaire, $context);
{ } else {
//wrong answer // Wrong answer.
$info = get_string( 'millionaire_info_wrong_answer', 'game'). $info = get_string( 'millionaire_info_wrong_answer', 'game').
'<br><br><b><center>'.$aAnswer[ $query->correct-1].'</b>'; '<br><br><b><center>'.$aanswer[ $query->correct - 1].'</b>';
$millionaire->state = 15; $millionaire->state = 15;
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, $info, $context); game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aanswer, $info, $context);
}
} }
}
function game_millionaire_onquit( $id, $game, $attempt, $query) function game_millionaire_onquit( $id, $game, $attempt, $query) {
{
global $CFG, $DB; global $CFG, $DB;
game_updateattempts( $game, $attempt, -1, true); game_updateattempts( $game, $attempt, -1, true);
@ -634,7 +627,7 @@ function game_millionaire_onhelp5050( $game, $id, &$millionaire, $query, $conte
} }
echo '<br>'; echo '<br>';
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id\">".get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; '; echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id\">".
get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
echo "<a href=\"{$CFG->wwwroot}/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> '; echo "<a href=\"{$CFG->wwwroot}/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> ';
} }

66
report/default.php

@ -1,49 +1,63 @@
<?php // $Id: default.php,v 1.2 2012/07/25 11:16:07 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
//////////////////////////////////////////////////////////////////// //
/// Default class for report plugins // Moodle is free software: you can redistribute it and/or modify
/// // it under the terms of the GNU General Public License as published by
/// Doesn't do anything on it's own -- it needs to be extended. // the Free Software Foundation, either version 3 of the License, or
/// This class displays quiz reports. Because it is called from // (at your option) any later version.
/// within /mod/game/report.php you can assume that the page header //
/// and footer are taken care of. // Moodle is distributed in the hope that it will be useful,
/// // but WITHOUT ANY WARRANTY; without even the implied warranty of
/// This file can refer to itself as report.php to pass variables // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// to itself - all these will also be globally available. You must // GNU General Public License for more details.
/// pass "id=$cm->id" or q=$quiz->id", and "mode=reportname". //
//////////////////////////////////////////////////////////////////// // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// Included by ../report.php
/*
* Default class for report plugins
*
* Doesn't do anything on it's own -- it needs to be extended.
* This class displays quiz reports. Because it is called from
* within /mod/game/report.php you can assume that the page header
* and footer are taken care of.
*
* This file can refer to itself as report.php to pass variables
* to itself - all these will also be globally available. You must
* pass "id=$cm->id" or q=$quiz->id", and "mode=reportname".
*/
// Included by ../report.php.
class game_default_report { class game_default_report {
function display($cm, $course, $game) { /// This function just displays the report public function display($cm, $course, $game) {
// This function just displays the report.
return true; return true;
} }
function print_header_and_tabs($cm, $course, $game, $reportmode="overview", $meta=""){ public function print_header_and_tabs($cm, $course, $game, $reportmode = "overview", $meta = "") {
global $CFG; global $CFG;
/// Define some strings
// Define some strings.
$strgames = get_string("modulenameplural", "game"); $strgames = get_string("modulenameplural", "game");
$strgame = get_string("modulename", "game"); $strgame = get_string("modulename", "game");
/// Print the page header
if( function_exists( 'build_navigation')){ // Print the page header.
if (function_exists( 'build_navigation')) {
$navigation = build_navigation('', $cm); $navigation = build_navigation('', $cm);
echo $OUTPUT->heading( $course->shortname, $course->shortname, $navigation); echo $OUTPUT->heading( $course->shortname, $course->shortname, $navigation);
}else{ } else {
echo $OUTPUT->heading(format_string($game->name), "", echo $OUTPUT->heading(format_string($game->name), "",
"<a href=\"index.php?id=$course->id\">$strgames</a> "<a href=\"index.php?id=$course->id\">$strgames</a>
-> ".format_string($game->name), -> ".format_string($game->name),
'', $meta, true, update_module_button($cm->id, $course->id, $strgame), navmenu($course, $cm)); '', $meta, true, update_module_button($cm->id, $course->id, $strgame), navmenu($course, $cm));
} }
/// Print the tabs // Print the tabs.
$currenttab = 'reports'; $currenttab = 'reports';
$mode = $reportmode; $mode = $reportmode;
include('tabs.php'); require('tabs.php');
} }
} }
?>

320
report/overview/report.php

@ -1,4 +1,19 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This script lists student attempts * This script lists student attempts
* *
@ -15,38 +30,38 @@ class game_report extends game_default_report {
/** /**
* Display the report. * Display the report.
*/ */
function display($game, $cm, $course) { public function display($game, $cm, $course) {
global $CFG, $SESSION, $db, $QTYPES; global $CFG, $SESSION, $db, $QTYPES;
// Define some strings // Define some strings.
$strreallydel = addslashes(get_string('deleteattemptcheck','game')); $strreallydel = addslashes(get_string('deleteattemptcheck', 'game'));
$strtimeformat = get_string('strftimedatetime'); $strtimeformat = get_string('strftimedatetime');
$strreviewquestion = get_string('reviewresponse', 'quiz'); $strreviewquestion = get_string('reviewresponse', 'quiz');
// Only print headers if not asked to download data // Only print headers if not asked to download data.
if (!$download = optional_param('download', NULL)) { if (!$download = optional_param('download', null)) {
$this->print_header_and_tabs($cm, $course, $game, $reportmode="overview"); $this->print_header_and_tabs($cm, $course, $game, $reportmode = "overview");
} }
// Deal with actions // Deal with actions.
$action = optional_param('action', '', PARAM_ACTION); $action = optional_param('action', '', PARAM_ACTION);
switch($action) { switch ($action) {
case 'delete': // Some attempts need to be deleted case 'delete': // Some attempts need to be deleted.
$attemptids = optional_param('attemptid', array(), PARAM_INT); $attemptids = optional_param('attemptid', array(), PARAM_INT);
foreach($attemptids as $attemptid) { foreach ($attemptids as $attemptid) {
if ($attemptid && $todelete = get_record('game_attempts', 'id', $attemptid)) { if ($attemptid && $todelete = get_record('game_attempts', 'id', $attemptid)) {
delete_records('game_attempts', 'id', $attemptid); delete_records('game_attempts', 'id', $attemptid);
delete_records('game_queries', 'attemptid', $attemptid); delete_records('game_queries', 'attemptid', $attemptid);
// Search game_attempts for other instances by this user. // Search game_attempts for other instances by this user.
// If none, then delete record for this game, this user from game_grades // If none, then delete record for this game, this user from game_grades.
// else recalculate best grade // else recalculate best grade.
$userid = $todelete->userid; $userid = $todelete->userid;
if (!record_exists('game_attempts', 'userid', $userid, 'gameid', $game->id)) { if (!record_exists('game_attempts', 'userid', $userid, 'gameid', $game->id)) {
delete_records('game_grades', 'userid', $userid,'gameid', $game->id); delete_records('game_grades', 'userid', $userid, 'gameid', $game->id);
} else { } else {
game_save_best_score( $game, $userid); game_save_best_score( $game, $userid);
} }
@ -55,12 +70,14 @@ class game_report extends game_default_report {
break; break;
} }
// Print information on the number of existing attempts // Print information on the number of existing attempts.
if (!$download) { //do not print notices when downloading if (!$download) {
// Do not print notices when downloading.
if ($attemptnum = count_records('game_attempts', 'gameid', $game->id)) { if ($attemptnum = count_records('game_attempts', 'gameid', $game->id)) {
$a = new stdClass; $a = new stdClass;
$a->attemptnum = $attemptnum; $a->attemptnum = $attemptnum;
$a->studentnum = count_records_select('game_attempts', "gameid = '$game->id' AND preview = '0'", 'COUNT(DISTINCT userid)'); $a->studentnum = count_records_select('game_attempts',
"gameid = '$game->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
$a->studentstring = $course->students; $a->studentstring = $course->students;
notify( get_string('numattempts', 'game', $a)); notify( get_string('numattempts', 'game', $a));
@ -68,8 +85,8 @@ class game_report extends game_default_report {
} }
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// find out current groups mode // Find out current groups mode.
if ($groupmode = groupmode($course, $cm)) { // Groups are being used if ($groupmode = groupmode($course, $cm)) { // Groups are being used.
if (!$download) { if (!$download) {
$currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id&amp;mode=overview"); $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id&amp;mode=overview");
} else { } else {
@ -79,7 +96,7 @@ class game_report extends game_default_report {
$currentgroup = get_and_set_current_group($course, $groupmode); $currentgroup = get_and_set_current_group($course, $groupmode);
} }
// Set table options // Set table options.
$noattempts = optional_param('noattempts', 0, PARAM_INT); $noattempts = optional_param('noattempts', 0, PARAM_INT);
$detailedmarks = optional_param('detailedmarks', 0, PARAM_INT); $detailedmarks = optional_param('detailedmarks', 0, PARAM_INT);
$pagesize = optional_param('pagesize', 10, PARAM_INT); $pagesize = optional_param('pagesize', 10, PARAM_INT);
@ -88,24 +105,25 @@ class game_report extends game_default_report {
$pagesize = 10; $pagesize = 10;
} }
// Now check if asked download of data // Now check if asked download of data.
if ($download) { if ($download) {
$filename = clean_filename("$course->shortname ".format_string($game->name,true)); $filename = clean_filename("$course->shortname ".format_string($game->name, true));
$sort = ''; $sort = '';
} }
// Define table columns // Define table columns.
$tablecolumns = array('checkbox', 'picture', 'fullname', 'timestart', 'timefinish', 'duration'); $tablecolumns = array('checkbox', 'picture', 'fullname', 'timestart', 'timefinish', 'duration');
$tableheaders = array(NULL, '', get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted','game'), get_string('attemptduration', 'game')); $tableheaders = array(null, '', get_string('fullname'), get_string('startedon', 'game'),
get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
if ($game->grade) { if ($game->grade) {
$tablecolumns[] = 'grade'; $tablecolumns[] = 'grade';
$tableheaders[] = get_string('grade', 'game').'/'.$game->grade; $tableheaders[] = get_string('grade', 'game').'/'.$game->grade;
} }
if($detailedmarks) { if ($detailedmarks) {
// we want to display marks for all questions // We want to display marks for all questions.
// Start by getting all questions // Start by getting all questions.
$questionlist = game_questions_in_game( $game->questions); $questionlist = game_questions_in_game( $game->questions);
$questionids = explode(',', $questionlist); $questionids = explode(',', $questionlist);
$sql = "SELECT q.*, i.score AS maxgrade, i.id AS instance". $sql = "SELECT q.*, i.score AS maxgrade, i.id AS instance".
@ -117,15 +135,15 @@ class game_report extends game_default_report {
print_error('No questions found'); print_error('No questions found');
} }
$number = 1; $number = 1;
foreach($questionids as $key => $id) { foreach ($questionids as $key => $id) {
if ($questions[$id]->length) { if ($questions[$id]->length) {
// Only print questions of non-zero length // Only print questions of non-zero length.
$tablecolumns[] = '$'.$id; $tablecolumns[] = '$'.$id;
$tableheaders[] = '#'.$number; $tableheaders[] = '#'.$number;
$questions[$id]->number = $number; $questions[$id]->number = $number;
$number += $questions[$id]->length; $number += $questions[$id]->length;
} else { } else {
// get rid of zero length questions // Get rid of zero length questions.
unset($questions[$id]); unset($questions[$id]);
unset($questionids[$key]); unset($questionids[$key]);
} }
@ -138,7 +156,7 @@ class game_report extends game_default_report {
} }
if (!$download) { if (!$download) {
// Set up the table // Set up the table.
$table = new flexible_table('mod-game-report-overview-report'); $table = new flexible_table('mod-game-report-overview-report');
@ -160,20 +178,20 @@ class game_report extends game_default_report {
$table->set_attribute('id', 'attempts'); $table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox'); $table->set_attribute('class', 'generaltable generalbox');
// Start working -- this is necessary as soon as the niceties are over // Start working -- this is necessary as soon as the niceties are over.
$table->setup(); $table->setup();
} else if ($download =='ODS') { } else if ($download == 'ODS') {
require_once("$CFG->libdir/odslib.class.php"); require_once("$CFG->libdir/odslib.class.php");
$filename .= ".ods"; $filename .= ".ods";
// Creating a workbook // Creating a workbook.
$workbook = new MoodleODSWorkbook("-"); $workbook = new MoodleODSWorkbook("-");
// Sending HTTP headers // Sending HTTP headers.
$workbook->send($filename); $workbook->send($filename);
// Creating the first worksheet // Creating the first worksheet.
$sheettitle = get_string('reportoverview','game'); $sheettitle = get_string('reportoverview', 'game');
$myxls =& $workbook->add_worksheet($sheettitle); $myxls =& $workbook->add_worksheet($sheettitle);
// format types // Format types.
$format =& $workbook->add_format(); $format =& $workbook->add_format();
$format->set_bold(0); $format->set_bold(0);
$formatbc =& $workbook->add_format(); $formatbc =& $workbook->add_format();
@ -193,8 +211,8 @@ class game_report extends game_default_report {
$formatg->set_bold(1); $formatg->set_bold(1);
$formatg->set_color('green'); $formatg->set_color('green');
$formatg->set_align('center'); $formatg->set_align('center');
// Here starts workshhet headers
// Here starts workshhet headers.
$headers = array(get_string('fullname'), $headers = array(get_string('fullname'),
get_string('startedon', 'game'), get_string('startedon', 'game'),
get_string('timecompleted', 'game'), get_string('timecompleted', 'game'),
@ -204,7 +222,7 @@ class game_report extends game_default_report {
if ($game->grade) { if ($game->grade) {
$headers[] = get_string('grade', 'game').'/'.$game->grade; $headers[] = get_string('grade', 'game').'/'.$game->grade;
} }
if($detailedmarks) { if ($detailedmarks) {
foreach ($questionids as $id) { foreach ($questionids as $id) {
$headers[] = '#'.$questions[$id]->number; $headers[] = '#'.$questions[$id]->number;
} }
@ -214,22 +232,22 @@ class game_report extends game_default_report {
} }
$colnum = 0; $colnum = 0;
foreach ($headers as $item) { foreach ($headers as $item) {
$myxls->write(0,$colnum,$item,$formatbc); $myxls->write(0, $colnum, $item, $formatbc);
$colnum++; $colnum++;
} }
$rownum=1; $rownum = 1;
} else if ($download =='Excel') { } else if ($download == 'Excel') {
require_once("$CFG->libdir/excellib.class.php"); require_once("$CFG->libdir/excellib.class.php");
$filename .= ".xls"; $filename .= ".xls";
// Creating a workbook // Creating a workbook.
$workbook = new MoodleExcelWorkbook("-"); $workbook = new MoodleExcelWorkbook("-");
// Sending HTTP headers // Sending HTTP headers.
$workbook->send($filename); $workbook->send($filename);
// Creating the first worksheet // Creating the first worksheet.
$sheettitle = get_string('reportoverview','game'); $sheettitle = get_string('reportoverview', 'game');
$myxls =& $workbook->add_worksheet($sheettitle); $myxls =& $workbook->add_worksheet($sheettitle);
// format types // Format types.
$format =& $workbook->add_format(); $format =& $workbook->add_format();
$format->set_bold(0); $format->set_bold(0);
$formatbc =& $workbook->add_format(); $formatbc =& $workbook->add_format();
@ -249,14 +267,15 @@ class game_report extends game_default_report {
$formatg->set_bold(1); $formatg->set_bold(1);
$formatg->set_color('green'); $formatg->set_color('green');
$formatg->set_align('center'); $formatg->set_align('center');
// Here starts workshhet headers
$headers = array(get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game')); // Here starts workshhet headers.
$headers = array(get_string('fullname'), get_string('startedon', 'game'),
get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
if ($game->grade) { if ($game->grade) {
$headers[] = get_string('grade', 'game').'/'.$game->grade; $headers[] = get_string('grade', 'game').'/'.$game->grade;
} }
if($detailedmarks) { if ($detailedmarks) {
foreach ($questionids as $id) { foreach ($questionids as $id) {
$headers[] = '#'.$questions[$id]->number; $headers[] = '#'.$questions[$id]->number;
} }
@ -266,11 +285,11 @@ class game_report extends game_default_report {
} }
$colnum = 0; $colnum = 0;
foreach ($headers as $item) { foreach ($headers as $item) {
$myxls->write(0,$colnum,$item,$formatbc); $myxls->write(0, $colnum, $item, $formatbc);
$colnum++; $colnum++;
} }
$rownum=1; $rownum = 1;
} else if ($download=='CSV') { } else if ($download == 'CSV') {
$filename .= ".txt"; $filename .= ".txt";
header("Content-Type: application/download\n"); header("Content-Type: application/download\n");
@ -279,12 +298,13 @@ class game_report extends game_default_report {
header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Pragma: public"); header("Pragma: public");
$headers = get_string('fullname')."\t".get_string('startedon', 'game')."\t".get_string('timecompleted', 'game')."\t".get_string('attemptduration', 'game'); $headers = get_string('fullname')."\t".get_string('startedon', 'game').
"\t".get_string('timecompleted', 'game')."\t".get_string('attemptduration', 'game');
if ($game->grade) { if ($game->grade) {
$headers .= "\t".get_string('grade', 'game')."/".$game->grade; $headers .= "\t".get_string('grade', 'game')."/".$game->grade;
} }
if($detailedmarks) { if ($detailedmarks) {
foreach ($questionids as $id) { foreach ($questionids as $id) {
$headers .= "\t#".$questions[$id]->number; $headers .= "\t#".$questions[$id]->number;
} }
@ -297,48 +317,54 @@ class game_report extends game_default_report {
$contextlists = get_related_contexts_string( get_context_instance( CONTEXT_COURSE, $course->id)); $contextlists = get_related_contexts_string( get_context_instance( CONTEXT_COURSE, $course->id));
// Construct the SQL // Construct the SQL.
$select = 'SELECT qa.id,'.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, '. $select = 'SELECT qa.id,'.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, '.
'qa.id as attemptuniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, '. 'qa.id as attemptuniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, '.
// 'qa.uniqueid as attemptuniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, '.
'qa.score, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration '; 'qa.score, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
if ($course->id != SITEID) { // this is too complicated, so just do it for each of the four cases. if ($course->id != SITEID) {
// This is too complicated, so just do it for each of the four cases.
if (!empty($currentgroup) && empty($noattempts)) { if (!empty($currentgroup) && empty($noattempts)) {
// we want a particular group and we only want to see students WITH attempts. // We want a particular group and we only want to see students WITH attempts.
// So join on groups_members and do an inner join on attempts. // So join on groups_members and do an inner join on attempts.
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '. $from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
groups_members_join_sql(). groups_members_join_sql().
'JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id; 'JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
$where = ' WHERE ra.contextid ' . $contextlists . ' AND '. groups_members_where_sql($currentgroup) .' AND qa.preview = 0'; $where = ' WHERE ra.contextid ' . $contextlists .
' AND '. groups_members_where_sql($currentgroup) .' AND qa.preview = 0';
} else if (!empty($currentgroup) && !empty($noattempts)) { } else if (!empty($currentgroup) && !empty($noattempts)) {
// We want a particular group and we want to do something funky with attempts // We want a particular group and we want to do something funky with attempts.
// So join on groups_members and left join on attempts... // So join on groups_members and left join on attempts...
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '. $from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
groups_members_join_sql(). groups_members_join_sql().
'LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id; 'LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
$where = ' WHERE ra.contextid ' .$contextlists . ' AND '.groups_members_where_sql($currentgroup); $where = ' WHERE ra.contextid ' .$contextlists . ' AND '.groups_members_where_sql($currentgroup);
if ($noattempts == 1) { if ($noattempts == 1) {
// noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts) // Noattempts = 1 means only no attempts, so make the left join ask.
$where .= ' AND qa.userid IS NULL'; // show ONLY no attempts; // For only records where the right is null (no attempts).
$where .= ' AND qa.userid IS NULL'; // Show ONLY no attempts.
} else { } else {
// We are including attempts, so exclude previews. // We are including attempts, so exclude previews.
$where .= ' AND qa.preview = 0'; $where .= ' AND qa.preview = 0';
} }
} else if (empty($currentgroup)) { } else if (empty($currentgroup)) {
// We don't care about group, and we to do something funky with attempts // We don't care about group, and we to do something funky with attempts.
// So do a left join on attempts // So do a left join on attempts.
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id; $from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
' LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
$where = " WHERE ra.contextid $contextlists"; $where = " WHERE ra.contextid $contextlists";
if (empty($noattempts)) { if (empty($noattempts)) {
$where .= ' AND qa.userid IS NOT NULL AND qa.preview = 0'; // show ONLY students with attempts; // Show ONLY students with attempts.
$where .= ' AND qa.userid IS NOT NULL AND qa.preview = 0';
} else if ($noattempts == 1) { } else if ($noattempts == 1) {
// noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts) // The noattempts = 1 means only no attempts,.
$where .= ' AND qa.userid IS NULL'; // show ONLY students without attempts; // So make the left join ask for only records where the right is null (no attempts).
// Show ONLY students without attempts.
$where .= ' AND qa.userid IS NULL';
} else if ($noattempts == 3) { } else if ($noattempts == 3) {
// we want all attempts // We want all attempts.
$from = 'FROM {user} u JOIN {game_attempts} qa ON u.id = qa.userid '; $from = 'FROM {user} u JOIN {game_attempts} qa ON u.id = qa.userid ';
$where = ' WHERE qa.gameid = '.$game->id.' AND qa.preview = 0'; $where = ' WHERE qa.gameid = '.$game->id.' AND qa.preview = 0';
} // noattempts = 2 means we want all students, with or without attempts } // The noattempts = 2 means we want all students, with or without attempts.
} }
$countsql = 'SELECT COUNT(DISTINCT('.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).')) '.$from.$where; $countsql = 'SELECT COUNT(DISTINCT('.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).')) '.$from.$where;
} else { } else {
@ -349,36 +375,35 @@ class game_report extends game_default_report {
} }
} }
if (!$download) { if (!$download) {
// Add extra limits due to initials bar // Add extra limits due to initials bar.
if($table->get_sql_where()) { if ($table->get_sql_where()) {
$where .= ' AND '.$table->get_sql_where(); $where .= ' AND '.$table->get_sql_where();
} }
// Count the records NOW, before funky question grade sorting messes up $from // Count the records NOW, before funky question grade sorting messes up $from.
if (!empty($countsql)) { if (!empty($countsql)) {
$totalinitials = count_records_sql($countsql); $totalinitials = count_records_sql($countsql);
if ($table->get_sql_where()) { if ($table->get_sql_where()) {
$countsql .= ' AND '.$table->get_sql_where(); $countsql .= ' AND '.$table->get_sql_where();
} }
$total = count_records_sql($countsql); $total = count_records_sql($countsql);
} }
// Add extra limits due to sorting by question grade // Add extra limits due to sorting by question grade.
if($sort = $table->get_sql_sort()) { if ($sort = $table->get_sql_sort()) {
$sortparts = explode(',', $sort); $sortparts = explode(',', $sort);
$newsort = array(); $newsort = array();
$questionsort = false; $questionsort = false;
foreach($sortparts as $sortpart) { foreach ($sortparts as $sortpart) {
$sortpart = trim($sortpart); $sortpart = trim($sortpart);
if(substr($sortpart, 0, 1) == '$') { if (substr($sortpart, 0, 1) == '$') {
if(!$questionsort) { if (!$questionsort) {
$qid = intval(substr($sortpart, 1)); $qid = intval(substr($sortpart, 1));
$select .= ', grade '; $select .= ', grade ';
$from .= ' LEFT JOIN {question_sessions} qns ON qns.attemptid = qa.id '. $from .= ' LEFT JOIN {question_sessions} qns ON qns.attemptid = qa.id '.
'LEFT JOIN {question_states} qs ON qs.id = qns.newgraded '; 'LEFT JOIN {question_states} qs ON qs.id = qns.newgraded ';
$where .= ' AND ('.sql_isnull('qns.questionid').' OR qns.questionid = '.$qid.')'; $where .= ' AND ('.sql_isnull('qns.questionid').' OR qns.questionid = '.$qid.')';
$newsort[] = 'grade '.(strpos($sortpart, 'ASC')? 'ASC' : 'DESC'); $newsort[] = 'grade '.(strpos($sortpart, 'ASC') ? 'ASC' : 'DESC');
$questionsort = true; $questionsort = true;
} }
} else { } else {
@ -386,13 +411,12 @@ class game_report extends game_default_report {
} }
} }
// Reconstruct the sort string // Reconstruct the sort string.
$sort = ' ORDER BY '.implode(', ', $newsort); $sort = ' ORDER BY '.implode(', ', $newsort);
} }
// Fix some wired sorting // Fix some wired sorting.
if (empty($sort)) { if (empty($sort)) {
//$sort = ' ORDER BY uniqueid';
$sort = ' ORDER BY qa.id'; $sort = ' ORDER BY qa.id';
} }
@ -402,12 +426,13 @@ class game_report extends game_default_report {
// If there is feedback, include it in the query. // If there is feedback, include it in the query.
if ($hasfeedback) { if ($hasfeedback) {
$select .= ', qf.feedbacktext '; $select .= ', qf.feedbacktext ';
$from .= " JOIN {game_feedback} AS qf ON " . $from .= " JOIN {game_feedback} qf ON " .
"qf.gameid = $game->id AND qf.mingrade <= qa.score * $game->grade AND qa.score * $game->grade < qf.maxgrade"; "qf.gameid = $game->id AND qf.mingrade <= qa.score * $game->grade AND qa.score * $game->grade < qf.maxgrade";
} }
// Fetch the attempts // Fetch the attempts.
if (!empty($from)) { // if we're in the site course and displaying no attempts, it makes no sense to do the query. if (!empty($from)) {
// If we're in the site course and displaying no attempts, it makes no sense to do the query.
if (!$download) { if (!$download) {
$attempts = get_records_sql($select.$from.$where.$sort, $attempts = get_records_sql($select.$from.$where.$sort,
$table->get_page_start(), $table->get_page_size()); $table->get_page_start(), $table->get_page_size());
@ -418,64 +443,79 @@ class game_report extends game_default_report {
$attempts = array(); $attempts = array();
} }
// Build table rows.
// Build table rows
if (!$download) { if (!$download) {
$table->initialbars($totalinitials>20); $table->initialbars($totalinitials > 20);
} }
if(!empty($attempts) || !empty($noattempts)) { if (!empty($attempts) || !empty($noattempts)) {
if ($attempts) { if ($attempts) {
foreach ($attempts as $attempt) { foreach ($attempts as $attempt) {
$picture = print_user_picture($attempt->userid, $course->id, $attempt->picture, false, true); $picture = print_user_picture($attempt->userid, $course->id, $attempt->picture, false, true);
/* Uncomment the commented lines below if you are choosing to show unenrolled users and
// uncomment the commented lines below if you are choosing to show unenrolled users and * have uncommented the corresponding lines earlier in this script
// have uncommented the corresponding lines earlier in this script * if (in_array($attempt->userid, $unenrolledusers)) {
//if (in_array($attempt->userid, $unenrolledusers)) { * $userlink = '<a class="dimmed" href="'.$CFG->wwwroot.
// $userlink = '<a class="dimmed" href="'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>'; * '/user/view.php?id='.$attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>';
//} *}
//else { *else {
$userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>'; * $userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.
//} * $attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>';
*}
*/
if (!$download) { if (!$download) {
$row = array( $row = array(
'<input type="checkbox" name="attemptid[]" value="'.$attempt->attempt.'" />', '<input type="checkbox" name="attemptid[]" value="'.$attempt->attempt.'" />',
$picture, $picture,
$userlink, $userlink,
empty($attempt->attempt) ? '-' : '<a href="review.php?q='.$game->id.'&amp;attempt='.$attempt->attempt.'">'.userdate($attempt->timestart, $strtimeformat).'</a>', empty($attempt->attempt) ? '-' : '<a href="review.php?q='.
empty($attempt->timefinish) ? '-' : '<a href="review.php?q='.$game->id.'&amp;attempt='.$attempt->attempt.'">'.userdate($attempt->timefinish, $strtimeformat).'</a>', $game->id.'&amp;attempt='.$attempt->attempt.'">'.
empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time($attempt->duration)) userdate($attempt->timestart, $strtimeformat).'</a>',
empty($attempt->timefinish) ? '-' : '<a href="review.php?q='.
$game->id.'&amp;attempt='.$attempt->attempt.'">'.
userdate($attempt->timefinish, $strtimeformat).'</a>',
empty($attempt->attempt) ? '-' : (
empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time(
$attempt->duration))
); );
} else { } else {
$row = array(fullname($attempt), $row = array(fullname($attempt),
empty($attempt->attempt) ? '-' : userdate($attempt->timestart, $strtimeformat), empty($attempt->attempt) ? '-' : userdate($attempt->timestart, $strtimeformat),
empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish, $strtimeformat), empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish, $strtimeformat),
empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time($attempt->duration)) empty($attempt->attempt) ? '-' : (
empty($attempt->timefinish) ? get_string(
'unfinished', 'game') : format_time($attempt->duration))
); );
} }
if ($game->grade) { if ($game->grade) {
if (!$download) { if (!$download) {
$row[] = $attempt->score === NULL ? '-' : '<a href="review.php?q='.$game->id.'&amp;attempt='.$attempt->attempt.'">'.round($attempt->score * $game->grade,$game->decimalpoints).'</a>'; $row[] = $attempt->score === null ? '-' : '<a href="review.php?q='.
$game->id.'&amp;attempt='.$attempt->attempt.'">'.
round($attempt->score * $game->grade, $game->decimalpoints).'</a>';
} else { } else {
$row[] = $attempt->score === NULL ? '-' : round($attempt->score * $game->grade,$game->decimalpoints); $row[] = $attempt->score === null ? '-' : round($attempt->score * $game->grade, $game->decimalpoints);
} }
} }
if($detailedmarks) { if ($detailedmarks) {
if(empty($attempt->attempt)) { if (empty($attempt->attempt)) {
foreach($questionids as $questionid) { foreach ($questionids as $questionid) {
$row[] = '-'; $row[] = '-';
} }
} else { } else {
foreach($questionids as $questionid) { foreach ($questionids as $questionid) {
if ($gradedstateid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid)) { if ($gradedstateid = get_field('question_sessions', 'newgraded',
$grade = round(get_field('question_states', 'grade', 'id', $gradedstateid), $game->decimalpoints); 'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid)) {
$grade = round(get_field('question_states', 'grade', 'id',
$gradedstateid), $game->decimalpoints);
} else { } else {
$grade = '--'; $grade = '--';
} }
if (!$download) { if (!$download) {
$row[] = link_to_popup_window ('/mod/game/reviewquestion.php?state='.$gradedstateid.'&amp;number='.$questions[$questionid]->number, 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true); $row[] = link_to_popup_window (
'/mod/game/reviewquestion.php?state='.
$gradedstateid.'&amp;number='.
$questions[$questionid]->number, 'reviewquestion', $grade,
450, 650, $strreviewquestion, 'none', true);
} else { } else {
$row[] = $grade; $row[] = $grade;
} }
@ -493,43 +533,50 @@ class game_report extends game_default_report {
$table->add_data($row); $table->add_data($row);
} else if ($download == 'Excel' or $download == 'ODS') { } else if ($download == 'Excel' or $download == 'ODS') {
$colnum = 0; $colnum = 0;
foreach($row as $item){ foreach ($row as $item) {
$myxls->write($rownum,$colnum,$item,$format); $myxls->write($rownum, $colnum, $item, $format);
$colnum++; $colnum++;
} }
$rownum++; $rownum++;
} else if ($download=='CSV') { } else if ($download == 'CSV') {
$text = implode("\t", $row); $text = implode("\t", $row);
echo $text." \n"; echo $text." \n";
} }
} }
} }
if (!$download) { if (!$download) {
// Start form // Start form.
echo '<div id="tablecontainer">'; echo '<div id="tablecontainer">';
echo '<form id="attemptsform" method="post" action="report.php" onsubmit="var menu = document.getElementById(\'menuaction\'); return (menu.options[menu.selectedIndex].value == \'delete\' ? confirm(\''.$strreallydel.'\') : true);">'; echo '<form id="attemptsform" method="post" action="report.php" '.
'onsubmit="var menu = document.getElementById(\'menuaction\'); '.
'return (menu.options[menu.selectedIndex].value == \'delete\' ? confirm(\''.$strreallydel.'\') : true);">';
echo '<div>'; echo '<div>';
echo '<input type="hidden" name="id" value="'.$cm->id.'" />'; echo '<input type="hidden" name="id" value="'.$cm->id.'" />';
echo '<input type="hidden" name="mode" value="overview" />'; echo '<input type="hidden" name="mode" value="overview" />';
// Print table // Print table.
$table->print_html(); $table->print_html();
// Print "Select all" etc. // Print "Select all" etc..
if (!empty($attempts)) { if (!empty($attempts)) {
echo '<table id="commands">'; echo '<table id="commands">';
echo '<tr><td>'; echo '<tr><td>';
echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectall', 'game').'</a> / '; echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.
echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectnone', 'game').'</a> '; get_string('selectall', 'game').'</a> / ';
echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.
get_string('selectnone', 'game').'</a> ';
echo '&nbsp;&nbsp;'; echo '&nbsp;&nbsp;';
$options = array('delete' => get_string('delete')); $options = array('delete' => get_string('delete'));
echo choose_from_menu($options, 'action', '', get_string('withselected', 'game'), 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true); echo choose_from_menu($options, 'action', '', get_string('withselected', 'game'),
'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true);
echo '<noscript id="noscriptmenuaction" style="display: inline;"><div>'; echo '<noscript id="noscriptmenuaction" style="display: inline;"><div>';
echo '<input type="submit" value="'.get_string('go').'" /></div></noscript>'; echo '<input type="submit" value="'.get_string('go').'" /></div></noscript>';
echo '<script type="text/javascript">'."\n<!--\n".'document.getElementById("noscriptmenuaction").style.display = "none";'."\n-->\n".'</script>'; echo '<script type="text/javascript">'."\n<!--\n".
'document.getElementById("noscriptmenuaction").style.display = "none";'
."\n-->\n".'</script>';
echo '</td></tr></table>'; echo '</td></tr></table>';
} }
// Close form // Close form.
echo '</div>'; echo '</div>';
echo '</form></div>'; echo '</form></div>';
@ -545,7 +592,7 @@ class game_report extends game_default_report {
$options['detailedmarks'] = $detailedmarks; $options['detailedmarks'] = $detailedmarks;
echo '<td>'; echo '<td>';
$options["download"] = "ODS"; $options["download"] = "ODS";
print_single_button("report.php", $options, get_string("downloadods", 'game')); ///check bdaloukas print_single_button("report.php", $options, get_string("downloadods", 'game'));
echo "</td>\n"; echo "</td>\n";
echo '<td>'; echo '<td>';
$options["download"] = "Excel"; $options["download"] = "Excel";
@ -572,7 +619,7 @@ class game_report extends game_default_report {
$table->print_html(); $table->print_html();
} }
} }
// Print display options // Print display options.
echo '<div class="controls">'; echo '<div class="controls">';
echo '<form id="options" action="report.php" method="get">'; echo '<form id="options" action="report.php" method="get">';
echo '<div>'; echo '<div>';
@ -589,16 +636,19 @@ class game_report extends game_default_report {
echo '</tr>'; echo '</tr>';
echo '<tr align="left">'; echo '<tr align="left">';
echo '<td colspan="2">'; echo '<td colspan="2">';
$options = array(0 => get_string('attemptsonly','game', $course->students)); $options = array(0 => get_string('attemptsonly', 'game', $course->students));
if ($course->id != SITEID) { if ($course->id != SITEID) {
$options[1] = get_string('noattemptsonly', 'game', $course->students); $options[1] = get_string('noattemptsonly', 'game', $course->students);
$options[2] = get_string('allstudents','game', $course->students); $options[2] = get_string('allstudents', 'game', $course->students);
$options[3] = get_string('allattempts','game'); $options[3] = get_string('allattempts', 'game');
} }
choose_from_menu($options,'noattempts',$noattempts,''); choose_from_menu($options, 'noattempts', $noattempts, '');
echo '</td></tr>'; echo '</td></tr>';
echo '<tr align="left">'; echo '<tr align="left">';
echo '<td colspan="2"><input type="checkbox" id="checkdetailedmarks" name="detailedmarks" '.($detailedmarks?'checked="checked" ':'').'value="1" /> <label for="checkdetailedmarks">'.get_string('showdetailedmarks', 'game').'</label> '; echo '<td colspan="2"><input type="checkbox" id="checkdetailedmarks" name="detailedmarks" '.
($detailedmarks ? 'checked="checked" ' : '').
'value="1" /> <label for="checkdetailedmarks">'.
get_string('showdetailedmarks', 'game').'</label> ';
echo '</td></tr>'; echo '</td></tr>';
echo '<tr><td colspan="2" align="center">'; echo '<tr><td colspan="2" align="center">';
echo '<input type="submit" value="'.get_string('go').'" />'; echo '<input type="submit" value="'.get_string('go').'" />';
@ -611,5 +661,3 @@ class game_report extends game_default_report {
return true; return true;
} }
} }
?>

310
snakes/createboard.php

@ -1,26 +1,30 @@
<?php // $Id: createboard.php,v 1.5 2012/07/25 11:16:07 bdaloukas Exp $ <?php
// This file creates a board for "Snakes and Ladders" // This file is part of Moodle - http://moodle.org/
/* //
require( "../../../config.php"); // Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
$im=game_createsnakesboard( $_GET[ 'file'], $_GET[ 'colsx'], $_GET[ 'colsy'], $_GET[ 'ofstop'], $_GET[ 'ofsbottom'], $_GET[ 'ofsright'], $_GET[ 'ofsleft'], $_GET[ 'aboard']); // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
header('Content-type: image/jpg'); //
imagejpeg($im); // Moodle is distributed in the hope that it will be useful,
imagedestroy($im); // but WITHOUT ANY WARRANTY; without even the implied warranty of
*/ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
function game_createsnakesboard($imageasstring, $colsx, $colsy, $ofstop, $ofsbottom, $ofsright, $ofsleft, $board, $setwidth, $setheight) //
{ // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This file creates a board for "Snakes and Ladders".
function game_createsnakesboard($imageasstring, $colsx, $colsy, $ofstop, $ofsbottom,
$ofsright, $ofsleft, $board, $setwidth, $setheight) {
global $CFG; global $CFG;
$dir = $CFG->dirroot.'/mod/game/snakes/1'; $dir = $CFG->dirroot.'/mod/game/snakes/1';
$im = imagecreatefromstring($imageasstring); $im = imagecreatefromstring($imageasstring);
//check if need resize // Check if need resize.
if( $setwidth >0 or $setheight > 0) if ( $setwidth > 0 or $setheight > 0) {
{
$source = $im; $source = $im;
$width = imagesx($source); $width = imagesx($source);
$height = imagesy($source); $height = imagesy($source);
@ -39,36 +43,31 @@ function game_createsnakesboard($imageasstring, $colsx, $colsy, $ofstop, $ofsbot
$cy = imagesy($im) - $ofstop - $ofsbottom; $cy = imagesy($im) - $ofstop - $ofsbottom;
$color = 0xFF0000; $color = 0xFF0000;
for( $i=0; $i <= $colsx; $i++) for ($i = 0; $i <= $colsx; $i++) {
{ imageline( $im, $ofsleft + $i * $cx / $colsx, $ofstop, $ofsleft + $i * $cx / $colsx, $cy + $ofstop, $color);
imageline( $im, $ofsleft+$i * $cx / $colsx, $ofstop, $ofsleft+$i * $cx / $colsx, $cy+$ofstop, $color);
} }
for( $i=0; $i <= $colsy; $i++) for ($i = 0; $i <= $colsy; $i++) {
{ imageline( $im, $ofsleft, $ofstop + $i * $cy / $colsy, $cx + $ofsleft, $ofstop + $i * $cy / $colsy, $color);
imageline( $im, $ofsleft, $ofstop+$i * $cy / $colsy, $cx+$ofsleft, $ofstop+$i * $cy / $colsy, $color);
} }
$filenamenumbers=$dir.'/numbers.png'; $filenamenumbers = $dir.'/numbers.png';
$img_numbers = imageCreateFrompng( $filenamenumbers); $imgnumbers = imagecreatefrompng( $filenamenumbers);
$size_numbers = getimagesize ($filenamenumbers); $sizenumbers = getimagesize ($filenamenumbers);
for( $iy=0; $iy < $colsy; $iy++) for ($iy = 0; $iy < $colsy; $iy++) {
{ if ($iy % 2 == 0) {
if( $iy % 2 == 0){ $inc = false;
$inc=false; $num = ($colsy - $iy) * $colsy;
$num = ($colsy-$iy)*$colsy; } else {
}else $inc = true;
{ $num = ($colsy - $iy) * $colsy - ($colsy - 1);
$inc=true;
$num = ($colsy-$iy)*$colsy-($colsy-1);
} }
$ypos = $iy * $cy / $colsy+$ofstop; $ypos = $iy * $cy / $colsy + $ofstop;
for( $ix=0; $ix < $colsx; $ix++) for ($ix = 0; $ix < $colsx; $ix++) {
{
$xpos = $ix * $cx / $colsx + $ofsleft; $xpos = $ix * $cx / $colsx + $ofsleft;
shownumber( $im, $img_numbers, $num, $xpos, $ypos, $cx/4, $cy/4, $size_numbers); shownumber( $im, $imgnumbers, $num, $xpos, $ypos, $cx / 4, $cy / 4, $sizenumbers);
$num = ($inc ? $num+1 : $num-1); $num = ($inc ? $num + 1 : $num - 1);
} }
} }
@ -77,36 +76,33 @@ function game_createsnakesboard($imageasstring, $colsx, $colsy, $ofstop, $ofsbot
return $im; return $im;
} }
function computexy( $pos, &$x, &$y, $colsx, $colsy) function computexy( $pos, &$x, &$y, $colsx, $colsy) {
{
$x = ($pos - 1) % $colsx; $x = ($pos - 1) % $colsx;
$y = ($colsy-1) - floor( ($pos - 1) / $colsy); $y = ($colsy - 1) - floor( ($pos - 1) / $colsy);
if($y % 2 == 0) if ($y % 2 == 0) {
$x = ($colsx-1) - $x; $x = ($colsx - 1) - $x;
}
} }
function makeboard( $im, $dir, $cx, $cy, $board, $colsx, $colsy, $ofsleft, $ofstop) function makeboard( $im, $dir, $cx, $cy, $board, $colsx, $colsy, $ofsleft, $ofstop) {
{
$a = explode( ',', $board); $a = explode( ',', $board);
foreach( $a as $s) foreach ($a as $s) {
{ if (substr( $s, 0, 1) == 'L') {
if( substr( $s,0,1) == 'L')
makeboardL( $im, $dir, $cx, $cy, substr( $s, 1), $colsx, $colsy, $ofsleft, $ofstop); makeboardL( $im, $dir, $cx, $cy, substr( $s, 1), $colsx, $colsy, $ofsleft, $ofstop);
else } else {
makeboardS( $im, $dir, $cx, $cy, substr( $s, 1), $colsx, $colsy, $ofsleft, $ofstop); makeboardS( $im, $dir, $cx, $cy, substr( $s, 1), $colsx, $colsy, $ofsleft, $ofstop);
} }
}
} }
function makeboardL( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop) function makeboardl( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop) {
{
$pos = strpos( $s, '-'); $pos = strpos( $s, '-');
$from = substr( $s, 0, $pos); $from = substr( $s, 0, $pos);
$to = substr( $s, $pos+1); $to = substr( $s, $pos + 1);
computexy( $from, $startx, $starty, $colsx, $colsy); computexy( $from, $startx, $starty, $colsx, $colsy);
computexy( $to, $x2, $y2, $colsx, $colsy); computexy( $to, $x2, $y2, $colsx, $colsy);
if( ($x2 < $startx) and ($y2 < $starty)) if (($x2 < $startx) and ($y2 < $starty)) {
{
$temp = $x2; $x2 = $startx; $startx = $temp; $temp = $x2; $x2 = $startx; $startx = $temp;
$temp = $y2; $y2 = $starty; $starty = $temp; $temp = $y2; $y2 = $starty; $starty = $temp;
} }
@ -115,201 +111,193 @@ function makeboardL( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop)
$letter = ( $movex * $movey < 0 ? 'b' : 'a'); $letter = ( $movex * $movey < 0 ? 'b' : 'a');
$_startx = $startx; $_movex=$movex; $_starty = $starty; $_movey=$movey; $oldstartx = $startx; $oldmovex = $movex; $oldstarty = $starty; $oldmovey = $movey;
if( $movex < 0) if ($movex < 0) {
{
$startx += $movex; $startx += $movex;
$movex = -$movex; $movex = -$movex;
} }
if( $movey < 0) if ($movey < 0) {
{
$starty += $movey; $starty += $movey;
$movey = -$movey; $movey = -$movey;
} }
$stamp = 0; $stamp = 0;
if( $letter == 'b'){ if ($letter == 'b') {
$file = $dir.'/l'.$letter.$movey.$movex.'.png'; $file = $dir.'/l'.$letter.$movey.$movex.'.png';
if( file_exists( $file)){ if (file_exists( $file)) {
$stamp = game_imagecreatefrompng( $file); $stamp = game_imagecreatefrompng( $file);
}else } else {
{
$file = $dir.'/la'.$movey.$movex.'.png'; $file = $dir.'/la'.$movey.$movex.'.png';
$source = game_imagecreatefrompng( $file); $source = game_imagecreatefrompng( $file);
if( $source != 0) if ( $source != 0) {
$stamp = imagerotate($source, 90, 0); $stamp = imagerotate($source, 90, 0);
} }
}else }
{ } else {
$file = $dir.'/la'.$movex.$movey.'.png'; $file = $dir.'/la'.$movex.$movey.'.png';
$stamp = game_imagecreatefrompng( $file); $stamp = game_imagecreatefrompng( $file);
} }
$dst_x = $startx*$cx/$colsx; $dstx = $startx * $cx / $colsx;
$dst_y = $starty*$cy/$colsy; $dsty = $starty * $cy / $colsy;
$dst_w = ($movex+1) * $cx / $colsx; $dstw = ($movex + 1) * $cx / $colsx;
$dst_h = ($movey+1) * $cy / $colsy; $dsth = ($movey + 1) * $cy / $colsy;
if( $stamp == 0) if ($stamp == 0) {
{ game_printladder( $im, $file, $dstx + $ofsleft, $dsty + $ofstop, $dstw, $dsth, $cx / $colsx, $cy / $colsy);
game_printladder( $im, $file, $dst_x+$ofsleft, $dst_y+$ofstop, $dst_w, $dst_h, $cx/$colsx, $cy/$colsy); } else {
}else imagecopyresampled( $im, $stamp, $ofsleft + $dstx, $ofstop + $dsty, 0, 0, $dstw, $dsth,
{ 100 * $movex + 100, 100 * $movey + 100);
imagecopyresampled( $im, $stamp, $ofsleft+$dst_x, $ofstop+$dst_y, 0, 0, $dst_w, $dst_h, 100*$movex+100, 100*$movey+100);
} }
} }
function makeboardS( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop) function makeboards( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop) {
{
$pos = strpos( $s, '-'); $pos = strpos( $s, '-');
$from = substr( $s, 0, $pos); $from = substr( $s, 0, $pos);
$to = substr( $s, $pos+1); $to = substr( $s, $pos + 1);
computexy( $from, $startx, $starty, $colsx, $colsy); computexy( $from, $startx, $starty, $colsx, $colsy);
computexy( $to, $x2, $y2, $colsx, $colsy); computexy( $to, $x2, $y2, $colsx, $colsy);
$swap=0; $swap = 0;
if( ($x2 < $startx) and ($y2 < $starty)) if (($x2 < $startx) and ($y2 < $starty)) {
{
$temp = $x2; $x2 = $startx; $startx = $temp; $temp = $x2; $x2 = $startx; $startx = $temp;
$temp = $y2; $y2 = $starty; $starty = $temp; $temp = $y2; $y2 = $starty; $starty = $temp;
$swap=1; $swap = 1;
} }
$movex = $x2 - $startx; $movex = $x2 - $startx;
$movey = $y2 - $starty; $movey = $y2 - $starty;
//a*d /* a*d
//*** *
//b*c * b*c
*/
$stamp = $rotate = 0; $stamp = $rotate = 0;
if( $movex >= 0 and $movey < 0){ if ($movex >= 0 and $movey < 0) {
$letter = 'b'; $letter = 'b';
$file = $dir.'/sa'.$movey.$movex.'.png'; $file = $dir.'/sa'.$movey.$movex.'.png';
$source = game_imagecreatefrompng( $file); $source = game_imagecreatefrompng( $file);
if( $source != 0) if ($source != 0) {
{
$stamp = imagerotate($source, 270, 0); $stamp = imagerotate($source, 270, 0);
$starty += $movey; $movey = -$movey; $starty += $movey; $movey = -$movey;
}else } else {
$rotate = 270; $rotate = 270;
}else if( $movex < 0 and $movey < 0){ }
} else if ($movex < 0 and $movey < 0) {
$letter = 'c'; $letter = 'c';
$file = $dir.'/sa'.$movey.$movex.'.png'; $file = $dir.'/sa'.$movey.$movex.'.png';
$source = game_imagecreatefrompng( $file); $source = game_imagecreatefrompng( $file);
if( $source != 0) if ($source != 0) {
{
$stamp = imagerotate($source, 180, 0); $stamp = imagerotate($source, 180, 0);
$startx += $movex; $movex = -$movex; $startx += $movex; $movex = -$movex;
$starty += $movey; $movey = -$movey; $starty += $movey; $movey = -$movey;
}else } else {
$rotate = 180; $rotate = 180;
}else if( ($movex < 0) and ($movey >= 0)){ }
} else if (($movex < 0) and ($movey >= 0)) {
$letter = 'd'; $letter = 'd';
$file = $dir.'/sa'.$movey.$movex.'.png'; $file = $dir.'/sa'.$movey.$movex.'.png';
$source = game_imagecreatefrompng( $file); $source = game_imagecreatefrompng( $file);
if( $source != 0) if ($source != 0) {
{
$stamp = imagerotate($source, 270, 0); $stamp = imagerotate($source, 270, 0);
$startx += $movex; $movex = -$movex; $startx += $movex; $movex = -$movex;
}else } else {
$rotate=270; $rotate = 270;
}else }
{ } else {
$file = $dir.'/sa'.$movex.$movey.'.png'; $file = $dir.'/sa'.$movex.$movey.'.png';
$stamp = game_imagecreatefrompng( $file); $stamp = game_imagecreatefrompng( $file);
} }
if( ($swap != 0) and ($stamp == 0)) if (($swap != 0) and ($stamp == 0)) {
{
$temp = $x2; $x2 = $startx; $startx = $temp; $temp = $x2; $x2 = $startx; $startx = $temp;
$temp = $y2; $y2 = $starty; $starty = $temp; $temp = $y2; $y2 = $starty; $starty = $temp;
$movex = $x2 - $startx; $movex = $x2 - $startx;
$movey = $y2 - $starty; $movey = $y2 - $starty;
} }
$dst_x = $startx*$cx/$colsx; $dstx = $startx * $cx / $colsx;
$dst_y = $starty*$cy/$colsy; $dsty = $starty * $cy / $colsy;
$dst_w = ($movex+1) * $cx / $colsx; $dstw = ($movex + 1) * $cx / $colsx;
$dst_h = ($movey+1) * $cy / $colsy; $dsth = ($movey + 1) * $cy / $colsy;
if( $stamp == 0) if ($stamp == 0) {
{ game_printsnake( $im, $file, $dstx + $ofsleft, $dsty + $ofstop, $dstw, $dsth, $cx / $colsx, $cy / $colsy);
game_printsnake( $im, $file, $dst_x+$ofsleft, $dst_y+$ofstop, $dst_w, $dst_h, $cx/$colsx, $cy/$colsy); } else {
}else imagecopyresampled( $im, $stamp, $dstx + $ofsleft, $dsty + $ofstop, 0, 0, $dstw, $dsth,
imagecopyresampled( $im, $stamp, $dst_x+$ofsleft, $dst_y+$ofstop, 0, 0, $dst_w, $dst_h, 100*$movex+100, 100*$movey+100); 100 * $movex + 100, 100 * $movey + 100);
}
} }
function game_imagecreatefrompng( $file){ function game_imagecreatefrompng( $file) {
if( file_exists( $file)) if (file_exists( $file)) {
return imagecreatefrompng( $file); return imagecreatefrompng( $file);
}
return 0; return 0;
} }
function shownumber( $img_handle, $img_numbers, $number, $x1 , $y1, $width, $height, $size_numbers){ function shownumber( $imghandle, $imgnumbers, $number, $x1 , $y1, $width, $height, $sizenumbers) {
if( $number < 10){ if ($number < 10) {
$width_number = $size_numbers[ 0] / 10; $widthnumber = $sizenumbers[ 0] / 10;
$dstX = $x1 + $width / 10; $dstx = $x1 + $width / 10;
$dstY = $y1 + $height / 10; $dsty = $y1 + $height / 10;
$srcX = $number * $size_numbers[ 0] / 10; $srcx = $number * $sizenumbers[ 0] / 10;
$srcW = $size_numbers[ 0]/10; $srcw = $sizenumbers[ 0] / 10;
$srcH = $size_numbers[ 1]; $srch = $sizenumbers[ 1];
$dstW = $width / 10; $dstw = $width / 10;
$dstH = $dstW * $srcH / $srcW; $dsth = $dstw * $srch / $srcw;
imagecopyresampled( $img_handle, $img_numbers, $dstX, $dstY, $srcX, 0, $dstW, $dstH, $srcW, $srcH); imagecopyresampled( $imghandle, $imgnumbers, $dstx, $dsty, $srcx, 0, $dstw, $dsth, $srcw, $srch);
}else } else {
{
$number1 = floor( $number / 10); $number1 = floor( $number / 10);
$number2 = $number % 10; $number2 = $number % 10;
shownumber( $img_handle, $img_numbers, $number1, $x1-$width/20, $y1, $width, $height, $size_numbers); shownumber( $imghandle, $imgnumbers, $number1, $x1 - $width / 20, $y1, $width, $height, $sizenumbers);
shownumber( $img_handle, $img_numbers, $number2, $x1+$width/20, $y1, $width, $height, $size_numbers); shownumber( $imghandle, $imgnumbers, $number2, $x1 + $width / 20, $y1, $width, $height, $sizenumbers);
} }
} }
function returnRotatedPoint($x,$y,$cx,$cy,$a) function returnrotatedpoint($x, $y, $cx, $cy, $a) {
{ // Radius using distance formula.
// radius using distance formula $r = sqrt(pow(($x - $cx), 2) + pow(($y - $cy), 2));
$r = sqrt(pow(($x-$cx),2)+pow(($y-$cy),2));
// initial angle in relation to center
$iA = rad2deg(atan2(($y-$cy),($x-$cx)));
$nx = $r * cos(deg2rad($a + $iA)); // Initial angle in relation to center.
$ny = $r * sin(deg2rad($a + $iA)); $ia = rad2deg(atan2(($y - $cy), ($x - $cx)));
return array("x"=>$cx+$nx,"y"=>$cy+$ny); $nx = $r * cos(deg2rad($a + $ia));
} $ny = $r * sin(deg2rad($a + $ia));
return array("x" => $cx + $nx, "y" => $cy + $ny);
}
function game_printladder( $im, $file, $x, $y, $width, $height, $cellx, $celly) function game_printladder( $im, $file, $x, $y, $width, $height, $cellx, $celly) {
{
$color = imagecolorallocate($im, 0, 0, 255); $color = imagecolorallocate($im, 0, 0, 255);
$x2 = $x+$width-$cellx/2; $x2 = $x + $width - $cellx / 2;
$y2 = $y+$height-$celly/2; $y2 = $y + $height - $celly / 2;
$x1 = $x+$cellx/2; $x1 = $x + $cellx / 2;
$y1 = $y+$celly/2; $y1 = $y + $celly / 2;
imageline( $im, $x1, $y1, $x2, $y2, $color); imageline( $im, $x1, $y1, $x2, $y2, $color);
$r = sqrt(pow(($x2-$x1),2)+pow(($y2-$y1),2)); $r = sqrt(pow(($x2 - $x1), 2) + pow(($y2 - $y1), 2));
$mul = 100 / $r; $mul = 100 / $r;
$x1 = $x2 - ($x2-$x1) * $mul; $x1 = $x2 - ($x2 - $x1) * $mul;
$y1 = $y2 - ($y2-$y1) * $mul; $y1 = $y2 - ($y2 - $y1) * $mul;
$a = returnRotatedPoint( $x1, $y1, $x2, $y2, 20); $a = returnRotatedPoint( $x1, $y1, $x2, $y2, 20);
imageline( $im, $x2, $y2, $a[ 'x'], $a[ 'y'], $color); imageline( $im, $x2, $y2, $a[ 'x'], $a[ 'y'], $color);
$a = returnRotatedPoint( $x1, $y1, $x2, $y2, -20); $a = returnRotatedPoint( $x1, $y1, $x2, $y2, -20);
imageline( $im, $x2, $y2, $a[ 'x'], $a[ 'y'], $color); imageline( $im, $x2, $y2, $a[ 'x'], $a[ 'y'], $color);
} }
function game_printsnake( $im, $file, $x, $y, $width, $height, $cellx, $celly) function game_printsnake( $im, $file, $x, $y, $width, $height, $cellx, $celly) {
{
$color = imagecolorallocate($im, 0, 255, 0); $color = imagecolorallocate($im, 0, 255, 0);
$x2 = $x+$width-$cellx/2; $x2 = $x + $width - $cellx / 2;
$y2 = $y+$height-$celly/2; $y2 = $y + $height - $celly / 2;
$x1 = $x+$cellx/2; $x1 = $x + $cellx / 2;
$y1 = $y+$celly/2; $y1 = $y + $celly / 2;
imageline( $im, $x1, $y1, $x2, $y2, $color); imageline( $im, $x1, $y1, $x2, $y2, $color);
$r = sqrt(pow(($x2-$x1),2)+pow(($y2-$y1),2)); $r = sqrt(pow(($x2 - $x1), 2) + pow(($y2 - $y1), 2));
$mul = 100 / $r; $mul = 100 / $r;
$x2 = $x1 + ($x2-$x1) * $mul; $x2 = $x1 + ($x2 - $x1) * $mul;
$y2 = $y1 + ($y2-$y1) * $mul; $y2 = $y1 + ($y2 - $y1) * $mul;
$a = returnRotatedPoint( $x1, $y1, $x2, $y2, 80); $a = returnRotatedPoint( $x1, $y1, $x2, $y2, 80);
imageline( $im, $x1, $y1, $a[ 'x'], $a[ 'y'], $color); imageline( $im, $x1, $y1, $a[ 'x'], $a[ 'y'], $color);
$a = returnRotatedPoint( $x1, $y1, $x2, $y2, -80); $a = returnRotatedPoint( $x1, $y1, $x2, $y2, -80);

239
snakes/play.php

@ -1,26 +1,40 @@
<?php // $Id: play.php,v 1.26 2012/07/26 05:39:00 bdaloukas Exp $ <?php
// This file is part of Moodle - http://moodle.org/
// This files plays the game "Snakes and Ladders" //
// Moodle is free software: you can redistribute it and/or modify
function game_snakes_continue( $id, $game, $attempt, $snakes, $context) // it under the terms of the GNU General Public License as published by
{ // the Free Software Foundation, either version 3 of the License, or
if( $attempt != false and $snakes != false){ // (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This files plays the game "Snakes and Ladders".
function game_snakes_continue( $id, $game, $attempt, $snakes, $context) {
if ($attempt != false and $snakes != false) {
return game_snakes_play( $id, $game, $attempt, $snakes, $context); return game_snakes_play( $id, $game, $attempt, $snakes, $context);
} }
if( $attempt === false){ if ($attempt === false) {
$attempt = game_addattempt( $game); $attempt = game_addattempt( $game);
} }
$newrec = new stdClass(); $newrec = new stdClass();
$newrec->id = $attempt->id; $newrec->id = $attempt->id;
$newrec->snakesdatabaseid = $game->param3; $newrec->snakesdatabaseid = $game->param3;
if( $newrec->snakesdatabaseid == 0) if ($newrec->snakesdatabaseid == 0) {
$newrec->snakesdatabaseid = 1; $newrec->snakesdatabaseid = 1;
}
$newrec->position = 1; $newrec->position = 1;
$newrec->queryid = 0; $newrec->queryid = 0;
$newrec->dice = rand( 1, 6); $newrec->dice = rand( 1, 6);
if( !game_insert_record( 'game_snakes', $newrec)){ if (!game_insert_record( 'game_snakes', $newrec)) {
print_error( 'game_snakes_continue: error inserting in game_snakes'); print_error( 'game_snakes_continue: error inserting in game_snakes');
} }
@ -29,14 +43,13 @@ function game_snakes_continue( $id, $game, $attempt, $snakes, $context)
return game_snakes_play( $id, $game, $attempt, $newrec, $context); return game_snakes_play( $id, $game, $attempt, $newrec, $context);
} }
function game_snakes_play( $id, $game, $attempt, $snakes, $context) function game_snakes_play( $id, $game, $attempt, $snakes, $context) {
{
global $CFG, $DB, $OUTPUT; global $CFG, $DB, $OUTPUT;
$board = game_snakes_get_board( $game); $board = game_snakes_get_board( $game);
$showboard = false; $showboard = false;
if( $snakes->position > $board->cols * $board->rows && $snakes->queryid <> 0){ if ($snakes->position > $board->cols * $board->rows && $snakes->queryid <> 0) {
$finish = true; $finish = true;
if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) { if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) {
@ -45,30 +58,29 @@ function game_snakes_play( $id, $game, $attempt, $snakes, $context)
echo '<B>'.get_string( 'win', 'game').'</B><BR>'; echo '<B>'.get_string( 'win', 'game').'</B><BR>';
echo '<br>'; echo '<br>';
echo "<a href=\"$CFG->wwwroot/mod/game/attempt.php?id=$id\">".get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; '; echo "<a href=\"$CFG->wwwroot/mod/game/attempt.php?id=$id\">".
get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
echo "<a href=\"$CFG->wwwroot/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> '; echo "<a href=\"$CFG->wwwroot/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> ';
$gradeattempt = 1; $gradeattempt = 1;
$finish = 1; $finish = 1;
game_updateattempts( $game, $attempt, $gradeattempt, $finish); game_updateattempts( $game, $attempt, $gradeattempt, $finish);
}else } else {
{
$finish = false; $finish = false;
if( $snakes->queryid == 0){ if ($snakes->queryid == 0) {
game_snakes_computenextquestion( $game, $snakes, $query); game_snakes_computenextquestion( $game, $snakes, $query);
}else } else {
{
$query = $DB->get_record( 'game_queries', array( 'id' => $snakes->queryid)); $query = $DB->get_record( 'game_queries', array( 'id' => $snakes->queryid));
} }
if( $game->toptext != ''){ if ($game->toptext != '') {
echo $game->toptext.'<br>'; echo $game->toptext.'<br>';
} }
$showboard = true; $showboard = true;
} }
if( $showboard and $game->param8 == 0) if ($showboard and $game->param8 == 0) {
game_snakes_showquestion( $id, $game, $snakes, $query, $context); game_snakes_showquestion( $id, $game, $snakes, $query, $context);
}
?> ?>
<script language="javascript" event="onload" for="window"> <script language="javascript" event="onload" for="window">
<!-- <!--
@ -87,48 +99,51 @@ function game_snakes_play( $id, $game, $attempt, $snakes, $context)
<tr> <tr>
<td> <td>
<div id="board" STYLE="position:relative; left:0px;top:0px; width:<?php p($board->width); ?>px; height:<?php p($board->height); ?>px;"> <div id="board" STYLE="position:relative; left:0px;top:0px;
width:<?php p($board->width); ?>px; height:<?php p($board->height); ?>px;">
<img src="<?php echo $board->imagesrc; ?>"></img> <img src="<?php echo $board->imagesrc; ?>"></img>
</div> </div>
<?php <?php
if ($finish == false) {
if( $finish == false){
game_snakes_showdice( $snakes, $board); game_snakes_showdice( $snakes, $board);
} }
?> ?>
</td> </td>
</tr> </tr>
</table> </table>
<?php <?php
if( $game->bottomtext != ''){ if ($game->bottomtext != '') {
echo '<br>'.$game->bottomtext; echo '<br>'.$game->bottomtext;
} }
if( $showboard and $game->param8 != 0) if ($showboard and $game->param8 != 0) {
game_snakes_showquestion( $id, $game, $snakes, $query, $context); game_snakes_showquestion( $id, $game, $snakes, $query, $context);
}
} }
function game_snakes_showdice( $snakes, $board) function game_snakes_showdice( $snakes, $board) {
{
$pos = game_snakes_computeplayerposition( $snakes, $board); $pos = game_snakes_computeplayerposition( $snakes, $board);
?> ?>
<div ID="player1" STYLE="position:relative; left:<?php p( $pos->x);?>px; top:<?php p( $pos->y);?>px;" > <div ID="player1" STYLE="position:relative; left:<?php p( $pos->x);?>px; top:<?php p( $pos->y);?>px;" >
<img src="snakes/1/player1.png" alt="<?php print_string('snakes_player', 'game', ($snakes->position +1)); /*Accessibility. */ ?>" width="<?php echo $pos->width; ?>" height="<?php echo $pos->height; ?>"/> <img src="snakes/1/player1.png"
alt="<?php print_string('snakes_player', 'game', ($snakes->position + 1)); /*Accessibility. */ ?>"
width="<?php echo $pos->width; ?>"
height="<?php echo $pos->height; ?>"/>
</div> </div>
<div ID="dice" STYLE="position:relative; left:<?php p( $board->width + round($board->width/3));?>px;top:<?php p( -2*round($board->height/3));?>px; "> <div ID="dice" STYLE="position:relative;
left:<?php p( $board->width + round($board->width / 3)); ?>px;
top:<?php p( -2 * round($board->height / 3));?>px; ">
<img src="snakes/1/dice<?php p($snakes->dice);?>.png" alt="<?php print_string('snakes_dice', 'game', $snakes->dice) ?>" /> <img src="snakes/1/dice<?php p($snakes->dice);?>.png" alt="<?php print_string('snakes_dice', 'game', $snakes->dice) ?>" />
</div> </div>
<?php <?php
} }
function game_snakes_computeplayerposition( $snakes, $board) function game_snakes_computeplayerposition( $snakes, $board) {
{
$x = ($snakes->position - 1) % $board->cols; $x = ($snakes->position - 1) % $board->cols;
$y = floor( ($snakes->position-1) / $board->cols); $y = floor( ($snakes->position - 1) / $board->cols);
$cellwidth = ($board->width - $board->headerx - $board->footerx) / $board->cols; $cellwidth = ($board->width - $board->headerx - $board->footerx) / $board->cols;
$cellheight = ($board->height - $board->headery - $board->footery) / $board->rows; $cellheight = ($board->height - $board->headery - $board->footery) / $board->rows;
@ -140,13 +155,13 @@ function game_snakes_computeplayerposition( $snakes, $board)
$pos->ofsx = 0; $pos->ofsx = 0;
$pos->ofsy = $pos->height; $pos->ofsy = $pos->height;
switch( $board->direction){ switch( $board->direction) {
case 1: case 1:
if( ($y % 2) == 1){ if (($y % 2) == 1) {
$x = $board->cols - $x - 1; $x = $board->cols - $x - 1;
} }
$pos->x = $board->headerx + $x * $cellwidth + ($cellwidth - $pos->width)/2+ $pos->ofsx; $pos->x = $board->headerx + $x * $cellwidth + ($cellwidth - $pos->width) / 2 + $pos->ofsx;
$pos->y = $board->footery + $y * $cellheight + ($cellheight - $pos->height)/2 + $pos->ofsy; $pos->y = $board->footery + $y * $cellheight + ($cellheight - $pos->height) / 2 + $pos->ofsy;
$pos->x = round( $pos->x); $pos->x = round( $pos->x);
$pos->y = round( -$pos->y); $pos->y = round( -$pos->y);
break; break;
@ -155,45 +170,44 @@ function game_snakes_computeplayerposition( $snakes, $board)
return $pos; return $pos;
} }
function game_snakes_computenextquestion( $game, &$snakes, &$query) function game_snakes_computenextquestion( $game, &$snakes, &$query) {
{
global $DB, $USER; global $DB, $USER;
//Retrieves CONST_GAME_TRIES_REPETITION words and select the one which is used fewer times // Retrieves CONST_GAME_TRIES_REPETITION words and select the one which is used fewer times.
if( ($recs = game_questions_selectrandom( $game, 1, CONST_GAME_TRIES_REPETITION)) == false){ if (($recs = game_questions_selectrandom( $game, 1, CONST_GAME_TRIES_REPETITION)) == false) {
return false; return false;
} }
$glossaryid = 0; $glossaryid = 0;
$questionid = 0; $questionid = 0;
$min_num = 0; $minnum = 0;
$query = new stdClass(); $query = new stdClass();
foreach( $recs as $rec){ foreach ($recs as $rec) {
$a = array( 'gameid' => $game->id, 'userid' => $USER->id, 'questionid' => $rec->questionid, 'glossaryentryid' => $rec->glossaryentryid); $a = array( 'gameid' => $game->id, 'userid' => $USER->id,
if(($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions AS r')) != false){ 'questionid' => $rec->questionid, 'glossaryentryid' => $rec->glossaryentryid);
if( ($rec2->r < $min_num) or ($min_num == 0)){ if (($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions AS r')) != false) {
$min_num = $rec2->r; if (($rec2->r < $minnum) or ($minnum == 0)) {
$minnum = $rec2->r;
$query->glossaryentryid = $rec->glossaryentryid; $query->glossaryentryid = $rec->glossaryentryid;
$query->questionid = $rec->questionid; $query->questionid = $rec->questionid;
} }
} } else {
else{
$query->glossaryentryid = $rec->glossaryentryid; $query->glossaryentryid = $rec->glossaryentryid;
$query->questionid = $rec->questionid; $query->questionid = $rec->questionid;
break; break;
} }
} }
if( ($query->glossaryentryid == 0) AND ($query->questionid == 0)) if (($query->glossaryentryid == 0) and ($query->questionid == 0)) {
return false; return false;
}
$query->attemptid = $snakes->id; $query->attemptid = $snakes->id;
$query->gameid = $game->id; $query->gameid = $game->id;
$query->userid = $USER->id; $query->userid = $USER->id;
$query->sourcemodule = $game->sourcemodule; $query->sourcemodule = $game->sourcemodule;
$query->score = 0; $query->score = 0;
$query->timelastattempt = time(); $query->timelastattempt = time();
if( !($query->id = $DB->insert_record( 'game_queries', $query))){ if (!($query->id = $DB->insert_record( 'game_queries', $query))) {
print_error( "Can't insert to table game_queries"); print_error( "Can't insert to table game_queries");
} }
@ -204,7 +218,7 @@ function game_snakes_computenextquestion( $game, &$snakes, &$query)
$updrec->queryid = $query->id; $updrec->queryid = $query->id;
$updrec->dice = $snakes->dice = rand( 1, 6); $updrec->dice = $snakes->dice = rand( 1, 6);
if( !$DB->update_record( 'game_snakes', $updrec)){ if (!$DB->update_record( 'game_snakes', $updrec)) {
print_error( 'game_questions_selectrandom: error updating in game_snakes'); print_error( 'game_questions_selectrandom: error updating in game_snakes');
} }
@ -213,64 +227,64 @@ function game_snakes_computenextquestion( $game, &$snakes, &$query)
return true; return true;
} }
function game_snakes_showquestion( $id, $game, $snakes, $query, $context) function game_snakes_showquestion( $id, $game, $snakes, $query, $context) {
{ if ($query->sourcemodule == 'glossary') {
if( $query->sourcemodule == 'glossary'){
game_snakes_showquestion_glossary( $id, $snakes, $query, $game); game_snakes_showquestion_glossary( $id, $snakes, $query, $game);
}else } else {
{
game_snakes_showquestion_question( $game, $id, $snakes, $query, $context); game_snakes_showquestion_question( $game, $id, $snakes, $query, $context);
} }
} }
function game_snakes_showquestion_question( $game, $id, $snakes, $query, $context) function game_snakes_showquestion_question( $game, $id, $snakes, $query, $context) {
{
global $CFG; global $CFG;
$questionlist = $query->questionid; $questionlist = $query->questionid;
$questions = game_sudoku_getquestions( $questionlist); $questions = game_sudoku_getquestions( $questionlist);
/// Start the form // Start the form.
echo "<form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; echo "<form id=\"responseform\" method=\"post\" ".
"action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n";
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n";
// Add a hidden field with the quiz id // Add a hidden field with the quiz id.
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n";
echo '<input type="hidden" name="action" value="snakescheck" />'; echo '<input type="hidden" name="action" value="snakescheck" />';
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n";
/// Print all the questions // Print all the questions.
foreach( $questions as $question) foreach ($questions as $question) {
game_print_question( $game, $question, $context); game_print_question( $game, $question, $context);
// Add a hidden field with questionids }
// Add a hidden field with questionids.
echo '<input type="hidden" name="questionids" value="'.$questionlist."\" />\n"; echo '<input type="hidden" name="questionids" value="'.$questionlist."\" />\n";
echo "</form>\n"; echo "</form>\n";
} }
function game_snakes_showquestion_glossary( $id, $snakes, $query, $game) function game_snakes_showquestion_glossary( $id, $snakes, $query, $game) {
{
global $CFG, $DB; global $CFG, $DB;
$entry = $DB->get_record( 'glossary_entries', array('id' => $query->glossaryentryid)); $entry = $DB->get_record( 'glossary_entries', array('id' => $query->glossaryentryid));
/// Start the form // Start the form.
echo "<form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; echo "<form id=\"responseform\" method=\"post\" ".
"action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n";
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n";
// Add a hidden field with the queryid // Add a hidden field with the queryid.
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n";
echo '<input type="hidden" name="action" value="snakescheckg" />'; echo '<input type="hidden" name="action" value="snakescheckg" />';
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n";
/// Print all the questions // Print all the questions.
// Add a hidden field with glossaryentryid // Add a hidden field with glossaryentryid.
echo '<input type="hidden" name="glossaryentryid" value="'.$query->glossaryentryid."\" />\n"; echo '<input type="hidden" name="glossaryentryid" value="'.$query->glossaryentryid."\" />\n";
$cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course);
$contextglossary = game_get_context_module_instance( $cmglossary->id); $contextglossary = game_get_context_module_instance( $cmglossary->id);
$s = game_filterglossary(str_replace( '\"', '"', $entry->definition), $query->glossaryentryid, $contextglossary->id, $game->course); $s = game_filterglossary(str_replace( '\"', '"', $entry->definition), $query->glossaryentryid,
$contextglossary->id, $game->course);
echo $s.'<br>'; echo $s.'<br>';
echo get_string( 'answer').': '; echo get_string( 'answer').': ';
@ -279,14 +293,12 @@ function game_snakes_showquestion_glossary( $id, $snakes, $query, $game)
echo "</form>\n"; echo "</form>\n";
} }
function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context) {
function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context)
{
global $QTYPES, $CFG, $DB; global $QTYPES, $CFG, $DB;
$responses = data_submitted(); $responses = data_submitted();
if( $responses->queryid != $snakes->queryid){ if ($responses->queryid != $snakes->queryid) {
game_snakes_play( $id, $game, $attempt, $snakes, $context); game_snakes_play( $id, $game, $attempt, $snakes, $context);
return; return;
} }
@ -296,35 +308,33 @@ function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context)
$questions = game_sudoku_getquestions( $questionlist); $questions = game_sudoku_getquestions( $questionlist);
$correct = false; $correct = false;
$query = ''; $query = '';
foreach($questions as $question) { foreach ($questions as $question) {
$query = new stdClass(); $query = new stdClass();
$query->id = $snakes->queryid; $query->id = $snakes->queryid;
$grade = game_grade_responses( $question, $responses, 100, $answertext); $grade = game_grade_responses( $question, $responses, 100, $answertext);
if( $grade < 99){ if ($grade < 99) {
//wrong answer // Wrong answer.
game_update_queries( $game, $attempt, $query, 0, $answertext); game_update_queries( $game, $attempt, $query, 0, $answertext);
continue; continue;
} }
//correct answer // Correct answer.
$correct = true; $correct = true;
game_update_queries( $game, $attempt, $query, 1, ''); game_update_queries( $game, $attempt, $query, 1, '');
} }
//set the grade of the whole game // Set the grade of the whole game.
game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context); game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context);
} }
function game_snakes_check_glossary( $id, $game, $attempt, $snakes, $context) {
function game_snakes_check_glossary( $id, $game, $attempt, $snakes, $context)
{
global $QTYPES, $CFG, $DB; global $QTYPES, $CFG, $DB;
$responses = data_submitted(); $responses = data_submitted();
if( $responses->queryid != $snakes->queryid){ if ($responses->queryid != $snakes->queryid) {
game_snakes_play( $id, $game, $attempt, $snakes, $context); game_snakes_play( $id, $game, $attempt, $snakes, $context);
return; return;
} }
@ -336,39 +346,34 @@ function game_snakes_check_glossary( $id, $game, $attempt, $snakes, $context)
$name = 'resp'.$query->glossaryentryid; $name = 'resp'.$query->glossaryentryid;
$useranswer = $responses->answer; $useranswer = $responses->answer;
if( game_upper( $useranswer) != game_upper( $glossaryentry->concept)){ if (game_upper( $useranswer) != game_upper( $glossaryentry->concept)) {
//wrong answer // Wrong answer.
$correct = false; $correct = false;
game_update_queries( $game, $attempt, $query, 0, $useranswer);//last param is grade game_update_queries( $game, $attempt, $query, 0, $useranswer); // Last param is grade.
}else } else {
{ // Correct answer.
//correct answer
$correct = true; $correct = true;
game_update_queries( $game, $attempt, $query, 1, $useranswer);//last param is grade game_update_queries( $game, $attempt, $query, 1, $useranswer); // Last param is grade.
} }
//set the grade of the whole game // Set the grade of the whole game.
game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context); game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context);
} }
function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context) {
function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context)
{
global $DB; global $DB;
$data = $DB->get_field( 'game_snakes_database', 'data', array( 'id' => $snakes->snakesdatabaseid)); $data = $DB->get_field( 'game_snakes_database', 'data', array( 'id' => $snakes->snakesdatabaseid));
if( $correct){ if ($correct) {
if( ($next=game_snakes_foundlander( $snakes->position + $snakes->dice, $data))){ if (($next = game_snakes_foundlander( $snakes->position + $snakes->dice, $data))) {
$snakes->position = $next; $snakes->position = $next;
}else } else {
{
$snakes->position = $snakes->position + $snakes->dice; $snakes->position = $snakes->position + $snakes->dice;
} }
}else } else {
{ if (($next = game_snakes_foundsnake( $snakes->position, $data))) {
if( ($next=game_snakes_foundsnake( $snakes->position, $data))){
$snakes->position = $next; $snakes->position = $next;
} }
} }
@ -378,7 +383,7 @@ function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query,
$updrec->position = $snakes->position; $updrec->position = $snakes->position;
$updrec->queryid = 0; $updrec->queryid = 0;
if( !$DB->update_record( 'game_snakes', $updrec)){ if (!$DB->update_record( 'game_snakes', $updrec)) {
print_error( "game_snakes_position: Can't update game_snakes"); print_error( "game_snakes_position: Can't update game_snakes");
} }
@ -393,24 +398,22 @@ function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query,
game_snakes_play( $id, $game, $attempt, $snakes, $context); game_snakes_play( $id, $game, $attempt, $snakes, $context);
} }
//in lander go forward // In lander go forward.
function game_snakes_foundlander( $position, $data) function game_snakes_foundlander( $position, $data) {
{
preg_match( "/L$position-([0-9]*)/", $data, $matches); preg_match( "/L$position-([0-9]*)/", $data, $matches);
if( count( $matches)){ if (count( $matches)) {
return $matches[ 1]; return $matches[ 1];
} }
return 0; return 0;
} }
//in snake go backward // In snake go backward.
function game_snakes_foundsnake( $position, $data) function game_snakes_foundsnake( $position, $data) {
{
preg_match( "/S([0-9]*)-$position,/", $data.',', $matches); preg_match( "/S([0-9]*)-$position,/", $data.',', $matches);
if( count( $matches)){ if (count( $matches)) {
return $matches[ 1]; return $matches[ 1];
} }
@ -429,7 +432,7 @@ function game_snakes_remove_attemptdata ($questionusageid, $questionid) {
AND state != 'todo'"; AND state != 'todo'";
if ($stepdata = $DB->get_records_sql($sql)) { if ($stepdata = $DB->get_records_sql($sql)) {
foreach($stepdata as $step) { foreach ($stepdata as $step) {
if ($step->id > 0) { if ($step->id > 0) {
$DB->delete_records('question_attempt_step_data', array('attemptstepid' => $step->id)); $DB->delete_records('question_attempt_step_data', array('attemptstepid' => $step->id));
$DB->get_records_sql("update {question_attempt_steps} set state='todo' where id = {$step->id}"); $DB->get_records_sql("update {question_attempt_steps} set state='todo' where id = {$step->id}");

Loading…
Cancel
Save