[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/grade/edit/tree/ -> item.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Edit the grade options for an individual grade item
  19   *
  20   * @package   core_grades
  21   * @copyright 2007 Petr Skoda
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  require_once '../../../config.php';
  27  require_once $CFG->dirroot.'/grade/lib.php';
  28  require_once $CFG->dirroot.'/grade/report/lib.php';
  29  require_once  'item_form.php';
  30  
  31  $courseid = required_param('courseid', PARAM_INT);
  32  $id       = optional_param('id', 0, PARAM_INT);
  33  
  34  $url = new moodle_url('/grade/edit/tree/item.php', array('courseid'=>$courseid));
  35  if ($id !== 0) {
  36      $url->param('id', $id);
  37  }
  38  $PAGE->set_url($url);
  39  $PAGE->set_pagelayout('admin');
  40  navigation_node::override_active_url(new moodle_url('/grade/edit/tree/index.php',
  41      array('id'=>$courseid)));
  42  
  43  if (!$course = $DB->get_record('course', array('id' => $courseid))) {
  44      print_error('nocourseid');
  45  }
  46  
  47  require_login($course);
  48  $context = context_course::instance($course->id);
  49  require_capability('moodle/grade:manage', $context);
  50  
  51  // default return url
  52  $gpr = new grade_plugin_return();
  53  $returnurl = $gpr->get_return_url('index.php?id='.$course->id);
  54  
  55  $heading = get_string('itemsedit', 'grades');
  56  
  57  if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
  58      // redirect if outcomeid present
  59      if (!empty($grade_item->outcomeid) && !empty($CFG->enableoutcomes)) {
  60          $url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?id='.$id.'&amp;courseid='.$courseid;
  61          redirect($gpr->add_url_params($url));
  62      }
  63      if ($grade_item->is_course_item() or $grade_item->is_category_item()) {
  64          $grade_category = $grade_item->get_item_category();
  65          $url = $CFG->wwwroot.'/grade/edit/tree/category.php?id='.$grade_category->id.'&amp;courseid='.$courseid;
  66          redirect($gpr->add_url_params($url));
  67      }
  68  
  69      $item = $grade_item->get_record_data();
  70      $parent_category = $grade_item->get_parent_category();
  71      $item->parentcategory = $parent_category->id;
  72  
  73  } else {
  74      $heading = get_string('newitem', 'grades');
  75      $grade_item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'), false);
  76      $item = $grade_item->get_record_data();
  77      $parent_category = grade_category::fetch_course_category($courseid);
  78      $item->parentcategory = $parent_category->id;
  79  }
  80  $decimalpoints = $grade_item->get_decimals();
  81  
  82  if ($item->hidden > 1) {
  83      $item->hiddenuntil = $item->hidden;
  84      $item->hidden = 0;
  85  } else {
  86      $item->hiddenuntil = 0;
  87  }
  88  
  89  $item->locked = !empty($item->locked);
  90  
  91  $item->grademax        = format_float($item->grademax, $decimalpoints);
  92  $item->grademin        = format_float($item->grademin, $decimalpoints);
  93  $item->gradepass       = format_float($item->gradepass, $decimalpoints);
  94  $item->multfactor      = format_float($item->multfactor, 4);
  95  $item->plusfactor      = format_float($item->plusfactor, 4);
  96  
  97  if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
  98      $item->aggregationcoef = $item->aggregationcoef == 0 ? 0 : 1;
  99  } else {
 100      $item->aggregationcoef = format_float($item->aggregationcoef, 4);
 101  }
 102  if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
 103      $item->aggregationcoef2 = format_float($item->aggregationcoef2 * 100.0);
 104  }
 105  $item->cancontrolvisibility = $grade_item->can_control_visibility();
 106  
 107  $mform = new edit_item_form(null, array('current'=>$item, 'gpr'=>$gpr));
 108  
 109  if ($mform->is_cancelled()) {
 110      redirect($returnurl);
 111  
 112  } else if ($data = $mform->get_data(false)) {
 113      // If unset, give the aggregationcoef a default based on parent aggregation method
 114      if (!isset($data->aggregationcoef) || $data->aggregationcoef == '') {
 115          if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
 116              $data->aggregationcoef = 1;
 117          } else {
 118              $data->aggregationcoef = 0;
 119          }
 120      }
 121  
 122      if (!isset($data->gradepass) || $data->gradepass == '') {
 123          $data->gradepass = 0;
 124      }
 125  
 126      if (!isset($data->grademin) || $data->grademin == '') {
 127          $data->grademin = 0;
 128      }
 129  
 130      $hidden      = empty($data->hidden) ? 0: $data->hidden;
 131      $hiddenuntil = empty($data->hiddenuntil) ? 0: $data->hiddenuntil;
 132      unset($data->hidden);
 133      unset($data->hiddenuntil);
 134  
 135      $locked   = empty($data->locked) ? 0: $data->locked;
 136      $locktime = empty($data->locktime) ? 0: $data->locktime;
 137      unset($data->locked);
 138      unset($data->locktime);
 139  
 140      $convert = array('grademax', 'grademin', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef', 'aggregationcoef2');
 141      foreach ($convert as $param) {
 142          if (property_exists($data, $param)) {
 143              $data->$param = unformat_float($data->$param);
 144          }
 145      }
 146      if (isset($data->aggregationcoef2) && $parent_category->aggregation == GRADE_AGGREGATE_SUM) {
 147          $data->aggregationcoef2 = $data->aggregationcoef2 / 100.0;
 148      }
 149  
 150      $grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
 151      grade_item::set_properties($grade_item, $data);
 152      $grade_item->outcomeid = null;
 153  
 154      // Handle null decimals value
 155      if (!property_exists($data, 'decimals') or $data->decimals < 0) {
 156          $grade_item->decimals = null;
 157      }
 158  
 159      if (empty($grade_item->id)) {
 160          $grade_item->itemtype = 'manual'; // all new items to be manual only
 161          $grade_item->insert();
 162  
 163          // set parent if needed
 164          if (isset($data->parentcategory)) {
 165              $grade_item->set_parent($data->parentcategory, 'gradebook');
 166          }
 167  
 168      } else {
 169          $grade_item->update();
 170      }
 171  
 172      // update hiding flag
 173      if ($hiddenuntil) {
 174          $grade_item->set_hidden($hiddenuntil, false);
 175      } else {
 176          $grade_item->set_hidden($hidden, false);
 177      }
 178  
 179      $grade_item->set_locktime($locktime); // locktime first - it might be removed when unlocking
 180      $grade_item->set_locked($locked, false, true);
 181  
 182      redirect($returnurl);
 183  }
 184  
 185  $PAGE->navbar->add($heading);
 186  print_grade_page_head($courseid, 'settings', null, $heading, false, false, false);
 187  
 188  $mform->display();
 189  
 190  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1