Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/edit/tree/item.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 require_once '../../../config.php';
00019 require_once $CFG->dirroot.'/grade/lib.php';
00020 require_once $CFG->dirroot.'/grade/report/lib.php';
00021 require_once 'item_form.php';
00022 
00023 $courseid = required_param('courseid', PARAM_INT);
00024 $id       = optional_param('id', 0, PARAM_INT);
00025 
00026 $url = new moodle_url('/grade/edit/tree/item.php', array('courseid'=>$courseid));
00027 if ($id !== 0) {
00028     $url->param('id', $id);
00029 }
00030 $PAGE->set_url($url);
00031 $PAGE->set_pagelayout('admin');
00032 
00033 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
00034     print_error('nocourseid');
00035 }
00036 
00037 require_login($course);
00038 $context = get_context_instance(CONTEXT_COURSE, $course->id);
00039 require_capability('moodle/grade:manage', $context);
00040 
00041 // default return url
00042 $gpr = new grade_plugin_return();
00043 $returnurl = $gpr->get_return_url('index.php?id='.$course->id);
00044 
00045 $heading = get_string('itemsedit', 'grades');
00046 
00047 if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
00048     // redirect if outcomeid present
00049     if (!empty($grade_item->outcomeid) && !empty($CFG->enableoutcomes)) {
00050         $url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?id='.$id.'&amp;courseid='.$courseid;
00051         redirect($gpr->add_url_params($url));
00052     }
00053     if ($grade_item->is_course_item() or $grade_item->is_category_item()) {
00054         $grade_category = $grade_item->get_item_category();
00055         $url = $CFG->wwwroot.'/grade/edit/tree/category.php?id='.$grade_category->id.'&amp;courseid='.$courseid;
00056         redirect($gpr->add_url_params($url));
00057     }
00058 
00059     $item = $grade_item->get_record_data();
00060     $parent_category = $grade_item->get_parent_category();
00061     $item->parentcategory = $parent_category->id;
00062 
00063 } else {
00064     $heading = get_string('newitem', 'grades');
00065     $grade_item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'), false);
00066     $item = $grade_item->get_record_data();
00067     $parent_category = grade_category::fetch_course_category($courseid);
00068     $item->parentcategory = $parent_category->id;
00069 }
00070 $decimalpoints = $grade_item->get_decimals();
00071 
00072 if ($item->hidden > 1) {
00073     $item->hiddenuntil = $item->hidden;
00074     $item->hidden = 0;
00075 } else {
00076     $item->hiddenuntil = 0;
00077 }
00078 
00079 $item->locked = !empty($item->locked);
00080 
00081 $item->grademax        = format_float($item->grademax, $decimalpoints);
00082 $item->grademin        = format_float($item->grademin, $decimalpoints);
00083 $item->gradepass       = format_float($item->gradepass, $decimalpoints);
00084 $item->multfactor      = format_float($item->multfactor, 4);
00085 $item->plusfactor      = format_float($item->plusfactor, 4);
00086 
00087 if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
00088     $item->aggregationcoef = $item->aggregationcoef == 0 ? 0 : 1;
00089 } else {
00090     $item->aggregationcoef = format_float($item->aggregationcoef, 4);
00091 }
00092 
00093 $mform = new edit_item_form(null, array('current'=>$item, 'gpr'=>$gpr));
00094 
00095 if ($mform->is_cancelled()) {
00096     redirect($returnurl);
00097 
00098 } else if ($data = $mform->get_data(false)) {
00099     // If unset, give the aggregationcoef a default based on parent aggregation method
00100     if (!isset($data->aggregationcoef) || $data->aggregationcoef == '') {
00101         if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
00102             $data->aggregationcoef = 1;
00103         } else {
00104             $data->aggregationcoef = 0;
00105         }
00106     }
00107 
00108     if (!isset($data->gradepass) || $data->gradepass == '') {
00109         $data->gradepass = 0;
00110     }
00111 
00112     if (!isset($data->grademin) || $data->grademin == '') {
00113         $data->grademin = 0;
00114     }
00115 
00116     $hidden      = empty($data->hidden) ? 0: $data->hidden;
00117     $hiddenuntil = empty($data->hiddenuntil) ? 0: $data->hiddenuntil;
00118     unset($data->hidden);
00119     unset($data->hiddenuntil);
00120 
00121     $locked   = empty($data->locked) ? 0: $data->locked;
00122     $locktime = empty($data->locktime) ? 0: $data->locktime;
00123     unset($data->locked);
00124     unset($data->locktime);
00125 
00126     $convert = array('grademax', 'grademin', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef');
00127     foreach ($convert as $param) {
00128         if (property_exists($data, $param)) {
00129             $data->$param = unformat_float($data->$param);
00130         }
00131     }
00132 
00133     $grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
00134     grade_item::set_properties($grade_item, $data);
00135     $grade_item->outcomeid = null;
00136 
00137     // Handle null decimals value
00138     if (!property_exists($data, 'decimals') or $data->decimals < 0) {
00139         $grade_item->decimals = null;
00140     }
00141 
00142     if (empty($grade_item->id)) {
00143         $grade_item->itemtype = 'manual'; // all new items to be manual only
00144         $grade_item->insert();
00145 
00146         // set parent if needed
00147         if (isset($data->parentcategory)) {
00148             $grade_item->set_parent($data->parentcategory, 'gradebook');
00149         }
00150 
00151     } else {
00152         $grade_item->update();
00153     }
00154 
00155     // update hiding flag
00156     if ($hiddenuntil) {
00157         $grade_item->set_hidden($hiddenuntil, false);
00158     } else {
00159         $grade_item->set_hidden($hidden, false);
00160     }
00161 
00162     $grade_item->set_locktime($locktime); // locktime first - it might be removed when unlocking
00163     $grade_item->set_locked($locked, false, true);
00164 
00165     redirect($returnurl);
00166 }
00167 
00168 $return = false;
00169 $buttons = false;
00170 $shownavigation = false;
00171 print_grade_page_head($courseid, 'edittree', null, $heading, $return, $buttons, $shownavigation);
00172 
00173 $mform->display();
00174 
00175 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations