|
@ -1,59 +1,73 @@ |
|
|
<?php // $Id: play.php,v 1.19 2012/08/15 09:26:55 bdaloukas Exp $
|
|
|
<?php |
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/ |
|
|
// This file plays the game Hidden Picture |
|
|
// |
|
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify |
|
|
function game_hiddenpicture_continue( $id, $game, $attempt, $hiddenpicture, $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 |
|
|
|
|
|
// (at your option) any later version. |
|
|
|
|
|
// |
|
|
|
|
|
// Moodle is distributed in the hope that it will be useful, |
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
|
// GNU General Public License for more details. |
|
|
|
|
|
// |
|
|
|
|
|
// You should have received a copy of the GNU General Public License |
|
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
|
|
|
|
// This file plays the game Hidden Picture. |
|
|
|
|
|
|
|
|
|
|
|
function game_hiddenpicture_continue( $id, $game, $attempt, $hiddenpicture, $context) { |
|
|
global $DB, $USER; |
|
|
global $DB, $USER; |
|
|
|
|
|
|
|
|
if( $attempt != false and $hiddenpicture != false){ |
|
|
if ($attempt != false and $hiddenpicture != false) { |
|
|
//Continue a previous attempt |
|
|
// Continue a previous attempt. |
|
|
return game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
|
|
return game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if( $attempt == false){ |
|
|
if ($attempt == false) { |
|
|
//Start a new attempt |
|
|
// Start a new attempt. |
|
|
$attempt = game_addattempt( $game); |
|
|
$attempt = game_addattempt( $game); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$cols = $game->param1; |
|
|
$cols = $game->param1; |
|
|
$rows = $game->param2; |
|
|
$rows = $game->param2; |
|
|
if( $cols == 0){ |
|
|
if ($cols == 0) { |
|
|
print_error( get_string( 'hiddenpicture_nocols', 'game')); |
|
|
print_error( get_string( 'hiddenpicture_nocols', 'game')); |
|
|
} |
|
|
} |
|
|
if( $rows == 0){ |
|
|
if ($rows == 0) { |
|
|
print_error( get_string( 'hiddenpicture_norows', 'game')); |
|
|
print_error( get_string( 'hiddenpicture_norows', 'game')); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//new attempt |
|
|
// New attempt. |
|
|
$n = $game->param1 * $game->param2; |
|
|
$n = $game->param1 * $game->param2; |
|
|
$recs = game_questions_selectrandom( $game, CONST_GAME_TRIES_REPETITION*$n); |
|
|
$recs = game_questions_selectrandom( $game, CONST_GAME_TRIES_REPETITION * $n); |
|
|
$selected_recs = game_select_from_repetitions( $game, $recs, $n); |
|
|
$selectedrecs = game_select_from_repetitions( $game, $recs, $n); |
|
|
|
|
|
|
|
|
$newrec = game_hiddenpicture_selectglossaryentry( $game, $attempt); |
|
|
$newrec = game_hiddenpicture_selectglossaryentry( $game, $attempt); |
|
|
|
|
|
|
|
|
if( $recs === false){ |
|
|
if ($recs === false) { |
|
|
print_error( get_string( 'no_questions', 'game')); |
|
|
print_error( get_string( 'no_questions', 'game')); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$positions = array(); |
|
|
$positions = array(); |
|
|
$pos=1; |
|
|
$pos = 1; |
|
|
for($col=0; $col < $cols; $col++){ |
|
|
for ($col = 0; $col < $cols; $col++) { |
|
|
for( $row=0; $row < $rows; $row++){ |
|
|
for ($row = 0; $row < $rows; $row++) { |
|
|
$positions[] = $pos++; |
|
|
$positions[] = $pos++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
$i = 0; |
|
|
$i = 0; |
|
|
$field = ($game->sourcemodule == 'glossary' ? 'glossaryentryid' : 'questionid'); |
|
|
$field = ($game->sourcemodule == 'glossary' ? 'glossaryentryid' : 'questionid'); |
|
|
foreach( $recs as $rec) |
|
|
foreach ($recs as $rec) { |
|
|
{ |
|
|
if ($game->sourcemodule == 'glossary') { |
|
|
if( $game->sourcemodule == 'glossary') |
|
|
|
|
|
$key = $rec->glossaryentryid; |
|
|
$key = $rec->glossaryentryid; |
|
|
else |
|
|
} else { |
|
|
$key = $rec->questionid; |
|
|
$key = $rec->questionid; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if( !array_key_exists( $key, $selected_recs)) |
|
|
if (!array_key_exists( $key, $selectedrecs)) { |
|
|
continue; |
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$query = new stdClass(); |
|
|
$query = new stdClass(); |
|
|
$query->attemptid = $newrec->id; |
|
|
$query->attemptid = $newrec->id; |
|
@ -69,40 +83,40 @@ function game_hiddenpicture_continue( $id, $game, $attempt, $hiddenpicture, $con |
|
|
$query->questionid = $rec->questionid; |
|
|
$query->questionid = $rec->questionid; |
|
|
$query->glossaryentryid = $rec->glossaryentryid; |
|
|
$query->glossaryentryid = $rec->glossaryentryid; |
|
|
$query->score = 0; |
|
|
$query->score = 0; |
|
|
if( ($query->id = $DB->insert_record( 'game_queries', $query)) == 0){ |
|
|
if (($query->id = $DB->insert_record( 'game_queries', $query)) == 0) { |
|
|
print_error( 'error inserting in game_queries'); |
|
|
print_error( 'error inserting in game_queries'); |
|
|
} |
|
|
} |
|
|
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
|
|
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//The score is zero |
|
|
// The score is zero. |
|
|
game_updateattempts( $game, $attempt, 0, 0); |
|
|
game_updateattempts( $game, $attempt, 0, 0); |
|
|
|
|
|
|
|
|
game_hiddenpicture_play( $id, $game, $attempt, $newrec, false, $context); |
|
|
game_hiddenpicture_play( $id, $game, $attempt, $newrec, false, $context); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Create the game_hiddenpicture record |
|
|
// Create the game_hiddenpicture record. |
|
|
function game_hiddenpicture_selectglossaryentry( $game, $attempt){ |
|
|
function game_hiddenpicture_selectglossaryentry( $game, $attempt) { |
|
|
global $CFG, $DB, $USER; |
|
|
global $CFG, $DB, $USER; |
|
|
|
|
|
|
|
|
srand( (double)microtime()*1000000); |
|
|
srand( (double)microtime() * 1000000); |
|
|
|
|
|
|
|
|
if( $game->glossaryid2 == 0){ |
|
|
if ($game->glossaryid2 == 0) { |
|
|
print_error( get_string( 'must_select_glossary', 'game')); |
|
|
print_error( get_string( 'must_select_glossary', 'game')); |
|
|
} |
|
|
} |
|
|
$select = "ge.glossaryid={$game->glossaryid2}"; |
|
|
$select = "ge.glossaryid={$game->glossaryid2}"; |
|
|
$table = '{glossary_entries} ge'; |
|
|
$table = '{glossary_entries} ge'; |
|
|
if( $game->glossarycategoryid2){ |
|
|
if ($game->glossarycategoryid2) { |
|
|
$table .= ",{glossary_entries_categories} gec"; |
|
|
$table .= ",{glossary_entries_categories} gec"; |
|
|
$select .= " AND gec.entryid = ge.id AND gec.categoryid = {$game->glossarycategoryid2}"; |
|
|
$select .= " AND gec.entryid = ge.id AND gec.categoryid = {$game->glossarycategoryid2}"; |
|
|
} |
|
|
} |
|
|
if( $game->param7 == 0){ |
|
|
if ($game->param7 == 0) { |
|
|
//Allow spaces |
|
|
// Allow spaces. |
|
|
$select .= " AND concept NOT LIKE '% %'"; |
|
|
$select .= " AND concept NOT LIKE '% %'"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$sql = "SELECT ge.id,attachment FROM $table WHERE $select"; |
|
|
$sql = "SELECT ge.id,attachment FROM $table WHERE $select"; |
|
|
if( ($recs=$DB->get_records_sql( $sql)) == false){ |
|
|
if (($recs = $DB->get_records_sql( $sql)) == false) { |
|
|
$a->name = "'".$DB->get_field('glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
|
|
$a->name = "'".$DB->get_field('glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
|
|
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
|
|
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
|
|
return false; |
|
|
return false; |
|
@ -112,58 +126,56 @@ function game_hiddenpicture_selectglossaryentry( $game, $attempt){ |
|
|
$fs = get_file_storage(); |
|
|
$fs = get_file_storage(); |
|
|
$cmg = get_coursemodule_from_instance('glossary', $game->glossaryid2, $game->course); |
|
|
$cmg = get_coursemodule_from_instance('glossary', $game->glossaryid2, $game->course); |
|
|
$context = game_get_context_module_instance( $cmg->id); |
|
|
$context = game_get_context_module_instance( $cmg->id); |
|
|
foreach( $recs as $rec){ |
|
|
foreach ($recs as $rec) { |
|
|
$files = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $rec->id, "timemodified", false); |
|
|
$files = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $rec->id, "timemodified", false); |
|
|
if( $files) |
|
|
if ($files) { |
|
|
{ |
|
|
foreach ($files as $key => $file) { |
|
|
foreach( $files as $key => $file) |
|
|
|
|
|
{ |
|
|
|
|
|
$s = strtoupper( $file->get_filename()); |
|
|
$s = strtoupper( $file->get_filename()); |
|
|
$s = substr( $s, -4); |
|
|
$s = substr( $s, -4); |
|
|
if( $s == '.GIF' or $s == '.JPG' or $s == '.PNG'){ |
|
|
if ($s == '.GIF' or $s == '.JPG' or $s == '.PNG') { |
|
|
$ids[] = $rec->id; |
|
|
$ids[] = $rec->id; |
|
|
$keys[] = $file->get_pathnamehash(); |
|
|
$keys[] = $file->get_pathnamehash(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if( count( $ids) == 0){ |
|
|
if (count( $ids) == 0) { |
|
|
$a->name = "'".$DB->get_field( 'glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
|
|
$a->name = "'".$DB->get_field( 'glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
|
|
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
|
|
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Have to select randomly one glossaryentry |
|
|
// Have to select randomly one glossaryentry. |
|
|
$poss = array(); |
|
|
$poss = array(); |
|
|
for($i=0;$i<count($ids);$i++){ |
|
|
for ($i = 0; $i < count($ids); $i++) { |
|
|
$poss[] = $i; |
|
|
$poss[] = $i; |
|
|
} |
|
|
} |
|
|
shuffle( $poss); |
|
|
shuffle( $poss); |
|
|
$min_num = 0; |
|
|
$minnum = 0; |
|
|
$attachement = ''; |
|
|
$attachement = ''; |
|
|
for($i=0;$i<count($ids);$i++){ |
|
|
for ($i = 0; $i < count($ids); $i++) { |
|
|
$pos = $poss[ $i]; |
|
|
$pos = $poss[ $i]; |
|
|
$tempid = $ids[ $pos]; |
|
|
$tempid = $ids[ $pos]; |
|
|
$a = array( 'gameid' => $game->id, 'userid' => $USER->id, 'questionid' => 0, 'glossaryentryid' => $tempid); |
|
|
$a = array( 'gameid' => $game->id, 'userid' => $USER->id, 'questionid' => 0, 'glossaryentryid' => $tempid); |
|
|
if(($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions r')) != false){ |
|
|
if (($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions r')) != false) { |
|
|
if( ($rec2->r < $min_num) or ($min_num == 0)){ |
|
|
if (($rec2->r < $minnum) or ($minnum == 0)) { |
|
|
$min_num = $rec2->r; |
|
|
$minnum = $rec2->r; |
|
|
$glossaryentryid = $tempid; |
|
|
$glossaryentryid = $tempid; |
|
|
$attachement = $keys[ $pos]; |
|
|
$attachement = $keys[ $pos]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
else{ |
|
|
|
|
|
$glossaryentryid = $tempid; |
|
|
$glossaryentryid = $tempid; |
|
|
$attachement = $keys[ $pos]; |
|
|
$attachement = $keys[ $pos]; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$sql = 'SELECT id, concept as answertext, definition as questiontext, id as glossaryentryid, 0 as questionid, glossaryid, attachment'. |
|
|
$sql = 'SELECT id, concept as answertext, definition as questiontext,'. |
|
|
|
|
|
' id as glossaryentryid, 0 as questionid, glossaryid, attachment'. |
|
|
' FROM {glossary_entries} WHERE id = '.$glossaryentryid; |
|
|
' FROM {glossary_entries} WHERE id = '.$glossaryentryid; |
|
|
if( ($rec = $DB->get_record_sql( $sql)) == false) |
|
|
if (($rec = $DB->get_record_sql( $sql)) == false) { |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
} |
|
|
$query = new stdClass(); |
|
|
$query = new stdClass(); |
|
|
$query->attemptid = $attempt->id; |
|
|
$query->attemptid = $attempt->id; |
|
|
$query->gamekind = $game->gamekind; |
|
|
$query->gamekind = $game->gamekind; |
|
@ -178,13 +190,13 @@ function game_hiddenpicture_selectglossaryentry( $game, $attempt){ |
|
|
$query->questiontext = $rec->questiontext; |
|
|
$query->questiontext = $rec->questiontext; |
|
|
$query->answertext = $rec->answertext; |
|
|
$query->answertext = $rec->answertext; |
|
|
$query->score = 0; |
|
|
$query->score = 0; |
|
|
if( ($query->id = $DB->insert_record( 'game_queries', $query)) == 0){ |
|
|
if (($query->id = $DB->insert_record( 'game_queries', $query)) == 0) { |
|
|
print_error( 'Error inserting in game_queries'); |
|
|
print_error( 'Error inserting in game_queries'); |
|
|
} |
|
|
} |
|
|
$newrec = new stdClass(); |
|
|
$newrec = new stdClass(); |
|
|
$newrec->id = $attempt->id; |
|
|
$newrec->id = $attempt->id; |
|
|
$newrec->correct = 0; |
|
|
$newrec->correct = 0; |
|
|
if( !game_insert_record( 'game_hiddenpicture', $newrec)){ |
|
|
if (!game_insert_record( 'game_hiddenpicture', $newrec)) { |
|
|
print_error( 'Error inserting in game_hiddenpicture'); |
|
|
print_error( 'Error inserting in game_hiddenpicture'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -193,71 +205,74 @@ function game_hiddenpicture_selectglossaryentry( $game, $attempt){ |
|
|
return $newrec; |
|
|
return $newrec; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, $showsolution, $context) |
|
|
function game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, $showsolution, $context) { |
|
|
{ |
|
|
if ($game->toptext != '') { |
|
|
if( $game->toptext != ''){ |
|
|
|
|
|
echo $game->toptext.'<br>'; |
|
|
echo $game->toptext.'<br>'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Show picture |
|
|
// Show picture. |
|
|
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions); |
|
|
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions); |
|
|
unset( $offsetquestions[ 0]); |
|
|
unset( $offsetquestions[ 0]); |
|
|
|
|
|
|
|
|
game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, $offsetquestions, $correctquestions, $id, $attempt, $showsolution); |
|
|
game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, |
|
|
|
|
|
$offsetquestions, $correctquestions, $id, $attempt, $showsolution); |
|
|
|
|
|
|
|
|
//Show questions |
|
|
// Show questions. |
|
|
$onlyshow = false; |
|
|
$onlyshow = false; |
|
|
$showsolution = false; |
|
|
$showsolution = false; |
|
|
|
|
|
|
|
|
switch( $game->sourcemodule) |
|
|
switch ($game->sourcemodule) { |
|
|
{ |
|
|
|
|
|
case 'quiz': |
|
|
case 'quiz': |
|
|
case 'question': |
|
|
case 'question': |
|
|
game_sudoku_showquestions_quiz( $id, $game, $attempt, $hiddenpicture, $offsetquestions, $numbers, $correctquestions, $onlyshow, $showsolution, $context); |
|
|
game_sudoku_showquestions_quiz( $id, $game, $attempt, $hiddenpicture, $offsetquestions, |
|
|
|
|
|
$numbers, $correctquestions, $onlyshow, $showsolution, $context); |
|
|
break; |
|
|
break; |
|
|
case 'glossary': |
|
|
case 'glossary': |
|
|
game_sudoku_showquestions_glossary( $id, $game, $attempt, $hiddenpicture, $offsetquestions, $numbers, $correctquestions, $onlyshow, $showsolution); |
|
|
game_sudoku_showquestions_glossary( $id, $game, $attempt, $hiddenpicture, |
|
|
|
|
|
$offsetquestions, $numbers, $correctquestions, $onlyshow, $showsolution); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if( $game->bottomtext != ''){ |
|
|
if ($game->bottomtext != '') { |
|
|
echo '<br><br>'.$game->bottomtext; |
|
|
echo '<br><br>'.$game->bottomtext; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function game_hidden_picture_computescore( $game, $hiddenpicture){ |
|
|
function game_hidden_picture_computescore( $game, $hiddenpicture) { |
|
|
$correct = $hiddenpicture->correct; |
|
|
$correct = $hiddenpicture->correct; |
|
|
if( $hiddenpicture->found){ |
|
|
if ($hiddenpicture->found) { |
|
|
$correct++; |
|
|
$correct++; |
|
|
} |
|
|
} |
|
|
$remaining = $game->param1 * $game->param2 - $hiddenpicture->correct; |
|
|
$remaining = $game->param1 * $game->param2 - $hiddenpicture->correct; |
|
|
$div2 = $correct + $hiddenpicture->wrong + $remaining; |
|
|
$div2 = $correct + $hiddenpicture->wrong + $remaining; |
|
|
if( $hiddenpicture->found){ |
|
|
if ($hiddenpicture->found) { |
|
|
$percent = ($correct + $remaining) / $div2; |
|
|
$percent = ($correct + $remaining) / $div2; |
|
|
}else{ |
|
|
} else { |
|
|
$percent = $correct / $div2; |
|
|
$percent = $correct / $div2; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $percent; |
|
|
return $percent; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, $offsetquestions, $correctquestions){ |
|
|
function game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, |
|
|
|
|
|
$offsetquestions, $correctquestions) { |
|
|
global $DB; |
|
|
global $DB; |
|
|
|
|
|
|
|
|
$foundcells=''; |
|
|
$foundcells = ''; |
|
|
foreach( $correctquestions as $key => $val){ |
|
|
foreach ($correctquestions as $key => $val) { |
|
|
$foundcells .= ','.$key; |
|
|
$foundcells .= ','.$key; |
|
|
} |
|
|
} |
|
|
$cells=''; |
|
|
$cells = ''; |
|
|
foreach( $offsetquestions as $key => $val){ |
|
|
foreach ($offsetquestions as $key => $val) { |
|
|
if( $key != 0){ |
|
|
if ($key != 0) { |
|
|
$cells .= ','.$key; |
|
|
$cells .= ','.$key; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$query = $DB->get_record_select( 'game_queries', "attemptid=$hiddenpicture->id AND col=0", null, 'id,glossaryentryid,attachment,questiontext'); |
|
|
$query = $DB->get_record_select( 'game_queries', "attemptid=$hiddenpicture->id AND col=0", |
|
|
|
|
|
null, 'id,glossaryentryid,attachment,questiontext'); |
|
|
|
|
|
|
|
|
//Grade |
|
|
// Grade. |
|
|
echo "<br/>".get_string( 'grade', 'game').' : '.round( $attempt->score * 100).' %'; |
|
|
echo "<br/>".get_string( 'grade', 'game').' : '.round( $attempt->score * 100).' %'; |
|
|
|
|
|
|
|
|
game_hiddenpicture_showquestion_glossary( $game, $id, $query); |
|
|
game_hiddenpicture_showquestion_glossary( $game, $id, $query); |
|
@ -267,23 +282,24 @@ function game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpict |
|
|
game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, true); |
|
|
game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function game_hiddenpicture_showquestion_glossary( $game, $id, $query) |
|
|
function game_hiddenpicture_showquestion_glossary( $game, $id, $query) { |
|
|
{ |
|
|
|
|
|
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 '<br>'; |
|
|
echo '<br>'; |
|
|
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('hiddenpicture_mainsubmit', '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('hiddenpicture_mainsubmit', '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="hiddenpicturecheckg" />'; |
|
|
echo '<input type="hidden" name="action" value="hiddenpicturecheckg" />'; |
|
|
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; |
|
|
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; |
|
|
|
|
|
|
|
|
// 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"; |
|
|
|
|
|
|
|
|
$temp = $game->glossaryid; |
|
|
$temp = $game->glossaryid; |
|
@ -297,8 +313,7 @@ function game_hiddenpicture_showquestion_glossary( $game, $id, $query) |
|
|
echo "</form><br>\n"; |
|
|
echo "</form><br>\n"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpicture, $finishattempt) |
|
|
function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpicture, $finishattempt) { |
|
|
{ |
|
|
|
|
|
global $QTYPES, $DB; |
|
|
global $QTYPES, $DB; |
|
|
|
|
|
|
|
|
$responses = data_submitted(); |
|
|
$responses = data_submitted(); |
|
@ -312,9 +327,9 @@ function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpict |
|
|
$actions = question_extract_responses($questions, $responses, QUESTION_EVENTSUBMIT); |
|
|
$actions = question_extract_responses($questions, $responses, QUESTION_EVENTSUBMIT); |
|
|
|
|
|
|
|
|
$correct = $wrong = 0; |
|
|
$correct = $wrong = 0; |
|
|
foreach($questions as $question) { |
|
|
foreach ($questions as $question) { |
|
|
if( !array_key_exists( $question->id, $actions)){ |
|
|
if (!array_key_exists( $question->id, $actions)) { |
|
|
//no answered |
|
|
// No answered. |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
unset( $state); |
|
|
unset( $state); |
|
@ -330,19 +345,19 @@ function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpict |
|
|
|
|
|
|
|
|
$select = "attemptid=$attempt->id"; |
|
|
$select = "attemptid=$attempt->id"; |
|
|
$select .= " AND questionid=$question->id"; |
|
|
$select .= " AND questionid=$question->id"; |
|
|
if( ($query->id = $DB->get_field_select( 'game_queries', 'id', $select)) == 0){ |
|
|
if (($query->id = $DB->get_field_select( 'game_queries', 'id', $select)) == 0) { |
|
|
print_error("problem game_hiddenpicture_check_questions (select=$select)"); |
|
|
print_error("problem game_hiddenpicture_check_questions (select=$select)"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$answertext = $state->responses[ '']; |
|
|
$answertext = $state->responses[ '']; |
|
|
if( $answertext != ''){ |
|
|
if ($answertext != '') { |
|
|
$grade = $state->raw_grade; |
|
|
$grade = $state->raw_grade; |
|
|
if( $grade < 50){ |
|
|
if ($grade < 50) { |
|
|
//wrong answer |
|
|
// Wrong answer. |
|
|
game_update_queries( $game, $attempt, $query, $grade/100, $answertext); |
|
|
game_update_queries( $game, $attempt, $query, $grade / 100, $answertext); |
|
|
$wrong++; |
|
|
$wrong++; |
|
|
}else{ |
|
|
} else { |
|
|
//correct answer |
|
|
// Correct answer. |
|
|
game_update_queries( $game, $attempt, $query, 1, $answertext); |
|
|
game_update_queries( $game, $attempt, $query, 1, $answertext); |
|
|
$correct++; |
|
|
$correct++; |
|
|
} |
|
|
} |
|
@ -352,12 +367,12 @@ function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpict |
|
|
$hiddenpicture->correct += $correct; |
|
|
$hiddenpicture->correct += $correct; |
|
|
$hiddenpicture->wrong += $wrong; |
|
|
$hiddenpicture->wrong += $wrong; |
|
|
|
|
|
|
|
|
if( !$DB->update_record( 'game_hiddenpicture', $hiddenpicture)){ |
|
|
if (!$DB->update_record( 'game_hiddenpicture', $hiddenpicture)) { |
|
|
print_error( 'game_hiddenpicture_check_questions: error updating in game_hiddenpicture'); |
|
|
print_error( 'game_hiddenpicture_check_questions: error updating in game_hiddenpicture'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$attempt->score = game_hidden_picture_computescore( $game, $hiddenpicture); |
|
|
$attempt->score = game_hidden_picture_computescore( $game, $hiddenpicture); |
|
|
if( !$DB->update_record( 'game_attempts', $attempt)){ |
|
|
if (!$DB->update_record( 'game_attempts', $attempt)) { |
|
|
print_error( 'game_hiddenpicture_check_questions: error updating in game_attempt'); |
|
|
print_error( 'game_hiddenpicture_check_questions: error updating in game_attempt'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -366,8 +381,7 @@ function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpict |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function game_hiddenpicture_check_mainquestion( $id, $game, &$attempt, &$hiddenpicture, $finishattempt, $context) |
|
|
function game_hiddenpicture_check_mainquestion( $id, $game, &$attempt, &$hiddenpicture, $finishattempt, $context) { |
|
|
{ |
|
|
|
|
|
global $QTYPES, $CFG, $DB; |
|
|
global $QTYPES, $CFG, $DB; |
|
|
|
|
|
|
|
|
$responses = data_submitted(); |
|
|
$responses = data_submitted(); |
|
@ -375,46 +389,47 @@ function game_hiddenpicture_check_mainquestion( $id, $game, &$attempt, &$hiddenp |
|
|
$glossaryentryid = $responses->glossaryentryid; |
|
|
$glossaryentryid = $responses->glossaryentryid; |
|
|
$queryid = $responses->queryid; |
|
|
$queryid = $responses->queryid; |
|
|
|
|
|
|
|
|
// Load the glossary entry |
|
|
// Load the glossary entry. |
|
|
if (!($entry = $DB->get_record( 'glossary_entries', array( 'id' => $glossaryentryid)))) { |
|
|
if (!($entry = $DB->get_record( 'glossary_entries', array( 'id' => $glossaryentryid)))) { |
|
|
print_error( get_string( 'noglossaryentriesfound', 'game')); |
|
|
print_error( get_string( 'noglossaryentriesfound', 'game')); |
|
|
} |
|
|
} |
|
|
$answer = $responses->answer; |
|
|
$answer = $responses->answer; |
|
|
$correct = false; |
|
|
$correct = false; |
|
|
if( $answer != ''){ |
|
|
if ($answer != '') { |
|
|
if( game_upper( $entry->concept) == game_upper( $answer)){ |
|
|
if (game_upper( $entry->concept) == game_upper( $answer)) { |
|
|
$correct = true; |
|
|
$correct = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Load the query |
|
|
// Load the query. |
|
|
if (!($query = $DB->get_record( 'game_queries', array( 'id' => $queryid)))) { |
|
|
if (!($query = $DB->get_record( 'game_queries', array( 'id' => $queryid)))) { |
|
|
print_error( "The query $queryid not found"); |
|
|
print_error( "The query $queryid not found"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
game_update_queries( $game, $attempt, $query, $correct, $answer); |
|
|
game_update_queries( $game, $attempt, $query, $correct, $answer); |
|
|
|
|
|
|
|
|
if( $correct){ |
|
|
if ($correct) { |
|
|
$hiddenpicture->found = 1; |
|
|
$hiddenpicture->found = 1; |
|
|
}else{ |
|
|
} else { |
|
|
$hiddenpicture->wrong++; |
|
|
$hiddenpicture->wrong++; |
|
|
} |
|
|
} |
|
|
if( !$DB->update_record( 'game_hiddenpicture', $hiddenpicture)){ |
|
|
if (!$DB->update_record( 'game_hiddenpicture', $hiddenpicture)) { |
|
|
print_error( 'game_hiddenpicture_check_mainquestion: error updating in game_hiddenpicture'); |
|
|
print_error( 'game_hiddenpicture_check_mainquestion: error updating in game_hiddenpicture'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$score = game_hidden_picture_computescore( $game, $hiddenpicture); |
|
|
$score = game_hidden_picture_computescore( $game, $hiddenpicture); |
|
|
game_updateattempts( $game, $attempt, $score, $correct); |
|
|
game_updateattempts( $game, $attempt, $score, $correct); |
|
|
|
|
|
|
|
|
if( $correct == false){ |
|
|
if ($correct == false) { |
|
|
game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
|
|
game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Finish the game |
|
|
// Finish the game. |
|
|
$query = $DB->get_record_select( 'game_queries', "attemptid=$hiddenpicture->id AND col=0", null, 'id,glossaryentryid,attachment,questiontext'); |
|
|
$query = $DB->get_record_select( 'game_queries', "attemptid=$hiddenpicture->id AND col=0", |
|
|
|
|
|
null, 'id,glossaryentryid,attachment,questiontext'); |
|
|
game_showpicture( $id, $game, $attempt, $query, '', '', false); |
|
|
game_showpicture( $id, $game, $attempt, $query, '', '', false); |
|
|
echo '<p><BR/><font size="5" color="green">'.get_string( 'win', 'game').'</font><BR/><BR/></p>'; |
|
|
echo '<p><br/><font size="5" color="green">'.get_string( 'win', 'game').'</font><BR/><BR/></p>'; |
|
|
global $CFG; |
|
|
global $CFG; |
|
|
|
|
|
|
|
|
echo '<br/>'; |
|
|
echo '<br/>'; |
|
@ -431,15 +446,14 @@ function game_hiddenpicture_check_mainquestion( $id, $game, &$attempt, &$hiddenp |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, $usemap) |
|
|
function game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, $usemap) { |
|
|
{ |
|
|
|
|
|
global $CFG; |
|
|
global $CFG; |
|
|
|
|
|
|
|
|
$filenamenumbers = str_replace( "\\", '/', $CFG->dirroot)."/mod/game/hiddenpicture/numbers.png"; |
|
|
$filenamenumbers = str_replace( "\\", '/', $CFG->dirroot)."/mod/game/hiddenpicture/numbers.png"; |
|
|
if( $usemap){ |
|
|
if ($usemap) { |
|
|
$cols = $game->param1; |
|
|
$cols = $game->param1; |
|
|
$rows = $game->param2; |
|
|
$rows = $game->param2; |
|
|
}else{ |
|
|
} else { |
|
|
$cols = $rows = 0; |
|
|
$cols = $rows = 0; |
|
|
} |
|
|
} |
|
|
$params = "id=$id&id2=$attempt->id&f=$foundcells&cols=$cols&rows=$rows&cells=$cells&p={$query->attachment}&n=$filenamenumbers"; |
|
|
$params = "id=$id&id2=$attempt->id&f=$foundcells&cols=$cols&rows=$rows&cells=$cells&p={$query->attachment}&n=$filenamenumbers"; |
|
@ -448,29 +462,28 @@ function game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, $u |
|
|
$fs = get_file_storage(); |
|
|
$fs = get_file_storage(); |
|
|
$file = get_file_storage()->get_file_by_hash( $query->attachment); |
|
|
$file = get_file_storage()->get_file_by_hash( $query->attachment); |
|
|
$image = $file->get_imageinfo(); |
|
|
$image = $file->get_imageinfo(); |
|
|
if( $game->param4 > 10){ |
|
|
if ($game->param4 > 10) { |
|
|
$width = $game->param4; |
|
|
$width = $game->param4; |
|
|
$height = $image[ 'height'] * $width / $image[ 'width']; |
|
|
$height = $image[ 'height'] * $width / $image[ 'width']; |
|
|
}else if( $game->param5 > 10){ |
|
|
} else if ( $game->param5 > 10) { |
|
|
$height = $game->param5; |
|
|
$height = $game->param5; |
|
|
$width = $image[ 'width'] * $height / $image[ 'height']; |
|
|
$width = $image[ 'width'] * $height / $image[ 'height']; |
|
|
}else |
|
|
} else { |
|
|
{ |
|
|
|
|
|
$width = $image[ 'width']; |
|
|
$width = $image[ 'width']; |
|
|
$height = $image[ 'height']; |
|
|
$height = $image[ 'height']; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
echo "<IMG SRC=\"$imagesrc\" width=$width "; |
|
|
echo "<IMG SRC=\"$imagesrc\" width=$width "; |
|
|
if( $usemap){ |
|
|
if ($usemap) { |
|
|
echo " USEMAP=\"#mapname\" "; |
|
|
echo " USEMAP=\"#mapname\" "; |
|
|
} |
|
|
} |
|
|
echo " BORDER=\"1\">\r\n"; |
|
|
echo " BORDER=\"1\">\r\n"; |
|
|
|
|
|
|
|
|
if( $usemap){ |
|
|
if ($usemap) { |
|
|
echo "<MAP NAME=\"mapname\">\r\n"; |
|
|
echo "<MAP NAME=\"mapname\">\r\n"; |
|
|
$pos=0; |
|
|
$pos = 0; |
|
|
for($row=0; $row < $rows; $row++){ |
|
|
for ($row = 0; $row < $rows; $row++) { |
|
|
for( $col=0; $col < $cols; $col++){ |
|
|
for ($col = 0; $col < $cols; $col++) { |
|
|
$pos++; |
|
|
$pos++; |
|
|
$x1 = $col * $width / $cols; |
|
|
$x1 = $col * $width / $cols; |
|
|
$y1 = $row * $height / $rows; |
|
|
$y1 = $row * $height / $rows; |
|
@ -483,4 +496,3 @@ function game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, $u |
|
|
echo "</MAP>"; |
|
|
echo "</MAP>"; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|