$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);
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);
}
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'),
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');
$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')));
$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'),
$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')) {
}
}
}
+
+ // no parent header for course category
+ if (!$mform->elementExists('aggregationcoef') and !$mform->elementExists('parentcategory')) {
+ $mform->removeElement('headerparent');
+ }
+
}
}
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;
$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;
$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);
$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'),
$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);
//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();
$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')));
}
}
}
// 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');
}
}
}
}
- /*
- 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');
$string['overriddenhelp'] = 'When on, the overridden flag prevents any future attempts to automatically adjust the value of the grade. This flag is often set internally by the gradebook, but can be switched on and off manually using this form element.';
$string['overriddennotice'] = 'Your final grade from this activity was manually adjusted.';
$string['overallavg'] = 'Overall average';
+$string['parentcategory'] = 'Parent category';
$string['pctoftotalgrade'] = '%% of total grade';
$string['percent'] = 'Percent';
$string['percentage'] = 'Percentage';