[ Index ]

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

title

Body

[close]

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

   1  <?php  //$Id: category.php,v 1.4.2.6 2008/02/27 12:45:11 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 '../../../config.php';
  27  require_once $CFG->dirroot.'/grade/lib.php';
  28  require_once $CFG->dirroot.'/grade/report/lib.php';
  29  require_once  'category_form.php';
  30  
  31  $courseid = required_param('courseid', PARAM_INT);
  32  $id       = optional_param('id', 0, PARAM_INT);
  33  
  34  if (!$course = get_record('course', 'id', $courseid)) {
  35      print_error('nocourseid');
  36  }
  37  
  38  require_login($course);
  39  $context = get_context_instance(CONTEXT_COURSE, $course->id);
  40  require_capability('moodle/grade:manage', $context);
  41  
  42  // default return url
  43  $gpr = new grade_plugin_return();
  44  $returnurl = $gpr->get_return_url('index.php?id='.$course->id);
  45  
  46  
  47  $mform = new edit_category_form(null, array('gpr'=>$gpr));
  48  
  49  if ($id) {
  50      if (!$grade_category = grade_category::fetch(array('id'=>$id, 'courseid'=>$course->id))) {
  51          error('Incorrect category id!');
  52      }
  53      $grade_category->apply_forced_settings();
  54      $category = $grade_category->get_record_data();
  55      // Get Category preferences
  56      $category->pref_aggregationview = grade_report::get_pref('aggregationview', $id);
  57      // Load agg coef
  58      $grade_item = $grade_category->load_grade_item();
  59      $category->aggregationcoef = format_float($grade_item->aggregationcoef, 4);
  60      // set parent
  61      $category->parentcategory = $grade_category->parent;
  62  
  63  } else {
  64      $grade_category = new grade_category(array('courseid'=>$courseid), false);
  65      $grade_category->apply_default_settings();
  66      $grade_category->apply_forced_settings();
  67  
  68      $category = $grade_category->get_record_data();
  69      $category->aggregationcoef = format_float(0, 4);
  70  }
  71  
  72  $mform->set_data($category);
  73  
  74  if ($mform->is_cancelled()) {
  75      redirect($returnurl);
  76  
  77  } else if ($data = $mform->get_data(false)) {
  78      // If no fullname is entered for a course category, put ? in the DB
  79      if (!isset($data->fullname) || $data->fullname == '') {
  80          $data->fullname = '?';
  81      }
  82  
  83      if (!isset($data->aggregateonlygraded)) {
  84          $data->aggregateonlygraded = 0;
  85      }
  86      if (!isset($data->aggregateoutcomes)) {
  87          $data->aggregateoutcomes = 0;
  88      }
  89      grade_category::set_properties($grade_category, $data);
  90  
  91      if (empty($grade_category->id)) {
  92          $grade_category->insert();
  93  
  94      } else {
  95          $grade_category->update();
  96      }
  97  
  98      // Handle user preferences
  99      if (isset($data->pref_aggregationview)) {
 100          if (!grade_report::set_pref('aggregationview', $data->pref_aggregationview, $grade_category->id)) {
 101              error("Could not set preference aggregationview to $value for this grade category");
 102          }
 103      }
 104  
 105      // set parent if needed
 106      if (isset($data->parentcategory)) {
 107          $grade_category->set_parent($data->parentcategory, 'gradebook');
 108      }
 109  
 110      // update agg coef if needed
 111      if (isset($data->aggregationcoef)) {
 112          $data->aggregationcoef = unformat_float($data->aggregationcoef);
 113          $grade_item = $grade_category->load_grade_item();
 114          $grade_item->aggregationcoef = $data->aggregationcoef;
 115          $grade_item->update();
 116      }
 117  
 118      redirect($returnurl);
 119  }
 120  
 121  
 122  $strgrades         = get_string('grades');
 123  $strgraderreport   = get_string('graderreport', 'grades');
 124  $strcategoriesedit = get_string('categoryedit', 'grades');
 125  $strcategory       = get_string('category', 'grades');
 126  
 127  $navigation = grade_build_nav(__FILE__, $strcategory, array('courseid' => $courseid));
 128  
 129  print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
 130  
 131  $mform->display();
 132  
 133  print_footer($course);
 134  die;


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