navbar->add(get_string('showattempts', 'game'));
$action = optional_param('action', "", PARAM_ALPHANUM); // action
if( $action == 'delete'){
game_ondeleteattempt( $game);
}
echo get_string( 'group').': ';
game_showgroups( $game);
echo ' '.get_string('user').': ';
game_showusers( $game);echo '
';
game_showattempts( $game);
echo $OUTPUT->footer();
function game_showusers($game)
{
global $CFG, $USER, $DB;
$users = array();
$context = get_context_instance(CONTEXT_COURSE, $game->course);
$groupid = optional_param('groupid',0, PARAM_INT);
$sql = "SELECT DISTINCT ra.userid,u.lastname,u.firstname FROM {role_assignments} ra, {user} u ".
" WHERE ra.contextid={$context->id} AND ra.userid=u.id";
if( $groupid != 0)
$sql .= " AND ra.userid IN (SELECT gm.userid FROM {groups_members} gm WHERE gm.groupid=$groupid)";
if( ($recs = $DB->get_records_sql( $sql))){
foreach( $recs as $rec){
$users[ $rec->userid] = $rec->lastname.' '.$rec->firstname;
}
}
if ($guest = guest_user()) {
$users[$guest->id] = fullname($guest);
}
?>
' . "\n";
$output .= ' ' . "\n";
}
}
}
echo $output . '' . "\n";
}
function game_showgroups($game)
{
global $CFG, $USER, $DB;
$groups = array();
if( ($recs = $DB->get_records_sql( "SELECT id,name FROM {groups} WHERE courseid=$game->course ORDER BY name"))){
foreach( $recs as $rec){
$groups[ $rec->id] = $rec->name;
}
}
?>
' . "\n";
$output .= ' ' . "\n";
}
}
}
echo $output . '' . "\n";
}
function game_showattempts($game){
global $CFG, $DB, $OUTPUT;
$allowdelete = optional_param('allowdelete', 0, PARAM_INT);
$userid = optional_param('userid',0,PARAM_INT);
$limitfrom = optional_param('limitfrom', 0, PARAM_INT);
$gamekind = $game->gamekind;
$update = get_coursemodule_from_instance( 'game', $game->id, $game->course)->id;
//Here are user attempts
$table = "{game_attempts} as ga, {user} u, {game} as g";
$select = "ga.userid=u.id AND ga.gameid={$game->id} AND g.id={$game->id}";
$fields = "ga.id, u.lastname, u.firstname, ga.attempts,".
"timestart, timefinish, timelastattempt, score, ga.lastip, ga.lastremotehost";
if( $userid != 0)
$select .= ' AND u.id='.$userid;
$sql = "SELECT COUNT(*) AS c FROM $table WHERE $select";
$count = $DB->count_records_sql( $sql);
$maxlines = 20;
$recslimitfrom = $recslimitnum = '';
if( $count > $maxlines){
$recslimitfrom = ( $limitfrom ? $limitfrom * $maxlines : '');
$recslimitnum = $maxlines;
for($i=0; $i*$maxlines < $count; $i++){
if( $i == $limitfrom){
echo ($i+1).' ';
}else
{
echo "wwwroot}/mod/game/preview.php?action=showattempts&update=$update&q={$game->id}&limitfrom=$i&\">".($i+1)."";
echo ' ';
}
}
echo "
";
}
$sql = "SELECT $fields FROM $table WHERE $select ORDER BY timelastattempt DESC,timestart DESC";
if( ($recs = $DB->get_records_sql( $sql, null, $recslimitfrom, $recslimitnum)) != false){
echo '
'.get_string( 'delete').' | '.get_string('user').' | '; echo ''.get_string('lastip', 'game').' | '; echo ''.get_string('timestart', 'game').' | '; echo ''.get_string('timelastattempt', 'game').' | '; echo ''.get_string('timefinish', 'game').' | '; echo ''.get_string('score', 'game').' | '; echo ''.get_string('attempts', 'game').' | '; echo ''.get_string('preview', 'game').' | '; echo ''.get_string('showsolution', 'game').' | '; echo "