function game_view_capability_attempt($game, $context, $course, $available, $cm)
{
    global $CFG, $USER;
    $unfinished = false;
    // Get this user's attempts.
    if ($USER->username == 'guest') {
        $attempts = array();
        $mygrade = array();
    } else {
        $attempts = game_get_user_attempts($game->id, $USER->id);
        if ($unfinishedattempt = game_get_user_attempt_unfinished($game->id, $USER->id)) {
            $attempts[] = $unfinishedattempt;
            $unfinished = true;
        }
        $mygrade = game_get_best_grade($game, $USER->id);
    }
    $numattempts = count($attempts);
    // Get some strings.
    $strattempt = get_string("attempt", "game");
    $strtimetaken = get_string("timetaken", "game");
    $strtimecompleted = get_string("timecompleted", "game");
    $strgrade = get_string("grade");
    $strmarks = get_string('marks', 'game');
    $strfeedback = get_string('feedback', 'game');
    // Print table with existing attempts
    if ($attempts) {
        // Work out which columns we need, taking account what data is available in each attempt.
        list($someoptions, $alloptions) = game_get_combined_reviewoptions($game, $attempts, $context);
        $gradecolumn = $someoptions->scores && $game->grade;
        //$markcolumn = $gradecolumn && ($game->grade != $game->grade);
        $overallstats = $alloptions->scores;
        $feedbackcolumn = game_has_feedback($game->id);
        $overallfeedback = $feedbackcolumn && $alloptions->overallfeedback;
        // prepare table header
        $table->head = array($strattempt, $strtimecompleted);
        $table->align = array("center", "left");
        $table->size = array("", "");
        /*			
                    if ( $markcolumn) {
                        $table->head[] = "$strmarks / $game->grade";
                        $table->align[] = 'right';
                        $table->size[] = '';
                    }
        */
        if ($gradecolumn) {
            $table->head[] = "{$strgrade} / {$game->grade}";
            $table->align[] = 'center';
            $table->size[] = '';
        }
        if ($feedbackcolumn) {
            $table->head[] = $strfeedback;
            $table->align[] = 'left';
            $table->size[] = '';
        }
        if (isset($game->showtimetaken)) {
            $table->head[] = $strtimetaken;
            $table->align[] = 'center';
            $table->size[] = '';
        }
        // One row for each attempt
        foreach ($attempts as $attempt) {
            $attemptoptions = game_get_reviewoptions($game, $attempt, $context);
            $row = array();
            // Add the attempt number, making it a link, if appropriate.
            $row[] = make_review_link('#' . $attempt->attempt, $game, $attempt);
            // prepare strings for time taken and date completed
            $timetaken = '';
            $datecompleted = '';
            if ($attempt->timefinish > 0) {
                // attempt has finished
                $timetaken = format_time($attempt->timefinish - $attempt->timestart);
                $datecompleted = userdate($attempt->timefinish);
            } else {
                if ($available) {
                    // The attempt is still in progress.
                    $timetaken = format_time(time() - $attempt->timestart);
                    $datecompleted = '';
                } else {
                    if ($game->timeclose) {
                        // The attempt was not completed but is also not available any more becuase the game is closed.
                        $timetaken = format_time($game->timeclose - $attempt->timestart);
                        $datecompleted = userdate($game->timeclose);
                    } else {
                        // Something wheird happened.
                        $timetaken = '';
                        $datecompleted = '';
                    }
                }
            }
            $row[] = $datecompleted;
            // Ouside the if because we may be showing feedback but not grades.
            $attemptgrade = game_score_to_grade($attempt->score, $game);
            /*
                            if ($markcolumn) {
                                if ($attemptoptions->scores) {
                                    $row[] = make_review_link(round($attempt->score * $game->grade, $game->decimalpoints), $game, $attempt);
                                } else {
                                    $row[] = '';
                                }
                            }
            */
            if ($gradecolumn) {
                if ($attemptoptions->scores) {
                    // highlight the highest grade if appropriate
                    if ($overallstats && !is_null($mygrade) && $attemptgrade == $mygrade && $game->grademethod == GAME_GRADEMETHOD_HIGHEST) {
                        $formattedgrade = "<span class='highlight'>{$attemptgrade}</span>";
                    } else {
                        $formattedgrade = $attemptgrade;
                    }
                    $row[] = make_review_link($formattedgrade, $game, $attempt);
                } else {
                    $row[] = '';
                }
            }
            if ($feedbackcolumn) {
                if ($attemptoptions->overallfeedback) {
                    $row[] = game_feedback_for_grade($attemptgrade, $game->id);
                } else {
                    $row[] = '';
                }
            }
            if (isset($game->showtimetaken)) {
                $row[] = $timetaken;
            }
            $table->data[] = $row;
        }
        // End of loop over attempts.
        print_table($table);
    }
    // Print information about the student's best score for this game if possible.
    $moreattempts = $unfinished || $numattempts < $game->attempts || $game->attempts == 0;
    if (!$moreattempts) {
        print_heading(get_string("nomoreattempts", "game"));
    }
    if ($numattempts && !is_null($mygrade)) {
        if ($overallstats) {
            if ($available && $moreattempts) {
                $GAME_GRADE_METHOD = array(GAME_GRADEMETHOD_HIGHEST => get_string("gradehighest", "game"), GAME_GRADEMETHOD_AVERAGE => get_string("gradeaverage", "game"), GAME_GRADEMETHOD_FIRST => get_string("attemptfirst", "game"), GAME_GRADEMETHOD_LAST => get_string("attemptlast", "game"));
                $a = new stdClass();
                $a->method = $GAME_GRADE_METHOD[$game->grademethod];
                $a->mygrade = $mygrade;
                $a->gamegrade = $game->grade;
                print_heading(get_string('gradesofar', 'game', $a));
            } else {
                print_heading(get_string('yourfinalgradeis', 'game', "{$mygrade} / {$game->grade}"));
            }
        }
        if ($overallfeedback) {
            echo '<p class="gamegradefeedback">' . game_feedback_for_grade($mygrade, $game->id) . '</p>';
        }
    }
    // Print a button to start/continue an attempt, if appropriate.
    //if (!$game->questions) {
    //   print_heading( get_string("noquestions", "game"));
    //} else
    if ($available && $moreattempts) {
        game_view_capability_attempt_showinfo($game, $course, $cm, $unfinished, $numattempts);
    } else {
        print_continue($CFG->wwwroot . '/course/view.php?id=' . $course->id);
    }
}
Beispiel #2
0
     $table->size[] = '';
 }
 $table->head[] = get_string('timecompleted', 'game');
 $table->align[] = 'left';
 $table->size[] = '';
 if ($gradecolumn) {
     $table->head[] = get_string('grade') . ' / ' . game_format_grade($game, $game->grade);
     $table->align[] = 'center';
     $table->size[] = '';
 }
 $table->head[] = get_string('timetaken', 'game');
 $table->align[] = 'left';
 $table->size[] = '';
 // One row for each attempt
 foreach ($attempts as $attempt) {
     $attemptoptions = game_get_reviewoptions($game, $attempt, $context);
     $row = array();
     // Add the attempt number, making it a link, if appropriate.
     if ($attemptcolumn) {
         if ($attempt->preview) {
             $row[] = get_string('preview', 'game');
         } else {
             $row[] = $attempt->attempt;
         }
     }
     // prepare strings for time taken and date completed
     $timetaken = '';
     $datecompleted = '';
     if ($attempt->timefinish > 0) {
         // attempt has finished
         $timetaken = format_time($attempt->timefinish - $attempt->timestart);
Beispiel #3
0
/**
 * Combines the review options from a number of different game attempts.
 * Returns an array of two ojects, so he suggested way of calling this
 * funciton is:
 * list($someoptions, $alloptions) = game_get_combined_reviewoptions(...)
 *
 * @param object $game the game instance.
 * @param array $attempts an array of attempt objects.
 * @param $context the roles and permissions context,
 *          normally the context for the game module instance.
 *
 * @return array of two options objects, one showing which options are true for
 *          at least one of the attempts, the other showing which options are true
 *          for all attempts.
 */
function game_get_combined_reviewoptions($game, $attempts, $context = null)
{
    $fields = array('readonly', 'scores', 'feedback', 'correct_responses', 'solutions', 'generalfeedback', 'overallfeedback');
    $someoptions = new stdClass();
    $alloptions = new stdClass();
    foreach ($fields as $field) {
        $someoptions->{$field} = false;
        $alloptions->{$field} = true;
    }
    foreach ($attempts as $attempt) {
        $attemptoptions = game_get_reviewoptions($game, $attempt, $context);
        foreach ($fields as $field) {
            $someoptions->{$field} = $someoptions->{$field} || $attemptoptions->{$field};
            $alloptions->{$field} = $alloptions->{$field} && $attemptoptions->{$field};
        }
    }
    return array($someoptions, $alloptions);
}