File: editquestion.php

package info (click to toggle)
moodle 1.6.3-2
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 37,052 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; perl: 638; sh: 441; makefile: 48; pascal: 36
file content (93 lines) | stat: -rw-r--r-- 3,668 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php // $Id: editquestion.php,v 1.1 2006/03/24 19:31:46 gustav_delius Exp $

// Get a handle to the question type we are dealing with here
$qtypeobj = $QTYPES['calculated'];

if (empty($form)) {
/****************************************************************/
/***** First page in question wizard - editquestion.html.html! **/
/****************************************************************/
// Inside this block everything works as for non-wizardquestions

    // The layout of the editing page will only support
    // one formula alternative for calculated questions.
    // However, the code behind supports up to six formulas
    // and the database store and attempt/review framework
    // does not have any limit.
    $answers= array();
    for ($i=0; $i<6; $i++) {
        // Make answer slots with default values
        $answers[$i]->answer              = "";
        $answers[$i]->feedback            = "";
        $answers[$i]->fraction            = "1.0";
        $answers[$i]->tolerance           = "0.01";
        $answers[$i]->tolerancetype       = "1";
        $answers[$i]->correctanswerlength = "2"; // Defaults to two ...
        $answers[$i]->correctanswerformat = "1"; // ... decimals
    }

    if (!empty($question->id)) {
        $QTYPES[$question->qtype]->get_question_options($question);
        if (!empty($question->options->answers)) {
            // Overwrite the default valued answer slots
            // with correct values from database
            $answersraw = array_values($question->options->answers);
            $n = count($answersraw);
            for ($i = 0; $i < $n; $i++) {
                $answers[$i] = $answersraw[$i];
            }
        }
    }

    // Units are handled the same way
    // as for numerical questions
    $units = array();
    for ($i=0 ; $i<6 ; $i++) {
        // Make unit slots, default as blank...
        $units[$i]->multiplier = '';
        $units[$i]->unit = '';
    }
    if (!empty($question->id) and $unitsraw = get_records(
            'question_numerical_units', 'question', $question->id)) {
        /// Find default unit and have it put in the zero slot
        /// This procedure might be overridden later when
        /// the unit is stripped form an answer...
        foreach ($unitsraw as $key => $unit) {
            if (1.0 == $unit->multiplier) {
                /// Default unit found:
                $units[0] = $unit;
                unset($unitsraw[$key]);
                break;
            }
        }
        /// Fill remaining answer slots with whatsever left
        if (!empty($unitsraw)) {
            $i = 1; // The zero slot got the default unit...
            foreach ($unitsraw as $unit) {
                $units[$i] = $unit;
                $i++;
            }
        }
    } else {
        $units[0]->multiplier = 1.0;
    }

    // Strip trailing zeros from multipliers
    foreach ($units as $i => $unit) {
        if (ereg('^(.*\\..(.*[^0])?)0+$', $unit->multiplier, $regs1)) {
            if (ereg('^(.+)\\.0$', $regs1[1], $regs2)) {
                $units[$i]->multiplier = $regs2[1];
            } else {
                $units[$i]->multiplier = $regs1[1];
            }
        }
    }
    print_heading_with_help(get_string("editingcalculated", "quiz"), "calculated", "quiz");
    require("$CFG->dirroot/question/type/calculated/editquestion.html");
} else { // $form is not empty
    /*********************************************************/
    /*****    Any subsequent page of the question wizard    **/
    /*********************************************************/
    $qtypeobj->print_next_wizard_page($question, $form, $course);
}
?>