Exemple #1
0
 /**
  * Prints the score obtained and maximum score available plus any penalty
  * information
  *
  * This function prints a summary of the scoring in the most recently
  * graded state (the question may not have been submitted for marking at
  * the current state). The default implementation should be suitable for most
  * question types.
  * @param object $question The question for which the grading details are
  *                         to be rendered. Question type specific information
  *                         is included. The maximum possible grade is in
  *                         ->maxgrade.
  * @param object $state    The state. In particular the grading information
  *                          is in ->grade, ->raw_grade and ->penalty.
  * @param object $cmoptions
  * @param object $options  An object describing the rendering options.
  */
 function print_question_grading_details(&$question, &$state, $cmoptions, $options)
 {
     /* The default implementation prints the number of marks if no attempt
        has been made. Otherwise it displays the grade obtained out of the
        maximum grade available and a warning if a penalty was applied for the
        attempt and displays the overall grade obtained counting all previous
        responses (and penalties) */
     if (QUESTION_EVENTDUPLICATE == $state->event) {
         echo ' ';
         print_string('duplicateresponse', 'quiz');
     }
     if ($question->maxgrade > 0 && $options->scores) {
         if (question_state_is_graded($state->last_graded)) {
             // Display the grading details from the last graded state
             $grade = new stdClass();
             $grade->cur = question_format_grade($cmoptions, $state->last_graded->grade);
             $grade->max = question_format_grade($cmoptions, $question->maxgrade);
             $grade->raw = question_format_grade($cmoptions, $state->last_graded->raw_grade);
             // let student know wether the answer was correct
             $class = question_get_feedback_class($state->last_graded->raw_grade / $question->maxgrade);
             echo '<div class="correctness ' . $class . '">' . get_string($class, 'quiz') . '</div>';
             echo '<div class="gradingdetails">';
             // print grade for this submission
             print_string('gradingdetails', 'quiz', $grade);
             if ($cmoptions->penaltyscheme) {
                 // print details of grade adjustment due to penalties
                 if ($state->last_graded->raw_grade > $state->last_graded->grade) {
                     echo ' ';
                     print_string('gradingdetailsadjustment', 'quiz', $grade);
                 }
                 // print info about new penalty
                 // penalty is relevant only if the answer is not correct and further attempts are possible
                 if ($state->last_graded->raw_grade < $question->maxgrade / 1.01 and QUESTION_EVENTCLOSEANDGRADE != $state->event) {
                     if ('' !== $state->last_graded->penalty && (double) $state->last_graded->penalty > 0.0) {
                         // A penalty was applied so display it
                         echo ' ';
                         print_string('gradingdetailspenalty', 'quiz', question_format_grade($cmoptions, $state->last_graded->penalty));
                     } else {
                         /* No penalty was applied even though the answer was
                            not correct (eg. a syntax error) so tell the student
                            that they were not penalised for the attempt */
                         echo ' ';
                         print_string('gradingdetailszeropenalty', 'quiz');
                     }
                 }
             }
             echo '</div>';
         }
     }
 }
