Skip to content

Commit

Permalink
MDL-12146 merged recent changes from normal item to outcome form; mer…
Browse files Browse the repository at this point in the history
…ged from MOODLE_19_STABLE
  • Loading branch information
skodak committed Nov 16, 2007
1 parent 1b452ba commit 6ba472c
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 35 deletions.
34 changes: 28 additions & 6 deletions grade/edit/tree/outcomeitem.php
Expand Up @@ -50,15 +50,25 @@
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;
Expand All @@ -67,11 +77,14 @@
}

} 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;
Expand Down Expand Up @@ -164,10 +177,19 @@
$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
Expand Down
106 changes: 77 additions & 29 deletions grade/edit/tree/outcomeitem_form.php
Expand Up @@ -69,14 +69,10 @@ function definition() {
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'));
Expand All @@ -91,6 +87,45 @@ function definition() {
$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);
Expand All @@ -102,6 +137,15 @@ function definition() {
$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();
Expand All @@ -119,9 +163,19 @@ function definition_after_data() {

//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();
Expand All @@ -131,38 +185,32 @@ function definition_after_data() {

$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');
}
}

Expand Down

0 comments on commit 6ba472c

Please sign in to comment.