navbar->add(get_string('showanswers', 'game')); $action = optional_param('action', "", PARAM_ALPHANUM); // action if( $action == 'delstats') $DB->delete_records('game_repetitions', array('gameid' => $game->id, 'userid' => $USER->id)); if( $action == 'computestats') game_compute_repetitions($game); echo ''.get_string('repetitions', 'game').':   '; echo get_string('user').': '; game_showusers($game); echo "  wwwroot}/mod/game/showanswers.php?q=$q&action=delstats\">".get_string('clearrepetitions','game').''; echo "   wwwroot}/mod/game/showanswers.php?q=$q&action=computestats\">".get_string('computerepetitions','game').''; echo '

'; $existsbook = ($DB->get_record( 'modules', array( 'name' => 'book'), 'id,id')); game_showanswers( $game, $existsbook, $context); echo $OUTPUT->footer(); function game_compute_repetitions($game){ global $DB, $USER; $DB->delete_records('game_repetitions', array('gameid' => $game->id,'userid' => $USER->id)); $sql = "INSERT INTO {game_repetitions}( gameid,userid,questionid,glossaryentryid,repetitions) ". "SELECT $game->id,$USER->id,questionid,glossaryentryid,COUNT(*) ". "FROM {game_queries} WHERE gameid=$game->id AND userid=$USER->id GROUP BY questionid,glossaryentryid"; if( !$DB->execute( $sql)) print_error('Problem on computing statistics for repetitions'); } function game_showusers($game) { global $CFG, $USER; $users = array(); $context = game_get_context_course_instance( $game->course); if ($courseusers = get_enrolled_users($context)) { foreach ($courseusers as $courseuser) { $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context)); } } if ($guest = guest_user()) { $users[$guest->id] = fullname($guest); } ?> id,PARAM_INT); $output = '' . "\n"; } function game_showanswers( $game, $existsbook, $context) { if( $game->gamekind == 'bookquiz' and $existsbook){ game_showanswers_bookquiz( $game, $context); return; } switch( $game->sourcemodule){ case 'question': game_showanswers_question( $game, $context); break; case 'glossary': game_showanswers_glossary( $game); break; case 'quiz': game_showanswers_quiz( $game, $context); break; } } function game_showanswers_appendselect( $game) { switch( $game->gamekind){ case 'hangman': case 'cross': case 'crypto': return " AND qtype='shortanswer'"; case 'millionaire': return " AND qtype = 'multichoice'"; case 'sudoku': case 'bookquiz': case 'snakes': return " AND qtype in ('shortanswer', 'truefalse', 'multichoice')"; } return ''; } function game_showanswers_question( $game, $context) { global $DB; if( $game->gamekind != 'bookquiz'){ $select = ' category='.$game->questioncategoryid; if( $game->subcategories){ $cats = question_categorylist( $game->questioncategoryid); if( strpos( $cats, ',') > 0){ $select = ' category in ('.$cats.')'; } } }else { $context2 = get_context_instance(50, $COURSE->id); $select = " contextid in ($context2->id)"; $select2 = ''; if( $recs = $DB->get_records_select( 'question_categories', $select, null, 'id,id')){ foreach( $recs as $rec){ $select2 .= ','.$rec->id; } } $select = ' AND category IN ('.substr( $select2, 1).')'; } $select .= ' AND hidden = 0 '; $select .= game_showanswers_appendselect( $game); $showcategories = ($game->gamekind == 'bookquiz'); $order = ($showcategories ? 'category,questiontext' : 'questiontext'); game_showanswers_question_select( $game, '{question} q', $select, '*', $order, $showcategories, $game->course, $context); } function game_showanswers_quiz( $game, $context) { global $CFG; $select = "quiz='$game->quizid' ". ' AND qqi.question=q.id'. ' AND q.hidden=0'. game_showanswers_appendselect( $game); $table = '{question} q,{quiz_question_instances} qqi'; game_showanswers_question_select( $game, $table, $select, 'q.*', 'category,questiontext', false, $game->course, $context); } function game_showanswers_question_select( $game, $table, $select, $fields, $order, $showcategoryname, $courseid, $context) { global $CFG, $DB, $OUTPUT; $sql = "SELECT $fields FROM $table WHERE $select ORDER BY $order"; if( ($questions = $DB->get_records_sql( $sql)) === false){ return; } $table .= ",{game_repetitions} gr"; $select .= " AND gr.questionid=q.id AND gr.glossaryentryid=0 AND gr.gameid=".$game->id; $userid = optional_param('userid',0,PARAM_INT); if( $userid) $select .= " AND gr.userid=$userid"; $sql = "SELECT q.id as id,SUM(repetitions) as c FROM {$table} WHERE $select GROUP BY q.id"; $reps = $DB->get_records_sql( $sql); $categorynames = array(); if( $showcategoryname){ $select = ''; $recs = $DB->get_records( 'question_categories', null, '', '*', 0, 1); foreach( $recs as $rec){ if( array_key_exists( 'course', $rec)){ $select = "course=$courseid"; }else{ $context = get_context_instance(50, $courseid); $select = " contextid in ($context->id)"; } break; } if( ($categories = $DB->get_records_select( 'question_categories', $select, null, '', 'id,name'))){ foreach( $categories as $rec){ $categorynames[ $rec->id] = $rec->name; } } } echo ''; echo ''; if( $showcategoryname){ echo ''; } echo ''; echo ''; echo ''; if( $reps) echo ''; echo "\r\n"; $line = 0; foreach( $questions as $question){ echo ''; echo ''; if( $showcategoryname){ echo ''; } echo '"; if( $rec->feedback == '') $rec->feedback = ' '; echo ""; break; case 'multichoice': case 'truefalse': $recs = $DB->get_records( 'question_answers', array( 'question' => $question->id)); $feedback = ''; echo ''; if( $feedback == '') $feedback = ' '; echo ""; break; default: echo ""; break; } //Show repetitions if( $reps){ if( array_key_exists( $question->id, $reps)){ $rep = $reps[ $question->id]; echo ''; }else echo ''; } echo "\r\n"; } echo "
'.get_string( 'categories', 'quiz').''.get_string( 'questions', 'quiz').''.get_string( 'answers', 'quiz').''.get_string( 'feedbacks', 'game').''.get_string( 'repetitions', 'game').'
'.(++$line); echo ''; if( array_key_exists( $question->category, $categorynames)){ echo $categorynames[ $question->category]; }else{ echo ' '; } echo ''; echo "wwwroot}/question/question.php?inpopup=1&id=$question->id&courseid=$courseid\" target=\"_blank\">pix_url('t/edit')."\" alt=\"Edit\" /> "; echo game_filterquestion(str_replace( array( "\'", '\"'), array( "'", '"'), $question->questiontext), $question->id, $context->id, $game->course); switch( $question->qtype){ case 'shortanswer': $recs = $DB->get_records( 'question_answers', array( 'question' => $question->id), 'fraction DESC', 'id,answer,feedback'); if( $recs == false){ $rec = false; }else{ foreach( $recs as $rec) break; } echo "$rec->answer$rec->feedback'; $i = 0; foreach( $recs as $rec){ if( $i++ > 0) echo '
'; if( $rec->fraction == 1){ echo " $rec->answer"; if( $rec->feedback == '') $feedback .= '
'; else $feedback .= "$rec->feedback
"; }else { echo " $rec->answer"; if( $rec->feedback == '') $feedback .= '
'; else $feedback .= "
"; } } echo '
$feedback$question->qtype
'.$rep->c.'
 

\r\n\r\n"; } function game_showanswers_glossary( $game) { global $CFG, $DB; $table = '{glossary_entries} ge'; $select = "glossaryid={$game->glossaryid}"; if( $game->glossarycategoryid){ $select .= " AND gec.entryid = ge.id ". " AND gec.categoryid = {$game->glossarycategoryid}"; $table .= ",{glossary_entries_categories} gec"; } $sql = "SELECT ge.id,definition,concept FROM $table WHERE $select ORDER BY definition"; if( ($questions = $DB->get_records_sql( $sql)) === false){ return; } //Show repetiotions of questions $table = "{glossary_entries} ge, {game_repetitions} gr"; $select = "glossaryid={$game->glossaryid} AND gr.glossaryentryid=ge.id AND gr.gameid=".$game->id; $userid = optional_param('userid',0,PARAM_INT); if( $userid) $select .= " AND gr.userid=$userid"; if( $game->glossarycategoryid){ $select .= " AND gec.entryid = ge.id ". " AND gec.categoryid = {$game->glossarycategoryid}"; $table .= ",{glossary_entries_categories} gec"; } $sql = "SELECT ge.id,SUM(repetitions) as c FROM {$table} WHERE $select GROUP BY ge.id"; $reps = $DB->get_records_sql( $sql); echo ''; echo ''; echo ''; echo ''; if( $reps != false) echo ''; echo "\r\n"; $line = 0; foreach( $questions as $question){ if( $game->param7 == 0){ //Not allowed spaces if(!( strpos( $question->concept, ' ') === false)) continue; } if( $game->param8 == 0){ //Not allowed - if(!( strpos( $question->concept, '-') === false)) continue; } echo ''; echo ''; $query = new StdClass; $query->glossaryid = $game->glossaryid; $query->glossaryentryid = $question->id; echo ''; echo ''; if( $reps != false){ if( array_key_exists( $question->id, $reps)) { $rep = $reps[ $question->id]; echo ''; }else echo ''; } echo "\r\n"; } echo "
'.get_string( 'questions', 'quiz').''.get_string( 'answers', 'quiz').''.get_string( 'repetitions', 'game').'
'.(++$line); echo ''.game_show_query( $game, $query, $question->definition).''.$question->concept.'
'.$rep->c.'
 

\r\n\r\n"; } function game_showanswers_bookquiz( $game, $context) { global $CFG; $select = "gbq.questioncategoryid=q.category ". " AND gbq.gameid = $game->id ". " AND bc.id = gbq.chapterid"; $table = "{question} q,{game_bookquiz_questions} gbq,{book_chapters} bc"; $showcategories = ($game->gamekind == 'bookquiz'); game_showanswers_question_select( $game, $table, $select, "DISTINCT q.*", "bc.pagenum,questiontext", $showcategories, $game->course, $context); }