Browse Source

Fix:Coding style

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
b5f11fca18
  1. 81
      lang/en/game.php
  2. 1073
      millionaire/play.php
  3. 66
      report/default.php
  4. 328
      report/overview/report.php
  5. 332
      snakes/createboard.php
  6. 483
      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';

1073
millionaire/play.php

File diff suppressed because it is too large

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');
} }
} }
?>

328
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".
@ -114,18 +132,18 @@ class game_report extends game_default_report {
" WHERE i.gameid = '$game->id' AND q.id = i.questionid". " WHERE i.gameid = '$game->id' AND q.id = i.questionid".
" AND q.id IN ($questionlist)"; " AND q.id IN ($questionlist)";
if (!$questions = get_records_sql($sql)) { if (!$questions = get_records_sql($sql)) {
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,14 +411,13 @@ 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';
} }
$table->pagesize($pagesize, $total); $table->pagesize($pagesize, $total);
@ -402,15 +426,16 @@ 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());
} else { } else {
$attempts = get_records_sql($select.$from.$where.$sort); $attempts = get_records_sql($select.$from.$where.$sort);
} }
@ -418,66 +443,81 @@ 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;
} }
} }
?>

332
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;
{ $movey = -$movey;
$starty += $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);

483
snakes/play.php

@ -1,74 +1,86 @@
<?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.
return game_snakes_play( $id, $game, $attempt, $snakes, $context); //
} // 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);
}
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->queryid = 0; $newrec->position = 1;
$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');
} }
game_updateattempts( $game, $attempt, 0, 0); game_updateattempts( $game, $attempt, 0, 0);
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))) {
print_error("Course Module ID was incorrect id=$id"); print_error("Course Module ID was incorrect id=$id");
} }
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\">".
echo "<a href=\"$CFG->wwwroot/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> '; 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> ';
$gradeattempt = 1;
$finish = 1; $gradeattempt = 1;
game_updateattempts( $game, $attempt, $gradeattempt, $finish); $finish = 1;
}else game_updateattempts( $game, $attempt, $gradeattempt, $finish);
{ } 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)
game_snakes_showquestion( $id, $game, $snakes, $query, $context);
if ($showboard and $game->param8 == 0) {
game_snakes_showquestion( $id, $game, $snakes, $query, $context);
}
?> ?>
<script language="javascript" event="onload" for="window"> <script language="javascript" event="onload" for="window">
<!-- <!--
@ -87,334 +99,325 @@ 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) {
game_snakes_showdice( $snakes, $board);
if( $finish == false){ }
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;
$pos = new stdClass();
$pos = new stdClass(); $pos->width = 22;
$pos->width = 22; $pos->height = 22;
$pos->height = 22;
$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; }
}
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");
} }
$snakes->queryid = $query->id; $snakes->queryid = $query->id;
$updrec = new stdClass(); $updrec = new stdClass();
$updrec->id = $snakes->id; $updrec->id = $snakes->id;
$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');
} }
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid);
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\" ".
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; "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";
// 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\" ".
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; "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";
// 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').': ';
echo "<input type=\"text\" name=\"answer\" size=30 /><br>"; echo "<input type=\"text\" name=\"answer\" size=30 /><br>";
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;
} }
$questionlist = $DB->get_field( 'game_queries', 'questionid', array( 'id' => $responses->queryid)); $questionlist = $DB->get_field( 'game_queries', 'questionid', array( 'id' => $responses->queryid));
$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;
} }
$query = $DB->get_record( 'game_queries', array( 'id' => $responses->queryid)); $query = $DB->get_record( 'game_queries', array( 'id' => $responses->queryid));
$glossaryentry = $DB->get_record( 'glossary_entries', array( 'id' => $query->glossaryentryid)); $glossaryentry = $DB->get_record( 'glossary_entries', array( 'id' => $query->glossaryentryid));
$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))) {
{ $snakes->position = $next;
if( ($next=game_snakes_foundsnake( $snakes->position, $data))){ }
$snakes->position = $next; }
}
}
$updrec = new stdClass(); $updrec = new stdClass();
$updrec->id = $snakes->id; $updrec->id = $snakes->id;
$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");
} }
$board = $DB->get_record_select( 'game_snakes_database', "id=$snakes->snakesdatabaseid"); $board = $DB->get_record_select( 'game_snakes_database', "id=$snakes->snakesdatabaseid");
$gradeattempt = $snakes->position / ($board->cols * $board->rows); $gradeattempt = $snakes->position / ($board->cols * $board->rows);
$finished = ( $snakes->position > $board->cols * $board->rows ? 1 : 0); $finished = ( $snakes->position > $board->cols * $board->rows ? 1 : 0);
game_updateattempts( $game, $attempt, $gradeattempt, $finished); game_updateattempts( $game, $attempt, $gradeattempt, $finished);
game_snakes_computenextquestion( $game, $snakes, $query); game_snakes_computenextquestion( $game, $snakes, $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];
} }
return 0; return 0;
} }
function game_snakes_remove_attemptdata ($questionusageid, $questionid) { function game_snakes_remove_attemptdata ($questionusageid, $questionid) {
@ -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