Skip to content

Commit

Permalink
Merge branch 'master-MDL-68284' of https://github.com/yao9394/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Oct 20, 2020
2 parents b79f17e + a0ffd0d commit 33831f6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 27 deletions.
47 changes: 24 additions & 23 deletions grade/edit/tree/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@
$data->grademin = 0;
}

$hidden = empty($data->hidden) ? 0: $data->hidden;
$hiddenuntil = empty($data->hiddenuntil) ? 0: $data->hiddenuntil;
$hide = empty($data->hiddenuntil) ? 0 : $data->hiddenuntil;
if (!$hide) {
$hide = empty($data->hidden) ? 0 : $data->hidden;
}

unset($data->hidden);
unset($data->hiddenuntil);

Expand All @@ -155,45 +158,43 @@
$data->aggregationcoef2 = $defaults['aggregationcoef2'];
}

$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
$oldmin = $grade_item->grademin;
$oldmax = $grade_item->grademax;
grade_item::set_properties($grade_item, $data);
$grade_item->outcomeid = null;
$gradeitem = new grade_item(array('id' => $id, 'courseid' => $courseid));
$oldmin = $gradeitem->grademin;
$oldmax = $gradeitem->grademax;
grade_item::set_properties($gradeitem, $data);
$gradeitem->outcomeid = null;

// Handle null decimals value
if (!property_exists($data, 'decimals') or $data->decimals < 0) {
$grade_item->decimals = null;
$gradeitem->decimals = null;
}

if (empty($grade_item->id)) {
$grade_item->itemtype = 'manual'; // all new items to be manual only
$grade_item->insert();
if (empty($gradeitem->id)) {
$gradeitem->itemtype = 'manual'; // All new items to be manual only.
$gradeitem->insert();

// set parent if needed
if (isset($data->parentcategory)) {
$grade_item->set_parent($data->parentcategory, false);
$gradeitem->set_parent($data->parentcategory, false);
}

} else {
$grade_item->update();
$gradeitem->update();

if (!empty($data->rescalegrades) && $data->rescalegrades == 'yes') {
$newmin = $grade_item->grademin;
$newmax = $grade_item->grademax;
$grade_item->rescale_grades_keep_percentage($oldmin, $oldmax, $newmin, $newmax, 'gradebook');
$newmin = $gradeitem->grademin;
$newmax = $gradeitem->grademax;
$gradeitem->rescale_grades_keep_percentage($oldmin, $oldmax, $newmin, $newmax, 'gradebook');
}
}

// update hiding flag
if ($hiddenuntil) {
$grade_item->set_hidden($hiddenuntil, false);
} else {
$grade_item->set_hidden($hidden, false);
if ($item->cancontrolvisibility) {
// Update hiding flag.
$gradeitem->set_hidden($hide, false);
}

$grade_item->set_locktime($locktime); // locktime first - it might be removed when unlocking
$grade_item->set_locked($locked, false, true);
$gradeitem->set_locktime($locktime); // Locktime first - it might be removed when unlocking.
$gradeitem->set_locked($locked, false, true);

redirect($returnurl);
}
Expand Down
5 changes: 2 additions & 3 deletions grade/edit/tree/item_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,9 @@ function definition() {

/// hiding
if ($item->cancontrolvisibility) {
// advcheckbox is not compatible with disabledIf!
$mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
$mform->addElement('advcheckbox', 'hidden', get_string('hidden', 'grades'), '', [], [0, 1]);
$mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
$mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked');
$mform->disabledIf('hidden', 'hiddenuntil[enabled]', 'checked');
} else {
$mform->addElement('static', 'hidden', get_string('hidden', 'grades'),
get_string('componentcontrolsvisibility', 'grades'));
Expand Down
22 changes: 22 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2793,5 +2793,27 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021052500.26);
}

if ($oldversion < 2021052500.27) {
// Script to fix incorrect records of "hidden" field in existing grade items.
$sql = "SELECT cm.instance, cm.course
FROM {course_modules} cm
JOIN {modules} m ON m.id = cm.module
WHERE m.name = :module AND cm.visible = :visible";
$hidequizlist = $DB->get_recordset_sql($sql, ['module' => 'quiz', 'visible' => 0]);

foreach ($hidequizlist as $hidequiz) {
$params = [
'itemmodule' => 'quiz',
'courseid' => $hidequiz->course,
'iteminstance' => $hidequiz->instance,
];

$DB->set_field('grade_items', 'hidden', 1, $params);
}
$hidequizlist->close();

upgrade_main_savepoint(true, 2021052500.27);
}

return true;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2021052500.26; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021052500.27; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20201016)'; // Human-friendly version name
Expand Down

0 comments on commit 33831f6

Please sign in to comment.