From: skodak Date: Fri, 16 Nov 2007 22:15:25 +0000 (+0000) Subject: MDL-12146 merged recent changes from normal item to outcome form; merged from MOODLE_... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6ba472cd6550f2eea1c978590a2dd566ae1853d4;p=moodle.git MDL-12146 merged recent changes from normal item to outcome form; merged from MOODLE_19_STABLE --- diff --git a/grade/edit/tree/outcomeitem.php b/grade/edit/tree/outcomeitem.php index 098a934af2..bc6334feab 100644 --- a/grade/edit/tree/outcomeitem.php +++ b/grade/edit/tree/outcomeitem.php @@ -50,15 +50,25 @@ if ($mform->is_cancelled() || empty($CFG->enableoutcomes)) { redirect($returnurl); } -if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) { - $item = new grade_item($item, false); - +if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) { // redirect if outcomeid present if (empty($item->outcomeid)) { $url = $CFG->wwwroot.'/grade/edit/tree/item.php?id='.$id.'&courseid='.$courseid; redirect($gpr->add_url_params($url)); } - $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id); + $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; + } + if ($item->itemtype == 'mod') { $cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid); $item->cmid = $cm->id; @@ -67,11 +77,14 @@ if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) { } } else { - $item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual')); + $grade_item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'), false); + $item = $grade_item->get_record_data(); $item->cmid = 0; + $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; @@ -164,10 +177,19 @@ if ($data = $mform->get_data(false)) { $grade_item->set_parent($item->categoryid); $grade_item->move_after_sortorder($item->sortorder); } + } else { + // set parent if needed + if (isset($data->parentcategory)) { + $grade_item->set_parent($data->parentcategory, 'gradebook'); + } } } else { $grade_item->update(); + // set parent if needed + if (isset($data->parentcategory)) { + $grade_item->set_parent($data->parentcategory, 'gradebook'); + } } // update hiding flag diff --git a/grade/edit/tree/outcomeitem_form.php b/grade/edit/tree/outcomeitem_form.php index 3f1623c484..b3c47c6341 100644 --- a/grade/edit/tree/outcomeitem_form.php +++ b/grade/edit/tree/outcomeitem_form.php @@ -69,14 +69,10 @@ class edit_outcomeitem_form extends moodleform { false, true, false, get_string('linkedactivityhelp', 'grades'))); $mform->setDefault('cmid', 0); - //$mform->addElement('text', 'calculation', get_string('calculation', 'grades')); - /*$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades')); $mform->setHelpButton('gradepass', array(false, get_string('gradepass', 'grades'), false, true, false, get_string('gradepasshelp', 'grades')));*/ - $mform->addElement('text', 'aggregationcoef', get_string('aggregationcoef', 'grades')); - /// hiding /// advcheckbox is not compatible with disabledIf !! $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades')); @@ -91,6 +87,45 @@ class edit_outcomeitem_form extends moodleform { $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true)); $mform->setHelpButton('locktime', array('locktime', get_string('locktime', 'grades'), 'grade')); +/// 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('gradecategory', 'grades'), $options); + $mform->disabledIf('parentcategory', 'cmid', 'noteq', 0); + } + + 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'))); + } + /// hidden params $mform->addElement('hidden', 'id', 0); $mform->setType('id', PARAM_INT); @@ -102,6 +137,15 @@ class edit_outcomeitem_form extends moodleform { $gpr = $this->_customdata['gpr']; $gpr->add_mform_elements($mform); +/// mark advanced according to site settings + if (isset($CFG->grade_item_advanced)) { + $advanced = explode(',', $CFG->grade_item_advanced); + foreach ($advanced as $el) { + if ($mform->elementExists($el)) { + $mform->setAdvanced($el); + } + } + } //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); @@ -119,9 +163,19 @@ class edit_outcomeitem_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(); @@ -131,38 +185,32 @@ class edit_outcomeitem_form extends moodleform { $parent_category->apply_forced_settings(); - if (!$parent_category->is_aggregationcoef_used() or !$parent_category->aggregateoutcomes) { - $mform->removeElement('aggregationcoef'); + 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) { - $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'))); } } } - } else { - $parent_category = grade_category::fetch_course_category($COURSE->id); - if (!$parent_category->is_aggregationcoef_used() or !$parent_category->aggregateoutcomes) { - $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'); } }