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

« back to all changes in this revision

Viewing changes to grade/edit/outcome/edit_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:
 
1
<?php  //$Id: edit_form.php,v 1.5.2.3 2008/10/22 09:09:32 nicolasconnault Exp $
 
2
 
 
3
///////////////////////////////////////////////////////////////////////////
 
4
//                                                                       //
 
5
// NOTICE OF COPYRIGHT                                                   //
 
6
//                                                                       //
 
7
// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
 
8
//          http://moodle.com                                            //
 
9
//                                                                       //
 
10
// Copyright (C) 1999 onwards  Martin Dougiamas  http://moodle.com       //
 
11
//                                                                       //
 
12
// This program is free software; you can redistribute it and/or modify  //
 
13
// it under the terms of the GNU General Public License as published by  //
 
14
// the Free Software Foundation; either version 2 of the License, or     //
 
15
// (at your option) any later version.                                   //
 
16
//                                                                       //
 
17
// This program is distributed in the hope that it will be useful,       //
 
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
 
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
 
20
// GNU General Public License for more details:                          //
 
21
//                                                                       //
 
22
//          http://www.gnu.org/copyleft/gpl.html                         //
 
23
//                                                                       //
 
24
///////////////////////////////////////////////////////////////////////////
 
25
 
 
26
require_once $CFG->libdir.'/formslib.php';
 
27
 
 
28
class edit_outcome_form extends moodleform {
 
29
    function definition() {
 
30
        global $CFG, $COURSE;
 
31
        $mform =& $this->_form;
 
32
 
 
33
        // visible elements
 
34
        $mform->addElement('header', 'general', get_string('outcomes', 'grades'));
 
35
 
 
36
        $mform->addElement('text', 'fullname', get_string('fullname'), 'size="40"');
 
37
        $mform->addRule('fullname', get_string('required'), 'required');
 
38
        $mform->setType('fullname', PARAM_TEXT);
 
39
 
 
40
        $mform->addElement('text', 'shortname', get_string('shortname'), 'size="20"');
 
41
        $mform->addRule('shortname', get_string('required'), 'required');
 
42
        $mform->setType('shortname', PARAM_NOTAGS);
 
43
 
 
44
        $mform->addElement('advcheckbox', 'standard', get_string('outcomestandard', 'grades'));
 
45
        $mform->setHelpButton('standard', array('outcomestandard', get_string('outcomestandard'), 'grade'));
 
46
 
 
47
        $options = array();
 
48
 
 
49
        $mform->addElement('selectwithlink', 'scaleid', get_string('scale'), $options, null,
 
50
            array('link' => $CFG->wwwroot.'/grade/edit/scale/edit.php?courseid='.$COURSE->id, 'label' => get_string('scalescustomcreate')));
 
51
        $mform->setHelpButton('scaleid', array('scaleid', get_string('scale'), 'grade'));
 
52
        $mform->addRule('scaleid', get_string('required'), 'required');
 
53
 
 
54
        $mform->addElement('htmleditor', 'description', get_string('description'), array('cols'=>80, 'rows'=>20));
 
55
 
 
56
 
 
57
        // hidden params
 
58
        $mform->addElement('hidden', 'id', 0);
 
59
        $mform->setType('id', PARAM_INT);
 
60
 
 
61
        $mform->addElement('hidden', 'courseid', 0);
 
62
        $mform->setType('courseid', PARAM_INT);
 
63
 
 
64
/// add return tracking info
 
65
        $gpr = $this->_customdata['gpr'];
 
66
        $gpr->add_mform_elements($mform);
 
67
 
 
68
//-------------------------------------------------------------------------------
 
69
        // buttons
 
70
        $this->add_action_buttons();
 
71
    }
 
72
 
 
73
 
 
74
/// tweak the form - depending on existing data
 
75
    function definition_after_data() {
 
76
        global $CFG;
 
77
 
 
78
        $mform =& $this->_form;
 
79
 
 
80
        // first load proper scales
 
81
        if ($courseid = $mform->getElementValue('courseid')) {
 
82
            $options = array();
 
83
            if ($scales = grade_scale::fetch_all_local($courseid)) {
 
84
                $options[-1] = '--'.get_string('scalescustom');
 
85
                foreach($scales as $scale) {
 
86
                    $options[$scale->id] = $scale->get_name();
 
87
                }
 
88
            }
 
89
            if ($scales = grade_scale::fetch_all_global()) {
 
90
                $options[-2] = '--'.get_string('scalesstandard');
 
91
                foreach($scales as $scale) {
 
92
                    $options[$scale->id] = $scale->get_name();
 
93
                }
 
94
            }
 
95
            $scale_el =& $mform->getElement('scaleid');
 
96
            $scale_el->load($options);
 
97
 
 
98
        } else {
 
99
            $options = array();
 
100
            if ($scales = grade_scale::fetch_all_global()) {
 
101
                foreach($scales as $scale) {
 
102
                    $options[$scale->id] = $scale->get_name();
 
103
                }
 
104
            }
 
105
            $scale_el =& $mform->getElement('scaleid');
 
106
            $scale_el->load($options);
 
107
        }
 
108
 
 
109
        if ($id = $mform->getElementValue('id')) {
 
110
            $outcome = grade_outcome::fetch(array('id'=>$id));
 
111
            $itemcount   = $outcome->get_item_uses_count();
 
112
            $coursecount = $outcome->get_course_uses_count();
 
113
 
 
114
            if ($itemcount) {
 
115
                $mform->hardFreeze('scaleid');
 
116
            }
 
117
 
 
118
            if (empty($courseid)) {
 
119
                $mform->hardFreeze('standard');
 
120
 
 
121
            } else if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
 
122
                $mform->hardFreeze('standard');
 
123
 
 
124
            } else if ($coursecount and empty($outcome->courseid)) {
 
125
                $mform->hardFreeze('standard');
 
126
            }
 
127
 
 
128
 
 
129
        } else {
 
130
            if (empty($courseid) or !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
 
131
                $mform->hardFreeze('standard');
 
132
            }
 
133
        }
 
134
    }
 
135
 
 
136
/// perform extra validation before submission
 
137
    function validation($data, $files) {
 
138
        $errors = parent::validation($data, $files);
 
139
 
 
140
        if ($data['scaleid'] < 1) {
 
141
            $errors['scaleid'] = get_string('required');
 
142
        }
 
143
 
 
144
        if (!empty($data['standard']) and $scale = grade_scale::fetch(array('id'=>$data['scaleid']))) {
 
145
            if (!empty($scale->courseid)) {
 
146
                //TODO: localize
 
147
                $errors['scaleid'] = 'Can not use custom scale in global outcome!';
 
148
            }
 
149
        }
 
150
 
 
151
        return $errors;
 
152
    }
 
153
 
 
154
 
 
155
}
 
156
 
 
157
?>