function question_print_comment_fields($question, $state, $prefix, $cmoptions, $caption = '')
{
    global $QTYPES;
    $idprefix = preg_replace('/[^-_a-zA-Z0-9]/', '', $prefix);
    $otherquestionsinuse = '';
    if (!empty($cmoptions->questions)) {
        $otherquestionsinuse = $cmoptions->questions;
    }
    if (!question_state_is_graded($state) && $QTYPES[$question->qtype]->is_question_manual_graded($question, $otherquestionsinuse)) {
        $grade = '';
    } else {
        $grade = question_format_grade($cmoptions, $state->last_graded->grade);
    }
    $maxgrade = question_format_grade($cmoptions, $question->maxgrade);
    $fieldsize = strlen($maxgrade) - 1;
    if (empty($caption)) {
        $caption = format_string($question->name);
    }
    ?>
<fieldset class="que comment clearfix">
    <legend class="ftoggler"><?php 
    echo $caption;
    ?>
</legend>
    <div class="fcontainer clearfix">
        <div class="fitem">
            <div class="fitemtitle">
                <label for="<?php 
    echo $idprefix;
    ?>
_comment_box"><?php 
    print_string('comment', 'quiz');
    ?>
</label>
            </div>
            <div class="felement fhtmleditor">
                <?php 
    print_textarea(can_use_html_editor(), 15, 60, 630, 300, $prefix . '[comment]', $state->manualcomment, 0, false, $idprefix . '_comment_box');
    ?>
            </div>
        </div>
        <div class="fitem">
            <div class="fitemtitle">
                <label for="<?php 
    echo $idprefix;
    ?>
_grade_field"><?php 
    print_string('grade', 'quiz');
    ?>
</label>
            </div>
            <div class="felement ftext">
                <input type="text" name="<?php 
    echo $prefix;
    ?>
[grade]" size="<?php 
    echo $fieldsize;
    ?>
" id="<?php 
    echo $idprefix;
    ?>
_grade_field" value="<?php 
    echo $grade;
    ?>
" /> / <?php 
    echo $maxgrade;
    ?>
            </div>
        </div>
    </div>
</fieldset>
    <?php 
}
Exemple #3
0
 /**
  * Prints the score obtained and maximum score available plus any penalty
  * information
  *
  * This function prints a summary of the scoring in the most recently
  * graded state (the question may not have been submitted for marking at
  * the current state). The default implementation should be suitable for most
  * question types.
  * @param object $question The question for which the grading details are
  *                         to be rendered. Question type specific information
  *                         is included. The maximum possible grade is in
  *                         ->maxgrade.
  * @param object $state    The state. In particular the grading information
  *                          is in ->grade, ->raw_grade and ->penalty.
  * @param object $cmoptions
  * @param object $options  An object describing the rendering options.
  */
 function print_question_grading_details(&$question, &$state, $cmoptions, $options)
 {
     /* The default implementation prints the number of marks if no attempt
        has been made. Otherwise it displays the grade obtained out of the
        maximum grade available and a warning if a penalty was applied for the
        attempt and displays the overall grade obtained counting all previous
        responses (and penalties) */
     global $QTYPES;
     // MDL-7496 show correct answer after "Incorrect"
     $correctanswer = '';
     if ($correctanswers = $QTYPES[$question->qtype]->get_correct_responses($question, $state)) {
         if ($options->readonly && $options->correct_responses) {
             $delimiter = '';
             if ($correctanswers) {
                 foreach ($correctanswers as $ca) {
                     $correctanswer .= $delimiter . $ca;
                     $delimiter = ', ';
                 }
             }
         }
     }
     if (QUESTION_EVENTDUPLICATE == $state->event) {
         echo ' ';
         print_string('duplicateresponse', 'quiz');
     }
     if ($question->maxgrade > 0 && $options->scores) {
         if (question_state_is_graded($state->last_graded)) {
             // Display the grading details from the last graded state
             $grade = new stdClass();
             $grade->cur = question_format_grade($cmoptions, $state->last_graded->grade);
             $grade->max = question_format_grade($cmoptions, $question->maxgrade);
             $grade->raw = question_format_grade($cmoptions, $state->last_graded->raw_grade);
             // let student know wether the answer was correct
             $class = question_get_feedback_class($state->last_graded->raw_grade / $question->maxgrade);
             echo '<div class="correctness ' . $class . '">' . get_string($class, 'quiz');
             if ($correctanswer != '' && ($class == 'partiallycorrect' || $class == 'incorrect')) {
                 echo '<div class="correctness">';
                 print_string('correctansweris', 'quiz', s($correctanswer));
                 echo '</div>';
             }
             echo '</div>';
             echo '<div class="gradingdetails">';
             // print grade for this submission
             print_string('gradingdetails', 'quiz', $grade);
             // A unit penalty for numerical was applied so display it
             // a temporary solution for unit rendering in numerical
             // waiting for the new question engine code for a permanent one
             if (isset($state->options->raw_unitpenalty) && $state->options->raw_unitpenalty > 0.0) {
                 echo ' ';
                 print_string('unitappliedpenalty', 'qtype_numerical', question_format_grade($cmoptions, $state->options->raw_unitpenalty));
             }
             if ($cmoptions->penaltyscheme) {
                 // print details of grade adjustment due to penalties
                 if ($state->last_graded->raw_grade > $state->last_graded->grade) {
                     echo ' ';
                     print_string('gradingdetailsadjustment', 'quiz', $grade);
                 }
                 // print info about new penalty
                 // penalty is relevant only if the answer is not correct and further attempts are possible
                 if ($state->last_graded->raw_grade < $question->maxgrade and QUESTION_EVENTCLOSEANDGRADE != $state->event) {
                     if ('' !== $state->last_graded->penalty && (double) $state->last_graded->penalty > 0.0) {
                         echo ' ';
                         print_string('gradingdetailspenalty', 'quiz', question_format_grade($cmoptions, $state->last_graded->penalty));
                     } else {
                         /* No penalty was applied even though the answer was
                            not correct (eg. a syntax error) so tell the student
                            that they were not penalised for the attempt */
                         echo ' ';
                         print_string('gradingdetailszeropenalty', 'quiz');
                     }
                 }
             }
             echo '</div>';
         }
     }
 }