Beispiel #1
0
 /**
  * @dataProvider quiz_attempt_state_data_provider
  *
  * @param unknown $attemptstate as in the quiz_attempts.state DB column.
  * @param unknown $relativetimefinish time relative to now when the attempt finished, or null for 0.
  * @param unknown $relativetimeclose time relative to now when the quiz closes, or null for 0.
  * @param unknown $expectedstate expected result. One of the mod_quiz_display_options constants/
  */
 public function test_quiz_attempt_state($attemptstate, $relativetimefinish, $relativetimeclose, $expectedstate)
 {
     $attempt = new stdClass();
     $attempt->state = $attemptstate;
     if ($relativetimefinish === null) {
         $attempt->timefinish = 0;
     } else {
         $attempt->timefinish = time() + $relativetimefinish;
     }
     $quiz = new stdClass();
     if ($relativetimeclose === null) {
         $quiz->timeclose = 0;
     } else {
         $quiz->timeclose = time() + $relativetimeclose;
     }
     $this->assertEquals($expectedstate, quiz_attempt_state($quiz, $attempt));
 }
Beispiel #2
0
 /**
  * @return int one of the mod_quiz_display_options::DURING,
  *      IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants.
  */
 public function get_attempt_state()
 {
     return quiz_attempt_state($this->get_quiz(), $this->attempt);
 }
Beispiel #3
0
    /**
     * Make some text into a link to review the quiz, if that is appropriate.
     *
     * @param string $linktext some text.
     * @param object $attempt the attempt object
     * @return string some HTML, the $linktext either unmodified or wrapped in a
     *      link to the review page.
     */
    public function make_review_link($attempt, $reviewoptions, $output) {

        // If the attempt is still open, don't link.
        if (in_array($attempt->state, array(quiz_attempt::IN_PROGRESS, quiz_attempt::OVERDUE))) {
            return $output->no_review_message('');
        }

        $when = quiz_attempt_state($this->quizobj->get_quiz(), $attempt);
        $reviewoptions = mod_quiz_display_options::make_from_quiz(
                $this->quizobj->get_quiz(), $when);

        if (!$reviewoptions->attempt) {
            return $output->no_review_message($this->quizobj->cannot_review_message($when, true));

        } else {
            return $output->review_link($this->quizobj->review_url($attempt->id),
                    $this->attempt_must_be_in_popup(), $this->get_popup_options());
        }
    }
Beispiel #4
0
/**
 * Combines the review options from a number of different quiz attempts.
 * Returns an array of two ojects, so the suggested way of calling this
 * funciton is:
 * list($someoptions, $alloptions) = quiz_get_combined_reviewoptions(...)
 *
 * @param object $quiz the quiz instance.
 * @param array $attempts an array of attempt objects.
 * @param $context the roles and permissions context,
 *          normally the context for the quiz 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 quiz_get_combined_reviewoptions($quiz, $attempts) {
    $fields = array('feedback', 'generalfeedback', 'rightanswer', 'overallfeedback');
    $someoptions = new stdClass();
    $alloptions = new stdClass();
    foreach ($fields as $field) {
        $someoptions->$field = false;
        $alloptions->$field = true;
    }
    $someoptions->marks = question_display_options::HIDDEN;
    $alloptions->marks = question_display_options::MARK_AND_MAX;

    foreach ($attempts as $attempt) {
        $attemptoptions = mod_quiz_display_options::make_from_quiz($quiz,
                quiz_attempt_state($quiz, $attempt));
        foreach ($fields as $field) {
            $someoptions->$field = $someoptions->$field || $attemptoptions->$field;
            $alloptions->$field = $alloptions->$field && $attemptoptions->$field;
        }
        $someoptions->marks = max($someoptions->marks, $attemptoptions->marks);
        $alloptions->marks = min($alloptions->marks, $attemptoptions->marks);
    }
    return array($someoptions, $alloptions);
}
Beispiel #5
0
 /**
  * Make some text into a link to review the quiz, if that is appropriate.
  *
  * @param string $linktext some text.
  * @param object $attempt the attempt object
  * @return string some HTML, the $linktext either unmodified or wrapped in a
  *      link to the review page.
  */
 public function make_review_link($attempt, $canpreview, $reviewoptions)
 {
     global $CFG;
     // If review of responses is not allowed, or the attempt is still open, don't link.
     if (!$attempt->timefinish) {
         return '';
     }
     $when = quiz_attempt_state($this->_readerobj->get_reader(), $attempt);
     $reviewoptions = mod_reader_display_options::make_from_quiz($this->_readerobj->get_reader(), $when);
     if (!$reviewoptions->attempt) {
         $message = $this->cannot_review_message($when, true);
         if ($message) {
             return '<span class="noreviewmessage">' . $message . '</span>';
         } else {
             return '';
         }
     }
     $linktext = get_string('review', 'quiz');
     // It is OK to link, does it need to be in a secure window?
     if ($this->securewindow_required($canpreview)) {
         return $this->_securewindowrule->make_review_link($linktext, $attempt->id);
     } else {
         return '<a href="' . $this->_readerobj->review_url($attempt->id) . '" title="' . get_string('reviewthisattempt', 'quiz') . '">' . $linktext . '</a>';
     }
 }
