MDL-12140 category can be selected when adding new items or categories; merged from MOODLE_19_STABLE

This commit is contained in:
skodak
2007-11-15 08:29:12 +00:00
parent ba1393b43f
commit e2eb2edbad
5 changed files with 185 additions and 106 deletions

View File

@@ -54,16 +54,19 @@ if ($id) {
$category = $grade_category->get_record_data();
// Get Category preferences
$category->pref_aggregationview = grade_report::get_pref('aggregationview', $id);
//GVA Patch
// Load agg coef
$grade_item = $grade_category->load_grade_item();
$category->aggregationcoef = $grade_item->aggregationcoef;
//End Patch
$category->aggregationcoef = format_float($grade_item->aggregationcoef, 4);
// set parent
$category->parentcategory = $grade_category->parent;
} else {
$grade_category = new grade_category();
$grade_category->courseid = $course->id;
$grade_category = new grade_category(array('courseid'=>$courseid), false);
$grade_category->apply_default_settings();
$grade_category->apply_forced_settings();
$category = $grade_category->get_record_data();
$category->aggregationcoef = format_float(0, 4);
}
$mform->set_data($category);
@@ -93,25 +96,20 @@ if ($mform->is_cancelled()) {
error("Could not set preference aggregationview to $value for this grade category");
}
}
//GVA Patch
if (isset($data->weightcourse)) {
global $COURSE;
$course_category = grade_category::fetch_course_category($COURSE->id);
$course_category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN;
$course_category->update();
// set parent if needed
if (isset($data->parentcategory)) {
$grade_category->set_parent($data->parentcategory, 'gradebook');
}
if (!isset($grade_item)) {
// update agg coef if needed
if (isset($data->aggregationcoef)) {
$data->aggregationcoef = unformat_float($data->aggregationcoef);
$grade_item = $grade_category->load_grade_item();
}
if (isset($data->aggregationcoef)){
$data_item->aggregationcoef = $data->aggregationcoef;
grade_item::set_properties($grade_item, $data_item);
$grade_item->aggregationcoef = $data->aggregationcoef;
$grade_item->update();
}
//End Patch
redirect($returnurl);
}

View File

@@ -28,7 +28,7 @@ require_once $CFG->libdir.'/formslib.php';
class edit_category_form extends moodleform {
function definition() {
global $CFG;
global $CFG, $COURSE;
$mform =& $this->_form;
$options = array(GRADE_AGGREGATE_MEAN =>get_string('aggregatemean', 'grades'),
@@ -41,7 +41,7 @@ class edit_category_form extends moodleform {
GRADE_AGGREGATE_SUM =>get_string('aggregatesum', 'grades'));
// visible elements
$mform->addElement('header', 'gradecat', get_string('gradecategory', 'grades'));
$mform->addElement('header', 'headercategory', get_string('gradecategory', 'grades'));
$mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
$mform->addRule('fullname', null, 'required', null, 'client');
@@ -51,14 +51,6 @@ class edit_category_form extends moodleform {
$mform->setAdvanced('aggregation');
}
//GVA Patch
$mform->addElement('checkbox', 'weightcourse', 'Weight grades for course'); //To Do Localize
$mform->addElement('text', 'aggregationcoef', get_string('aggregationcoefweight', 'grades'));
$mform->setHelpButton('aggregationcoef', array(false, get_string('aggregationcoefweight', 'grades'),
false, true, false, get_string('aggregationcoefweighthelp', 'grades')));
$mform->disabledIf('aggregationcoef', 'weightcourse', 'notchecked');
//End Patch
$mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
$mform->setHelpButton('aggregateonlygraded', array(false, get_string('aggregateonlygraded', 'grades'),
false, true, false, get_string('aggregateonlygradedhelp', 'grades')));
@@ -110,8 +102,46 @@ class edit_category_form extends moodleform {
$mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
$mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
// user preferences
$mform->addElement('header', 'userpref', get_string('myreportpreferences', 'grades'));
/// parent category related settings
$mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
$options = array();
$default = '';
$coefstring = '';
$categories = grade_category::fetch_all(array('courseid'=>$COURSE->id));
foreach ($categories as $cat) {
$cat->apply_forced_settings();
$options[$cat->id] = $cat->get_name();
if ($cat->is_course_category()) {
$default = $cat->id;
}
if ($cat->is_aggregationcoef_used()) {
if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef';
} else if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';
} else {
$coefstring = 'aggregationcoef';
}
} else {
$mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $cat->id);
}
}
if (count($categories) > 1) {
$mform->addElement('select', 'parentcategory', get_string('parentcategory', 'grades'), $options);
}
if ($coefstring !== '') {
$mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
$mform->setHelpButton('aggregationcoef', array(false, get_string($coefstring, 'grades'),
false, true, false, get_string($coefstring.'help', 'grades')));
$mform->setAdvanced('aggregationcoef');
}
/// user preferences
$mform->addElement('header', 'headerpreferences', get_string('myreportpreferences', 'grades'));
$options = array(GRADE_REPORT_PREFERENCE_DEFAULT => get_string('default', 'grades'),
GRADE_REPORT_AGGREGATION_VIEW_FULL => get_string('fullmode', 'grades'),
GRADE_REPORT_AGGREGATION_VIEW_AGGREGATES_ONLY => get_string('aggregatesonly', 'grades'),
@@ -171,52 +201,50 @@ class edit_category_form extends moodleform {
$mform->removeElement('droplow');
}
}
//GVA Patch
if (!$id = $mform->getElementValue('id')) {
$mform->setDefault('aggregateonlygraded',1);
$parent_category = grade_category::fetch_course_category($COURSE->id);
if ($parent_category->is_aggregationcoef_used()) {
if ($mform->elementExists('weightcourse')) {
$mform->removeElement('weightcourse');
}
}
}
//End Patch
if ($id = $mform->getElementValue('id')) {
$grade_category = grade_category::fetch(array('id'=>$id));
$grade_item = $grade_category->load_grade_item();
//GVA Patch
$category = $grade_item->get_item_category();
if(!$category->aggregateonlygraded) {
$mform->setAdvanced('aggregateonlygraded', false);
}
if ($grade_item->is_course_item()) { //An actual course, not a category, etc.
// remove agg coef if not used
if ($grade_category->is_course_category()) {
if ($mform->elementExists('parentcategory')) {
$mform->removeElement('parentcategory');
}
if ($mform->elementExists('aggregationcoef')) {
$mform->removeElement('aggregationcoef');
}
if ($mform->elementExists('weightcourse')) {
$mform->removeElement('weightcourse');
}
}
if (!$grade_item->is_category_item()) {
if ($mform->elementExists('weightcourse')) {
$mform->removeElement('weightcourse');
}
} else {
$category = $grade_item->get_item_category();
$parent_category = $category->get_parent_category();
if ($parent_category->is_aggregationcoef_used()) {
if ($mform->elementExists('weightcourse')) {
$mform->removeElement('weightcourse');
// if we wanted to change parent of existing category - we would have to verify there are no circular references in parents!!!
if ($mform->elementExists('parentcategory')) {
$mform->hardFreeze('parentcategory');
}
$parent_category = $grade_category->get_parent_category();
$parent_category->apply_forced_settings();
if (!$parent_category->is_aggregationcoef_used()) {
if ($mform->elementExists('aggregationcoef')) {
$mform->removeElement('aggregationcoef');
}
} else {
//fix label if needed
$agg_el =& $mform->getElement('aggregationcoef');
$aggcoef = '';
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$aggcoef = 'aggregationcoefweight';
} else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$aggcoef = 'aggregationcoefextra';
}
if ($aggcoef !== '') {
$agg_el->setLabel(get_string($aggcoef, 'grades'));
$mform->setHelpButton('aggregationcoef', array(false, get_string($aggcoef, 'grades'),
false, true, false, get_string($aggcoef.'help', 'grades')));
}
}
}
//End Patch
if ($grade_item->is_calculated()) {
// following elements are ignored when calculation formula used
if ($mform->elementExists('aggregation')) {
@@ -239,6 +267,12 @@ class edit_category_form extends moodleform {
}
}
}
// no parent header for course category
if (!$mform->elementExists('aggregationcoef') and !$mform->elementExists('parentcategory')) {
$mform->removeElement('headerparent');
}
}
}

View File

@@ -49,17 +49,31 @@ if ($mform->is_cancelled()) {
redirect($returnurl);
}
if ($item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
// redirect if outcomeid present
if (!empty($item->outcomeid) && !empty($CFG->enableoutcomes)) {
if (!empty($grade_item->outcomeid) && !empty($CFG->enableoutcomes)) {
$url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?id='.$id.'&courseid='.$courseid;
redirect($gpr->add_url_params($url));
}
$item->calculation = grade_item::denormalize_formula($item->calculation, $courseid);
$item = $grade_item->get_record_data();
if ($grade_item->is_course_item()) {
$item->parentcategory = 0;
} else if ($grade_item->is_category_item()) {
$parent_category = $grade_item->get_parent_category();
$parent_category = $parent_category->get_parent_category();
$item->parentcategory = $parent_category->id;
} else {
$parent_category = $grade_item->get_parent_category();
$item->parentcategory = $parent_category->id;
}
} else {
$item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'), false);
$grade_item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'), false);
$item = $grade_item->get_record_data();
$parent_category = grade_category::fetch_course_category($courseid);
$item->parentcategory = $parent_category->id;
}
$decimalpoints = $item->get_decimals();
$decimalpoints = $grade_item->get_decimals();
if ($item->hidden > 1) {
$item->hiddenuntil = $item->hidden;
@@ -80,9 +94,6 @@ $item->aggregationcoef = format_float($item->aggregationcoef, 4);
$mform->set_data($item);
if ($data = $mform->get_data(false)) {
if (array_key_exists('calculation', $data)) {
$data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
}
$hidden = empty($data->hidden) ? 0: $data->hidden;
$hiddenuntil = empty($data->hiddenuntil) ? 0: $data->hiddenuntil;
@@ -118,6 +129,11 @@ if ($data = $mform->get_data(false)) {
$grade_item->update();
}
// set parent if needed
if (isset($data->parentcategory)) {
$grade_item->set_parent($data->parentcategory, 'gradebook');
}
// update hiding flag
if ($hiddenuntil) {
$grade_item->set_hidden($hiddenuntil, false);

View File

@@ -100,10 +100,7 @@ class edit_item_form extends moodleform {
$mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
$mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
$mform->addElement('text', 'aggregationcoef', get_string('aggregationcoef', 'grades'));
/// grade display prefs
$default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype);
$options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'),
GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
@@ -147,6 +144,45 @@ class edit_item_form extends moodleform {
$mform->setHelpButton('locktime', array('locktime', get_string('locktime', 'grades'), 'grade'));
$mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
/// parent category related settings
$mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
$options = array();
$default = '';
$coefstring = '';
$categories = grade_category::fetch_all(array('courseid'=>$COURSE->id));
foreach ($categories as $cat) {
$cat->apply_forced_settings();
$options[$cat->id] = $cat->get_name();
if ($cat->is_course_category()) {
$default = $cat->id;
}
if ($cat->is_aggregationcoef_used()) {
if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef';
} else if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';
} else {
$coefstring = 'aggregationcoef';
}
} else {
$mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $cat->id);
}
}
if (count($categories) > 1) {
$mform->addElement('select', 'parentcategory', get_string('parentcategory', 'grades'), $options);
}
if ($coefstring !== '') {
$mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
$mform->setHelpButton('aggregationcoef', array(false, get_string($coefstring, 'grades'),
false, true, false, get_string($coefstring.'help', 'grades')));
$mform->setAdvanced('aggregationcoef');
}
/// hidden params
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
@@ -200,9 +236,19 @@ class edit_item_form extends moodleform {
//remove the aggregation coef element if not needed
if ($grade_item->is_course_item()) {
$mform->removeElement('aggregationcoef');
if ($mform->elementExists('parentcategory')) {
$mform->removeElement('parentcategory');
}
if ($mform->elementExists('aggregationcoef')) {
$mform->removeElement('aggregationcoef');
}
} else {
// if we wanted to change parent of existing item - we would have to verify there are no circular references in parents!!!
if ($mform->elementExists('parentcategory')) {
$mform->hardFreeze('parentcategory');
}
if ($grade_item->is_category_item()) {
$category = $grade_item->get_item_category();
$parent_category = $category->get_parent_category();
@@ -213,17 +259,22 @@ class edit_item_form extends moodleform {
$parent_category->apply_forced_settings();
if (!$parent_category->is_aggregationcoef_used()) {
$mform->removeElement('aggregationcoef');
if ($mform->elementExists('aggregationcoef')) {
$mform->removeElement('aggregationcoef');
}
} else {
//fix label if needed
$agg_el =& $mform->getElement('aggregationcoef');
$aggcoef = '';
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$agg_el->setLabel(get_string('aggregationcoefweight', 'grades'));
$mform->setHelpButton('aggregationcoef', array(false, get_string('aggregationcoefweight', 'grades'),
false, true, false, get_string('aggregationcoefweighthelp', 'grades')));
$aggcoef = 'aggregationcoefweight';
} else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$agg_el->setLabel(get_string('aggregationcoefextra', 'grades'));
$mform->setHelpButton('aggregationcoef', array(false, get_string('aggregationcoefextra', 'grades'),
false, true, false, get_string('aggregationcoefextrahelp', 'grades')));
$aggcoef = 'aggregationcoefextra';
}
if ($aggcoef !== '') {
$agg_el->setLabel(get_string($aggcoef, 'grades'));
$mform->setHelpButton('aggregationcoef', array(false, get_string($aggcoef, 'grades'),
false, true, false, get_string($aggcoef.'help', 'grades')));
}
}
}
@@ -249,22 +300,11 @@ class edit_item_form extends moodleform {
// all new items are manual, children of course category
$mform->removeElement('plusfactor');
$mform->removeElement('multfactor');
}
$parent_category = grade_category::fetch_course_category($COURSE->id);
if (!$parent_category->is_aggregationcoef_used()) {
$mform->removeElement('aggregationcoef');
} else {
$agg_el =& $mform->getElement('aggregationcoef');
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$agg_el->setLabel(get_string('aggregationcoefweight', 'grades'));
$mform->setHelpButton('aggregationcoef', array(false, get_string('aggregationcoefweight', 'grades'),
false, true, false, get_string('aggregationcoefweighthelp', 'grades')));
} else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$agg_el->setLabel(get_string('aggregationcoefextra', 'grades'));
$mform->setHelpButton('aggregationcoef', array(false, get_string('aggregationcoefextra', 'grades'),
false, true, false, get_string('aggregationcoefextrahelp', 'grades')));
}
}
// no parent header for course category
if (!$mform->elementExists('aggregationcoef') and !$mform->elementExists('parentcategory')) {
$mform->removeElement('headerparent');
}
}
@@ -290,16 +330,6 @@ class edit_item_form extends moodleform {
}
}
/*
if (array_key_exists('calculation', $data) and $data['calculation'] != '') {
$grade_item = new grade_item(array('id'=>$data['id'], 'itemtype'=>$data['itemtype'], 'courseid'=>$data['courseid']));
$result = $grade_item->validate_formula($data['calculation']);
if ($result !== true) {
$errors['calculation'] = $result;
}
}
*/
if (array_key_exists('gradetype', $data) and $data['gradetype'] == GRADE_TYPE_SCALE) {
if (empty($data['scaleid'])) {
$errors['scaleid'] = get_String('missingscale', 'grades');