Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/edit/tree/grade_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 if (!defined('MOODLE_INTERNAL')) {
00019     die('Direct access to this script is forbidden.');    
00020 }
00021 
00022 require_once $CFG->libdir.'/formslib.php';
00023 
00024 class edit_grade_form extends moodleform {
00025 
00026     function definition() {
00027         global $CFG, $COURSE, $DB;
00028 
00029         $mform =& $this->_form;
00030 
00031         $grade_item = $this->_customdata['grade_item'];
00032         $gpr        = $this->_customdata['gpr'];
00033 
00034         if ($grade_item->is_course_item()) {
00035             $grade_category = null;
00036         } else if ($grade_item->is_category_item()) {
00037             $grade_category = $grade_item->get_item_category();
00038             $grade_category = $grade_category->get_parent_category();
00039         } else {
00040             $grade_category = $grade_item->get_parent_category();
00041         }
00042 
00044         $mform->addElement('static', 'user', get_string('user'));
00045         $mform->addElement('static', 'itemname', get_string('itemname', 'grades'));
00046 
00047         $mform->addElement('checkbox', 'overridden', get_string('overridden', 'grades'));
00048         $mform->addHelpButton('overridden', 'overridden', 'grades');
00049 
00051         if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
00052             // numeric grade
00053             $mform->addElement('text', 'finalgrade', get_string('finalgrade', 'grades'));
00054             $mform->addHelpButton('finalgrade', 'finalgrade', 'grades');
00055             $mform->disabledIf('finalgrade', 'overridden', 'notchecked');
00056 
00057         } else if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
00058             // scale grade
00059             $scaleopt = array();
00060 
00061             if (empty($grade_item->outcomeid)) {
00062                 $scaleopt[-1] = get_string('nograde');
00063             } else {
00064                 $scaleopt[-1] = get_string('nooutcome', 'grades');
00065             }
00066 
00067             $i = 1;
00068             if ($scale = $DB->get_record('scale', array('id' => $grade_item->scaleid))) {
00069                 foreach (explode(",", $scale->scale) as $option) {
00070                     $scaleopt[$i] = $option;
00071                     $i++;
00072                 }
00073             }
00074 
00075             $mform->addElement('select', 'finalgrade', get_string('finalgrade', 'grades'), $scaleopt);
00076             $mform->addHelpButton('finalgrade', 'finalgrade', 'finalgrade');
00077             $mform->disabledIf('finalgrade', 'overridden', 'notchecked');
00078         }
00079 
00080         if ($grade_category and $grade_category->aggregation == GRADE_AGGREGATE_SUM) {
00081             $mform->addElement('advcheckbox', 'excluded', get_string('excluded', 'grades'), '<small>('.get_string('warningexcludedsum', 'grades').')</small>');
00082         } else {
00083             $mform->addElement('advcheckbox', 'excluded', get_string('excluded', 'grades'));
00084         }
00085         $mform->addHelpButton('excluded', 'excluded', 'grades');
00086 
00089         $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
00090         $mform->addHelpButton('hidden', 'hidden', 'grades');
00091         $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
00092         $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked');
00093 
00095         $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
00096         $mform->addHelpButton('locked', 'locked', 'grades');
00097         $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true));
00098         $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
00099 
00100         // Feedback format is automatically converted to html if user has enabled editor
00101         $feedbackoptions = array('maxfiles'=>0, 'maxbytes'=>0); //TODO: no files here for now, if ever gets implemented use component 'grade' and filearea 'feedback'
00102         $mform->addElement('editor', 'feedback', get_string('feedback', 'grades'), null, $feedbackoptions);
00103         $mform->addHelpButton('feedback', 'feedback', 'grades');
00104         $mform->setType('text', PARAM_RAW); // to be cleaned before display, no XSS risk
00105 
00106         // hidden params
00107         $mform->addElement('hidden', 'oldgrade');
00108         $mform->setType('oldgrade', PARAM_RAW);
00109         $mform->addElement('hidden', 'oldfeedback');
00110         $mform->setType('oldfeedback', PARAM_RAW);
00111 
00112         $mform->addElement('hidden', 'id', 0);
00113         $mform->setType('id', PARAM_INT);
00114 
00115         $mform->addElement('hidden', 'itemid', 0);
00116         $mform->setType('itemid', PARAM_INT);
00117 
00118         $mform->addElement('hidden', 'userid', 0);
00119         $mform->setType('userid', PARAM_INT);
00120 
00121         $mform->addElement('hidden', 'courseid', $COURSE->id);
00122         $mform->setType('courseid', PARAM_INT);
00123 
00125         $gpr->add_mform_elements($mform);
00126 
00127 //-------------------------------------------------------------------------------
00128         // buttons
00129         $this->add_action_buttons();
00130     }
00131 
00132     function definition_after_data() {
00133         global $CFG, $COURSE, $DB;
00134 
00135         $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
00136 
00137         $mform =& $this->_form;
00138         $grade_item = $this->_customdata['grade_item'];
00139 
00140         // fill in user name if user still exists
00141         $userid = $mform->getElementValue('userid');
00142         if ($user = $DB->get_record('user', array('id' => $userid))) {
00143             $username = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'">'.fullname($user).'</a>';
00144             $user_el =& $mform->getElement('user');
00145             $user_el->setValue($username);
00146         }
00147 
00148         // add activity name + link
00149         if ($grade_item->itemtype == 'mod') {
00150             $cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
00151             $itemname = '<a href="'.$CFG->wwwroot.'/mod/'.$grade_item->itemmodule.'/view.php?id='.$cm->id.'">'.$grade_item->get_name().'</a>';
00152         } else {
00153             $itemname = $grade_item->get_name();
00154         }
00155         $itemname_el =& $mform->getElement('itemname');
00156         $itemname_el->setValue($itemname);
00157 
00158         // access control - disable not allowed elements
00159         if (!has_capability('moodle/grade:manage', $context)) {
00160             $mform->hardFreeze('excluded');
00161         }
00162 
00163         if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:hide', $context)) {
00164             $mform->hardFreeze('hidden');
00165             $mform->hardFreeze('hiddenuntil');
00166         }
00167 
00168         $old_grade_grade = new grade_grade(array('itemid'=>$grade_item->id, 'userid'=>$userid));
00169 
00170         if (!$grade_item->is_overridable_item()) {
00171             $mform->removeElement('overridden');
00172         }
00173 
00174         if ($grade_item->is_hidden()) {
00175             $mform->hardFreeze('hidden');
00176         }
00177 
00178         if ($old_grade_grade->is_locked()) {
00179             if ($grade_item->is_locked()) {
00180                 $mform->hardFreeze('locked');
00181                 $mform->hardFreeze('locktime');
00182             }
00183 
00184             $mform->hardFreeze('overridden');
00185             $mform->hardFreeze('finalgrade');
00186             $mform->hardFreeze('feedback');
00187 
00188         } else {
00189             if (empty($old_grade_grade->id)) {
00190                 $old_grade_grade->locked = $grade_item->locked;
00191                 $old_grade_grade->locktime = $grade_item->locktime;
00192             }
00193 
00194             if (($old_grade_grade->locked or $old_grade_grade->locktime)
00195               and (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:unlock', $context))) {
00196                 $mform->hardFreeze('locked');
00197                 $mform->hardFreeze('locktime');
00198 
00199             } else if ((!$old_grade_grade->locked and !$old_grade_grade->locktime)
00200               and (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:lock', $context))) {
00201                 $mform->hardFreeze('locked');
00202                 $mform->hardFreeze('locktime');
00203             }
00204         }
00205     }
00206 }
00207 
00208 
 All Data Structures Namespaces Files Functions Variables Enumerations