Vasilis Daloukas
9 years ago
11 changed files with 1793 additions and 1827 deletions
File diff suppressed because it is too large
@ -1,382 +1,392 @@ |
|||||
<?php // $Id: play.php,v 1.8 2012/07/25 22:46:42 bdaloukas Exp $
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
function game_bookquiz_continue( $id, $game, $attempt, $bookquiz, $chapterid, $context) |
// |
||||
{ |
// Moodle is free software: you can redistribute it and/or modify |
||||
if( $attempt != false and $bookquiz != false){ |
// it under the terms of the GNU General Public License as published by |
||||
return game_bookquiz_play( $id, $game, $attempt, $bookquiz, $chapterid, $context); |
// the Free Software Foundation, either version 3 of the License, or |
||||
} |
// (at your option) any later version. |
||||
|
// |
||||
if( $attempt == false){ |
// Moodle is distributed in the hope that it will be useful, |
||||
$attempt = game_addattempt( $game); |
// 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. |
||||
$bookquiz = new stdClass(); |
// |
||||
$bookquiz->lastchapterid = 0; |
// You should have received a copy of the GNU General Public License |
||||
$bookquiz->id = $attempt->id; |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
$bookquiz->bookid = $game->bookid; |
|
||||
|
function game_bookquiz_continue( $id, $game, $attempt, $bookquiz, $chapterid, $context) { |
||||
if( !game_insert_record( 'game_bookquiz', $bookquiz)){ |
if ($attempt != false and $bookquiz != false) { |
||||
print_error( 'game_bookquiz_continue: error inserting in game_bookquiz'); |
return game_bookquiz_play( $id, $game, $attempt, $bookquiz, $chapterid, $context); |
||||
} |
} |
||||
|
|
||||
return game_bookquiz_play( $id, $game, $attempt, $bookquiz, 0, $context); |
if ($attempt == false) { |
||||
} |
$attempt = game_addattempt( $game); |
||||
|
} |
||||
function game_bookquiz_play( $id, $game, $attempt, $bookquiz, $chapterid, $context) |
|
||||
{ |
$bookquiz = new stdClass(); |
||||
global $DB, $OUTPUT, $cm; |
$bookquiz->lastchapterid = 0; |
||||
|
$bookquiz->id = $attempt->id; |
||||
if( $bookquiz->lastchapterid == 0){ |
$bookquiz->bookid = $game->bookid; |
||||
game_bookquiz_play_computelastchapter( $game, $bookquiz); |
|
||||
|
if ( !game_insert_record( 'game_bookquiz', $bookquiz)) { |
||||
if( $bookquiz->lastchapterid == 0){ |
print_error( 'game_bookquiz_continue: error inserting in game_bookquiz'); |
||||
print_error( get_string( 'bookquiz_empty', 'game')); |
} |
||||
} |
|
||||
} |
return game_bookquiz_play( $id, $game, $attempt, $bookquiz, 0, $context); |
||||
if( $chapterid == 0){ |
} |
||||
$chapterid = $bookquiz->lastchapterid; |
|
||||
}else |
function game_bookquiz_play( $id, $game, $attempt, $bookquiz, $chapterid, $context) { |
||||
{ |
global $DB, $OUTPUT, $cm; |
||||
if( ($DB->set_field( 'game_bookquiz', 'lastchapterid', $chapterid, array( 'id' => $bookquiz->id))) == false){ |
|
||||
print_error( "Can't update table game_bookquiz with lastchapterid to $chapterid"); |
if ($bookquiz->lastchapterid == 0) { |
||||
} |
game_bookquiz_play_computelastchapter( $game, $bookquiz); |
||||
} |
|
||||
|
if ($bookquiz->lastchapterid == 0) { |
||||
$book = $DB->get_record( 'book', array('id' => $game->bookid)); |
print_error( get_string( 'bookquiz_empty', 'game')); |
||||
if( !$chapter = $DB->get_record( 'book_chapters', array('id' => $chapterid))){ |
} |
||||
print_error('Error reading book chapters.'); |
} |
||||
} |
if ($chapterid == 0) { |
||||
$select = "bookid = $game->bookid AND hidden = 0"; |
$chapterid = $bookquiz->lastchapterid; |
||||
$chapters = $DB->get_records_select('book_chapters', $select, null, 'pagenum', 'id, pagenum, subchapter, title, hidden'); |
} else { |
||||
|
if (($DB->set_field( 'game_bookquiz', 'lastchapterid', $chapterid, array( 'id' => $bookquiz->id))) == false) { |
||||
$okchapters = array(); |
print_error( "Can't update table game_bookquiz with lastchapterid to $chapterid"); |
||||
if( ($recs = $DB->get_records( 'game_bookquiz_chapters', array( 'attemptid' => $attempt->id))) != false){ |
} |
||||
foreach( $recs as $rec){ |
} |
||||
//1 means correct answer |
|
||||
$okchapters[ $rec->chapterid] = 1; |
$book = $DB->get_record( 'book', array('id' => $game->bookid)); |
||||
} |
if (!$chapter = $DB->get_record( 'book_chapters', array('id' => $chapterid))) { |
||||
} |
print_error('Error reading book chapters.'); |
||||
//2 means current |
} |
||||
//$okchapters[ $chapterid] = 2; |
$select = "bookid = $game->bookid AND hidden = 0"; |
||||
$showquestions = false; |
$chapters = $DB->get_records_select('book_chapters', $select, null, 'pagenum', 'id, pagenum, subchapter, title, hidden'); |
||||
$a = array( 'gameid' => $game->id, 'chapterid' => $chapterid); |
|
||||
if( ($questions = $DB->get_records( 'game_bookquiz_questions', $a)) === false){ |
$okchapters = array(); |
||||
if( !array_key_exists( $chapterid, $okchapters)){ |
if (($recs = $DB->get_records( 'game_bookquiz_chapters', array( 'attemptid' => $attempt->id))) != false) { |
||||
$okchapters[ $chapterid] = 1; |
foreach ($recs as $rec) { |
||||
$newrec = new stdClass(); |
// The 1 means correct answer. |
||||
$newrec->attemptid = $attempt->id; |
$okchapters[ $rec->chapterid] = 1; |
||||
$newrec->chapterid = $chapterid; |
} |
||||
|
} |
||||
if( !$DB->insert_record( 'game_bookquiz_chapters', $newrec)){ |
|
||||
print_error( "Can't insert to table game_bookquiz_chapters"); |
// The 2 means current. |
||||
} |
$showquestions = false; |
||||
} |
$a = array( 'gameid' => $game->id, 'chapterid' => $chapterid); |
||||
}else |
if (($questions = $DB->get_records( 'game_bookquiz_questions', $a)) === false) { |
||||
{ |
if (!array_key_exists( $chapterid, $okchapters)) { |
||||
//Have to select random one question |
$okchapters[ $chapterid] = 1; |
||||
$questionid = game_bookquiz_selectrandomquestion( $questions); |
$newrec = new stdClass(); |
||||
if( $questionid != 0){ |
$newrec->attemptid = $attempt->id; |
||||
$showquestions = true; |
$newrec->chapterid = $chapterid; |
||||
} |
|
||||
} |
if (!$DB->insert_record( 'game_bookquiz_chapters', $newrec)) { |
||||
|
print_error( "Can't insert to table game_bookquiz_chapters"); |
||||
|
} |
||||
/// prepare chapter navigation icons |
} |
||||
$previd = null; |
} else { |
||||
$nextid = null; |
// Have to select random one question. |
||||
$found = 0; |
$questionid = game_bookquiz_selectrandomquestion( $questions); |
||||
$scoreattempt = 0; |
if ($questionid != 0) { |
||||
$lastid = 0; |
$showquestions = true; |
||||
foreach ($chapters as $ch) { |
} |
||||
$scoreattempt++; |
} |
||||
if ($found) { |
|
||||
$nextid= $ch->id; |
// Prepare chapter navigation icons. |
||||
break; |
$previd = null; |
||||
} |
$nextid = null; |
||||
if ($ch->id == $chapter->id) { |
$found = 0; |
||||
$found = 1; |
$scoreattempt = 0; |
||||
} |
$lastid = 0; |
||||
if (!$found) { |
foreach ($chapters as $ch) { |
||||
$previd = $ch->id; |
$scoreattempt++; |
||||
} |
if ($found) { |
||||
$lastid = $ch->id; |
$nextid = $ch->id; |
||||
} |
break; |
||||
if ($ch == current($chapters)) { |
} |
||||
$nextid = $ch->id; |
if ($ch->id == $chapter->id) { |
||||
} |
$found = 1; |
||||
if( count( $chapters)){ |
} |
||||
$scoreattempt = ($scoreattempt-1) / count( $chapters); |
if (!$found) { |
||||
} |
$previd = $ch->id; |
||||
|
} |
||||
$chnavigation = ''; |
$lastid = $ch->id; |
||||
|
} |
||||
|
if ($ch == current($chapters)) { |
||||
if ($previd) { |
$nextid = $ch->id; |
||||
$chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="attempt.php?id='.$id.'&chapterid='.$previd.'"><img src="'.$OUTPUT->pix_url('bookquiz/nav_prev', 'mod_game').'" class="bigicon" alt="'.get_string('navprev', 'book').'"/></a>'; |
} |
||||
} else { |
if (count( $chapters)) { |
||||
$chnavigation .= '<img src="'.$OUTPUT->pix_url('bookquiz/nav_prev_dis', 'mod_game').'" class="bigicon" alt="" />'; |
$scoreattempt = ($scoreattempt - 1) / count( $chapters); |
||||
} |
} |
||||
|
|
||||
$nextbutton = ''; |
$chnavigation = ''; |
||||
if ($nextid) { |
|
||||
if( !$showquestions){ |
if ($previd) { |
||||
$chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="attempt.php?id='.$id.'&chapterid='.$nextid.'"><img src="'.$OUTPUT->pix_url('bookquiz/nav_next', 'mod_game').'" class="bigicon" alt="'.get_string('navnext', 'book').'" ></a>'; |
$chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="attempt.php?id='.$id. |
||||
$nextbutton = '<center>'; |
'&chapterid='.$previd.'"><img src="'.$OUTPUT->pix_url('bookquiz/nav_prev', 'mod_game'). |
||||
$nextbutton .= '<form name="form" method="get" action="attempt.php">'; |
'" class="bigicon" alt="'.get_string('navprev', 'book').'"/></a>'; |
||||
$nextbutton .= '<input type="hidden" name="id" value="'.$id.'" >'."\r\n"; |
} else { |
||||
$nextbutton .= '<input type="hidden" name="chapterid" value="'.$nextid.'" >'."\r\n"; |
$chnavigation .= '<img src="'.$OUTPUT->pix_url('bookquiz/nav_prev_dis', 'mod_game').'" class="bigicon" alt="" />'; |
||||
$nextbutton .= '<input type="submit" value="'.get_string( 'continue').'">'; |
} |
||||
$nextbutton .= '</center>'; |
|
||||
$showquestions = false; |
$nextbutton = ''; |
||||
game_updateattempts_maxgrade( $game, $attempt, $scoreattempt, 0); |
if ($nextid) { |
||||
} |
if (!$showquestions) { |
||||
} else { |
$chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="attempt.php?id='. |
||||
game_updateattempts_maxgrade( $game, $attempt, 1, 0); |
$id.'&chapterid='.$nextid.'"><img src="'. |
||||
$sec = ''; |
$OUTPUT->pix_url('bookquiz/nav_next', 'mod_game').'" class="bigicon" alt="'.get_string('navnext', 'book').'" ></a>'; |
||||
if( !isset( $cm)) |
$nextbutton = '<center>'; |
||||
{ |
$nextbutton .= '<form name="form" method="get" action="attempt.php">'; |
||||
$cm = get_coursemodule_from_instance('game', $game->id, $game->course); |
$nextbutton .= '<input type="hidden" name="id" value="'.$id.'" >'."\r\n"; |
||||
} |
$nextbutton .= '<input type="hidden" name="chapterid" value="'.$nextid.'" >'."\r\n"; |
||||
if ($section = $DB->get_record('course_sections', array( 'id' => $cm->section))) { |
$nextbutton .= '<input type="submit" value="'.get_string( 'continue').'">'; |
||||
$sec = $section->section; |
$nextbutton .= '</center>'; |
||||
} |
$showquestions = false; |
||||
|
game_updateattempts_maxgrade( $game, $attempt, $scoreattempt, 0); |
||||
if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) { |
} |
||||
print_error("Course Module ID was incorrect id=$id"); |
} else { |
||||
} |
game_updateattempts_maxgrade( $game, $attempt, 1, 0); |
||||
$chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="attempt.php?id='.$id.'&chapterid='.$lastid.'><img src="'.$OUTPUT->pix_url('bookquiz/nav_exit', 'mod_game').'" class="bigicon" alt="'.get_string('navexit', 'book').'" /></a>'; |
$sec = ''; |
||||
} |
if (!isset( $cm)) { |
||||
|
$cm = get_coursemodule_from_instance('game', $game->id, $game->course); |
||||
require( 'toc.php'); |
} |
||||
$tocwidth = '10%'; |
|
||||
|
if ($section = $DB->get_record('course_sections', array( 'id' => $cm->section))) { |
||||
if( $showquestions){ |
$sec = $section->section; |
||||
if( $game->param3 == 0) |
} |
||||
game_bookquiz_showquestions( $id, $questionid, $chapter->id, $nextid, $scoreattempt, $game, $context); |
|
||||
} |
if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) { |
||||
|
print_error("Course Module ID was incorrect id=$id"); |
||||
|
} |
||||
?> |
$chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="attempt.php?id='. |
||||
<table border="0" cellspacing="0" width="100%" valign="top" cellpadding="2"> |
$id.'&chapterid='.$lastid.'><img src="'.$OUTPUT->pix_url('bookquiz/nav_exit', 'mod_game'). |
||||
|
'" class="bigicon" alt="'.get_string('navexit', 'book').'" /></a>'; |
||||
<!-- subchapter title and upper navigation row //--> |
} |
||||
<tr> |
|
||||
<td width="<?php echo 10;?>" valign="bottom"> |
require( 'toc.php'); |
||||
</td> |
$tocwidth = '10%'; |
||||
<td valign="top"> |
|
||||
<table border="0" cellspacing="0" width="100%" valign="top" cellpadding="0"> |
if ($showquestions) { |
||||
<tr> |
if ($game->param3 == 0) { |
||||
<td align="right"><?php echo $chnavigation ?></td> |
game_bookquiz_showquestions( $id, $questionid, $chapter->id, $nextid, $scoreattempt, $game, $context); |
||||
</tr> |
} |
||||
</table> |
} |
||||
</td> |
|
||||
</tr> |
?> |
||||
|
<table border="0" cellspacing="0" width="100%" valign="top" cellpadding="2"> |
||||
<!-- toc and chapter row //--> |
|
||||
<tr> |
<!-- subchapter title and upper navigation row //--> |
||||
<td width="<?php echo $tocwidth ?>" valign="top" align="left"> |
<tr> |
||||
<?php |
<td width="<?php echo 10;?>" valign="bottom"> |
||||
echo $OUTPUT->box_start('generalbox'); |
</td> |
||||
echo $toc; |
<td valign="top"> |
||||
echo $OUTPUT->box_end(); |
<table border="0" cellspacing="0" width="100%" valign="top" cellpadding="0"> |
||||
?> |
<tr> |
||||
</td> |
<td align="right"><?php echo $chnavigation ?></td> |
||||
<td valign="top" align="left"> |
</tr> |
||||
<?php |
</table> |
||||
echo $OUTPUT->box_start('generalbox'); |
</td> |
||||
$content = ''; |
</tr> |
||||
if (!$book->customtitles) { |
|
||||
if ($currsubtitle == ' ') { |
<!-- toc and chapter row //--> |
||||
$content .= '<p class="book_chapter_title">'.$currtitle.'</p>'; |
<tr> |
||||
} else { |
<td width="<?php echo $tocwidth ?>" valign="top" align="left"> |
||||
$content .= '<p class="book_chapter_title">'.$currtitle.'<br />'.$currsubtitle.'</p>'; |
<?php |
||||
} |
echo $OUTPUT->box_start('generalbox'); |
||||
} |
echo $toc; |
||||
$cmbook = get_coursemodule_from_instance( 'book', $game->bookid, $game->course); |
echo $OUTPUT->box_end(); |
||||
$modcontext = game_get_context_module_instance( $cmbook->id); |
?> |
||||
$content .= game_filterbook( $chapter->content, $chapter->id, $modcontext->id, $game->course); |
</td> |
||||
|
<td valign="top" align="left"> |
||||
$nocleanoption = new object(); |
<?php |
||||
$nocleanoption->noclean = true; |
echo $OUTPUT->box_start('generalbox'); |
||||
echo '<div>'; |
$content = ''; |
||||
if( $nextbutton != ''){ |
if (!$book->customtitles) { |
||||
echo $nextbutton; |
if ($currsubtitle == ' ') { |
||||
} |
$content .= '<p class="book_chapter_title">'.$currtitle.'</p>'; |
||||
echo format_text($content, FORMAT_HTML, $nocleanoption); |
} else { |
||||
if( $nextbutton != ''){ |
$content .= '<p class="book_chapter_title">'.$currtitle.'<br />'.$currsubtitle.'</p>'; |
||||
echo $nextbutton; |
} |
||||
} |
} |
||||
|
$cmbook = get_coursemodule_from_instance( 'book', $game->bookid, $game->course); |
||||
echo '</div>'; |
$modcontext = game_get_context_module_instance( $cmbook->id); |
||||
echo $OUTPUT->box_end(); |
$content .= game_filterbook( $chapter->content, $chapter->id, $modcontext->id, $game->course); |
||||
/// lower navigation |
|
||||
echo '<p align="right">'.$chnavigation.'</p>'; |
$nocleanoption = new object(); |
||||
?> |
$nocleanoption->noclean = true; |
||||
</td> |
echo '<div>'; |
||||
</tr> |
if ($nextbutton != '') { |
||||
</table> |
echo $nextbutton; |
||||
|
} |
||||
<?php |
echo format_text($content, FORMAT_HTML, $nocleanoption); |
||||
if( $showquestions){ |
if ($nextbutton != '') { |
||||
if( $game->param3 != 0) |
echo $nextbutton; |
||||
game_bookquiz_showquestions( $id, $questionid, $chapter->id, $nextid, $scoreattempt, $game, $context); |
} |
||||
} |
|
||||
} |
echo '</div>'; |
||||
|
echo $OUTPUT->box_end(); |
||||
function game_bookquiz_play_computelastchapter( $game, &$bookquiz) |
// Lower navigation. |
||||
{ |
echo '<p align="right">'.$chnavigation.'</p>'; |
||||
global $DB; |
?> |
||||
|
</td> |
||||
if( $game->bookid == 0) |
</tr> |
||||
{ |
</table> |
||||
print_error( 'Not defined a book on this game'); |
|
||||
} |
<?php |
||||
|
if ($showquestions) { |
||||
$pagenum = $DB->get_field( 'book_chapters', 'min(pagenum) as p', array('bookid' => $game->bookid)); |
if ($game->param3 != 0) { |
||||
|
game_bookquiz_showquestions( $id, $questionid, $chapter->id, $nextid, $scoreattempt, $game, $context); |
||||
if( $pagenum){ |
} |
||||
$bookquiz->lastchapterid = $DB->get_field( 'book_chapters', 'id', array('bookid' => $game->bookid, 'pagenum' => $pagenum)); |
} |
||||
|
} |
||||
if( $bookquiz->lastchapterid){ |
|
||||
//update the data in table game_bookquiz |
function game_bookquiz_play_computelastchapter( $game, &$bookquiz) { |
||||
if( ($DB->set_field( 'game_bookquiz', 'lastchapterid', $bookquiz->lastchapterid, array('id' => $bookquiz->id))) == false){ |
global $DB; |
||||
print_error( "Can't update table game_bookquiz with lastchapterid to $bookquiz->lastchapterid"); |
|
||||
} |
if ($game->bookid == 0) { |
||||
} |
print_error( 'Not defined a book on this game'); |
||||
} |
} |
||||
} |
|
||||
|
$pagenum = $DB->get_field( 'book_chapters', 'min(pagenum) as p', array('bookid' => $game->bookid)); |
||||
function game_bookquiz_showquestions( $id, $questionid, $chapterid, $nextchapterid, $scoreattempt, $game, $context) |
|
||||
{ |
if ($pagenum) { |
||||
$onlyshow = false; |
$bookquiz->lastchapterid = $DB->get_field( 'book_chapters', 'id', array('bookid' => $game->bookid, 'pagenum' => $pagenum)); |
||||
$showsolution = false; |
|
||||
|
if ($bookquiz->lastchapterid) { |
||||
$questionlist = $questionid; |
// Update the data in table game_bookquiz. |
||||
$questions = game_sudoku_getquestions( $questionlist); |
if (($DB->set_field( 'game_bookquiz', 'lastchapterid', $bookquiz->lastchapterid, |
||||
|
array('id' => $bookquiz->id))) == false) { |
||||
global $CFG; |
print_error( "Can't update table game_bookquiz with lastchapterid to $bookquiz->lastchapterid"); |
||||
|
} |
||||
/// Start the form |
} |
||||
echo "<form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; |
} |
||||
if( ($onlyshow === false) and ($showsolution === false)){ |
} |
||||
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; |
|
||||
} |
function game_bookquiz_showquestions( $id, $questionid, $chapterid, $nextchapterid, $scoreattempt, $game, $context) { |
||||
|
$onlyshow = false; |
||||
// Add a hidden field with the quiz id |
$showsolution = false; |
||||
echo '<div>'; |
|
||||
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; |
$questionlist = $questionid; |
||||
echo '<input type="hidden" name="action" value="bookquizcheck" />'; |
$questions = game_sudoku_getquestions( $questionlist); |
||||
echo '<input type="hidden" name="chapterid" value="'.$chapterid.'" />'; |
|
||||
echo '<input type="hidden" name="scoreattempt" value="'.$scoreattempt.'" />'; |
global $CFG; |
||||
echo '<input type="hidden" name="nextchapterid" value="'.$nextchapterid.'" />'; |
|
||||
|
// Start the form. |
||||
/// Print all the questions |
echo "<form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" ". |
||||
|
" onclick=\"this.autocomplete='off'\">\n"; |
||||
// Add a hidden field with questionids |
if (($onlyshow === false) and ($showsolution === false)) { |
||||
echo '<input type="hidden" name="questionids" value="'.$questionlist."\" />\n"; |
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; |
||||
|
} |
||||
$number=0; |
|
||||
foreach ($questions as $question) { |
// Add a hidden field with the quiz id. |
||||
game_print_question( $game, $question, $context); |
echo '<div>'; |
||||
} |
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; |
||||
echo "</div>"; |
echo '<input type="hidden" name="action" value="bookquizcheck" />'; |
||||
|
echo '<input type="hidden" name="chapterid" value="'.$chapterid.'" />'; |
||||
// Finish the form |
echo '<input type="hidden" name="scoreattempt" value="'.$scoreattempt.'" />'; |
||||
echo '</div>'; |
echo '<input type="hidden" name="nextchapterid" value="'.$nextchapterid.'" />'; |
||||
if( ($onlyshow === false) and ($showsolution === false)){ |
|
||||
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; |
// Print all the questions. |
||||
} |
|
||||
|
// Add a hidden field with questionids. |
||||
echo "</form>\n"; |
echo '<input type="hidden" name="questionids" value="'.$questionlist."\" />\n"; |
||||
} |
|
||||
|
$number = 0; |
||||
function game_bookquiz_selectrandomquestion( $questions) |
foreach ($questions as $question) { |
||||
{ |
game_print_question( $game, $question, $context); |
||||
global $DB; |
} |
||||
|
echo "</div>"; |
||||
$categorylist = ''; |
|
||||
if( $questions == false){ |
// Finish the form. |
||||
return 0; |
echo '</div>'; |
||||
} |
if (($onlyshow === false) and ($showsolution === false)) { |
||||
|
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; |
||||
foreach( $questions as $rec){ |
} |
||||
$categorylist .= ',' . $rec->questioncategoryid; |
|
||||
} |
echo "</form>\n"; |
||||
$select = 'category in ('.substr( $categorylist, 1). ") AND qtype in ('shortanswer', 'truefalse', 'multichoice')"; |
} |
||||
if( ($recs = $DB->get_records_select( 'question', $select, null, '', 'id,id')) == false){ |
|
||||
return 0; |
function game_bookquiz_selectrandomquestion( $questions) { |
||||
} |
global $DB; |
||||
$a = array(); |
|
||||
foreach( $recs as $rec){ |
$categorylist = ''; |
||||
$a[ $rec->id] = $rec->id; |
if ($questions == false) { |
||||
} |
return 0; |
||||
|
} |
||||
if( count( $a) == 0){ |
|
||||
return 0; |
foreach ($questions as $rec) { |
||||
}else |
$categorylist .= ',' . $rec->questioncategoryid; |
||||
{ |
} |
||||
return array_rand( $a); |
$select = 'category in ('.substr( $categorylist, 1). ") AND qtype in ('shortanswer', 'truefalse', 'multichoice')"; |
||||
} |
if (($recs = $DB->get_records_select( 'question', $select, null, '', 'id,id')) == false) { |
||||
} |
return 0; |
||||
|
} |
||||
function game_bookquiz_check_questions( $id, $game, $attempt, $bookquiz, $context) |
$a = array(); |
||||
{ |
foreach ($recs as $rec) { |
||||
global $USER, $DB; |
$a[ $rec->id] = $rec->id; |
||||
|
} |
||||
$scoreattempt = optional_param('scoreattempt', 0, PARAM_INT); |
|
||||
$responses = data_submitted(); |
if (count( $a) == 0) { |
||||
|
return 0; |
||||
$questionlist = $responses->questionids; |
} else { |
||||
|
return array_rand( $a); |
||||
$questions = game_sudoku_getquestions( $questionlist); |
} |
||||
$grades = game_grade_questions( $questions); |
} |
||||
|
|
||||
$scorequestion = 0; |
function game_bookquiz_check_questions( $id, $game, $attempt, $bookquiz, $context) { |
||||
$scoreattempt = 0; |
global $USER, $DB; |
||||
|
|
||||
$chapterid = required_param('chapterid', PARAM_INT); |
$scoreattempt = optional_param('scoreattempt', 0, PARAM_INT); |
||||
$nextchapterid = required_param('nextchapterid', PARAM_INT); |
$responses = data_submitted(); |
||||
|
|
||||
foreach($questions as $question) { |
$questionlist = $responses->questionids; |
||||
if( !array_key_exists( $question->id, $grades)){ |
|
||||
//no answered |
$questions = game_sudoku_getquestions( $questionlist); |
||||
continue; |
$grades = game_grade_questions( $questions); |
||||
} |
|
||||
$grade = $grades[ $question->id]; |
$scorequestion = 0; |
||||
if( $grade->grade < 0.99){ |
$scoreattempt = 0; |
||||
continue; |
|
||||
} |
$chapterid = required_param('chapterid', PARAM_INT); |
||||
|
$nextchapterid = required_param('nextchapterid', PARAM_INT); |
||||
//found one correct answer |
|
||||
if( !$DB->get_field( 'game_bookquiz_chapters', 'id', array( 'attemptid' => $attempt->id, 'chapterid' => $chapterid))) |
foreach ($questions as $question) { |
||||
{ |
if (!array_key_exists( $question->id, $grades)) { |
||||
$newrec = new stdClass(); |
// No answered. |
||||
$newrec->attemptid = $attempt->id; |
continue; |
||||
$newrec->chapterid = $chapterid; |
} |
||||
if( !$DB->insert_record( 'game_bookquiz_chapters', $newrec, false)){ |
$grade = $grades[ $question->id]; |
||||
print_object( $newrec); |
if ($grade->grade < 0.99) { |
||||
print_error( "Can't insert to table game_bookquiz_chapters"); |
continue; |
||||
} |
} |
||||
} |
|
||||
//Have to go to next page. |
// Found one correct answer. |
||||
$bookquiz->lastchapterid = $nextchapterid; |
if (!$DB->get_field( 'game_bookquiz_chapters', 'id', array( 'attemptid' => $attempt->id, 'chapterid' => $chapterid))) { |
||||
$scorequestion = 1; |
$newrec = new stdClass(); |
||||
break; |
$newrec->attemptid = $attempt->id; |
||||
} |
$newrec->chapterid = $chapterid; |
||||
|
if (!$DB->insert_record( 'game_bookquiz_chapters', $newrec, false)) { |
||||
$query = new stdClass(); |
print_error( "Can't insert to table game_bookquiz_chapters"); |
||||
$query->id = 0; |
} |
||||
$query->attemptid = $attempt->id; |
} |
||||
$query->gameid = $game->id; |
|
||||
$query->userid = $USER->id; |
// Have to go to next page. |
||||
$query->sourcemodule = 'question'; |
$bookquiz->lastchapterid = $nextchapterid; |
||||
$query->questionid = $question->id; |
$scorequestion = 1; |
||||
$query->glossaryentryid = 0; |
break; |
||||
$query->questiontext = $question->questiontext; |
} |
||||
$query->timelastattempt = time(); |
|
||||
game_update_queries( $game, $attempt, $query, $scorequestion, ''); |
$query = new stdClass(); |
||||
|
$query->id = 0; |
||||
game_updateattempts( $game, $attempt, $scoreattempt, 0); |
$query->attemptid = $attempt->id; |
||||
|
$query->gameid = $game->id; |
||||
game_bookquiz_continue( $id, $game, $attempt, $bookquiz, $bookquiz->lastchapterid, $context); |
$query->userid = $USER->id; |
||||
} |
$query->sourcemodule = 'question'; |
||||
|
$query->questionid = $question->id; |
||||
|
$query->glossaryentryid = 0; |
||||
|
$query->questiontext = $question->questiontext; |
||||
|
$query->timelastattempt = time(); |
||||
|
game_update_queries( $game, $attempt, $query, $scorequestion, ''); |
||||
|
|
||||
|
game_updateattempts( $game, $attempt, $scoreattempt, 0); |
||||
|
|
||||
|
game_bookquiz_continue( $id, $game, $attempt, $bookquiz, $bookquiz->lastchapterid, $context); |
||||
|
} |
||||
|
Loading…
Reference in new issue