Beispiel #6
0
/**
 * Combines the review options from a number of different quiz attempts.
 * Returns an array of two ojects, so the suggested way of calling this
 * funciton is:
 * list($someoptions, $alloptions) = quiz_get_combined_reviewoptions(...)
 *
 * @param object $quiz the quiz instance.
 * @param array $attempts an array of attempt objects.
 *
 * @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 quiz_get_combined_reviewoptions($quiz, $attempts)
{
    $fields = array('feedback', 'generalfeedback', 'rightanswer', 'overallfeedback');
    $someoptions = new stdClass();
    $alloptions = new stdClass();
    foreach ($fields as $field) {
        $someoptions->{$field} = false;
        $alloptions->{$field} = true;
    }
    $someoptions->marks = question_display_options::HIDDEN;
    $alloptions->marks = question_display_options::MARK_AND_MAX;
    // This shouldn't happen, but we need to prevent reveal information.
    if (empty($attempts)) {
        return array($someoptions, $someoptions);
    }
    foreach ($attempts as $attempt) {
        $attemptoptions = mod_quiz_display_options::make_from_quiz($quiz, quiz_attempt_state($quiz, $attempt));
        foreach ($fields as $field) {
            $someoptions->{$field} = $someoptions->{$field} || $attemptoptions->{$field};
            $alloptions->{$field} = $alloptions->{$field} && $attemptoptions->{$field};
        }
        $someoptions->marks = max($someoptions->marks, $attemptoptions->marks);
        $alloptions->marks = min($alloptions->marks, $attemptoptions->marks);
    }
    return array($someoptions, $alloptions);
}
Beispiel #7
0
 public function test_quiz_attempt_state_never_sumitted_quiz_closed()
 {
     $attempt = new stdClass();
     $attempt->state = quiz_attempt::ABANDONED;
     $attempt->timefinish = time() - 7200;
     $quiz = new stdClass();
     $quiz->timeclose = time() - 3600;
     $this->assertEquals(mod_quiz_display_options::AFTER_CLOSE, quiz_attempt_state($quiz, $attempt));
 }
Beispiel #8
0
    /**
     * Make some text into a link to review the quiz, if that is appropriate.
     *
     * @param string $linktext some text.
     * @param object $attempt the attempt object
     * @return string some HTML, the $linktext either unmodified or wrapped in a
     *      link to the review page.
     */
    public function make_review_link($attempt, $reviewoptions, $output) {

        // If review of responses is not allowed, or the attempt is still open, don't link.
        if (!$attempt->timefinish) {
            return $output->no_review_message('');
        }

        $when = quiz_attempt_state($this->quizobj->get_quiz(), $attempt);
        $reviewoptions = mod_quiz_display_options::make_from_quiz(
                $this->quizobj->get_quiz(), $when);

        if (!$reviewoptions->attempt) {
            return $output->no_review_message($this->quizobj->cannot_review_message($when, true));

        } else {
            return $output->review_link($this->quizobj->review_url($attempt->id),
                    $this->attempt_must_be_in_popup(), $this->get_popup_options());
        }
    }