~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to question/type/shortanswer/edit_shortanswer_form.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * @copyright © 2007 Jamie Pratt
6
6
 * @author Jamie Pratt me@jamiep.org
7
7
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8
 
 * @package questions
 
8
 * @package questionbank
 
9
 * @subpackage questiontypes
9
10
 */
10
11
 
11
12
/**
28
29
        $gradeoptions = $creategrades->gradeoptions;
29
30
        $repeated = array();
30
31
        $repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerno', 'qtype_shortanswer', '{no}'));
31
 
        $repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz'));
 
32
        $repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz'), array('size' => 54));
32
33
        $repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions);
33
 
        $repeated[] =& $mform->createElement('htmleditor', 'feedback', get_string('feedback', 'quiz'));
 
34
        $repeated[] =& $mform->createElement('htmleditor', 'feedback', get_string('feedback', 'quiz'),
 
35
                                array('course' => $this->coursefilesid));
34
36
 
35
37
        if (isset($this->question->options)){
36
38
            $countanswers = count($this->question->options->answers);
37
39
        } else {
38
40
            $countanswers = 0;
39
41
        }
40
 
        $repeatsatstart = (QUESTION_NUMANS_START > ($countanswers + QUESTION_NUMANS_ADD))?
41
 
                            QUESTION_NUMANS_START : ($countanswers + QUESTION_NUMANS_ADD);
 
42
        if ($this->question->formoptions->repeatelements){
 
43
            $repeatsatstart = (QUESTION_NUMANS_START > ($countanswers + QUESTION_NUMANS_ADD))?
 
44
                                QUESTION_NUMANS_START : ($countanswers + QUESTION_NUMANS_ADD);
 
45
        } else {
 
46
            $repeatsatstart = $countanswers;
 
47
        }
42
48
        $repeatedoptions = array();
43
49
        $mform->setType('answer', PARAM_RAW);
44
50
        $repeatedoptions['fraction']['default'] = 0;
63
69
        }
64
70
        parent::set_data($question);
65
71
    }
66
 
    function validation($data){
67
 
        $errors = array();
 
72
    function validation($data, $files) {
 
73
        $errors = parent::validation($data, $files);
68
74
        $answers = $data['answer'];
69
75
        $answercount = 0;
70
76
        $maxgrade = false;
71
77
        foreach ($answers as $key => $answer) {
72
78
            $trimmedanswer = trim($answer);
73
 
            if (!empty($trimmedanswer)){
 
79
            if ($trimmedanswer !== ''){
74
80
                $answercount++;
75
81
                if ($data['fraction'][$key] == 1) {
76
82
                    $maxgrade = true;
77
83
                }
 
84
            } else if ($data['fraction'][$key] != 0 || !html_is_blank($data['feedback'][$key])) {
 
85
                $errors["answer[$key]"] = get_string('answermustbegiven', 'qtype_shortanswer');
 
86
                $answercount++;
78
87
            }
79
88
        }
80
89
        if ($answercount==0){