[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/grade/edit/outcome/ -> edit_form.php (source)

   1  <?php  //$Id: edit_form.php,v 1.5.2.2 2008/03/03 10:21:42 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('select', 'scaleid', get_string('scale'), $options);
  50          $mform->setHelpButton('scaleid', array('scaleid', get_string('scale'), 'grade'));
  51          $mform->addRule('scaleid', get_string('required'), 'required');
  52  
  53          $mform->addElement('htmleditor', 'description', get_string('description'), array('cols'=>80, 'rows'=>20));
  54  
  55  
  56          // hidden params
  57          $mform->addElement('hidden', 'id', 0);
  58          $mform->setType('id', PARAM_INT);
  59  
  60          $mform->addElement('hidden', 'courseid', 0);
  61          $mform->setType('courseid', PARAM_INT);
  62  
  63  /// add return tracking info
  64          $gpr = $this->_customdata['gpr'];
  65          $gpr->add_mform_elements($mform);
  66  
  67  //-------------------------------------------------------------------------------
  68          // buttons
  69          $this->add_action_buttons();
  70      }
  71  
  72  
  73  /// tweak the form - depending on existing data
  74      function definition_after_data() {
  75          global $CFG;
  76  
  77          $mform =& $this->_form;
  78  
  79          // first load proper scales
  80          if ($courseid = $mform->getElementValue('courseid')) {
  81              $options = array();
  82              if ($scales = grade_scale::fetch_all_local($courseid)) {
  83                  $options[-1] = '--'.get_string('scalescustom');
  84                  foreach($scales as $scale) {
  85                      $options[$scale->id] = $scale->get_name();
  86                  }
  87              }
  88              if ($scales = grade_scale::fetch_all_global()) {
  89                  $options[-2] = '--'.get_string('scalesstandard');
  90                  foreach($scales as $scale) {
  91                      $options[$scale->id] = $scale->get_name();
  92                  }
  93              }
  94              $scale_el =& $mform->getElement('scaleid');
  95              $scale_el->load($options);
  96  
  97          } else {
  98              $options = array();
  99              if ($scales = grade_scale::fetch_all_global()) {
 100                  foreach($scales as $scale) {
 101                      $options[$scale->id] = $scale->get_name();
 102                  }
 103              }
 104              $scale_el =& $mform->getElement('scaleid');
 105              $scale_el->load($options);
 106          }
 107  
 108          if ($id = $mform->getElementValue('id')) {
 109              $outcome = grade_outcome::fetch(array('id'=>$id));
 110              $itemcount   = $outcome->get_item_uses_count();
 111              $coursecount = $outcome->get_course_uses_count();
 112  
 113              if ($itemcount) {
 114                  $mform->hardFreeze('scaleid');
 115              }
 116  
 117              if (empty($courseid)) {
 118                  $mform->hardFreeze('standard');
 119  
 120              } else if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
 121                  $mform->hardFreeze('standard');
 122  
 123              } else if ($coursecount and empty($outcome->courseid)) {
 124                  $mform->hardFreeze('standard');
 125              }
 126  
 127  
 128          } else {
 129              if (empty($courseid) or !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
 130                  $mform->hardFreeze('standard');
 131              }
 132          }
 133      }
 134  
 135  /// perform extra validation before submission
 136      function validation($data, $files) {
 137          $errors = parent::validation($data, $files);
 138  
 139          if ($data['scaleid'] < 1) {
 140              $errors['scaleid'] = get_string('required');
 141          }
 142  
 143          if (!empty($data['standard']) and $scale = grade_scale::fetch(array('id'=>$data['scaleid']))) {
 144              if (!empty($scale->courseid)) {
 145                  //TODO: localize
 146                  $errors['scaleid'] = 'Can not use custom scale in global outcome!';
 147              }
 148          }
 149  
 150          return $errors;
 151      }
 152  
 153  
 154  }
 155  
 156  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7