Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nguyen committed Aug 29, 2024
1 parent ca4f081 commit e7fcc43
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lang/en/grades.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@
$string['modgradeerrorbadpoint'] = 'Invalid grade value. This must be an integer between 1 and {$a}';
$string['modgradeerrorbadscale'] = 'Invalid scale selected. Please make sure you select a scale from the selections below.';
$string['modgrademaxgrade'] = 'Maximum grade';
$string['modgraderecalculatepenalty'] = 'Recalculate penalty';
$string['modgraderecalculatepenalty_help'] = 'The penalty will be recalculated for all users.';
$string['modgraderescalegrades'] = 'Rescale existing grades';
$string['modgraderescalegrades_help'] = 'When changing the maximum grades on a gradebook item you need to specify whether or not this will cause existing percentage grades to change as well.
Expand Down
1 change: 1 addition & 0 deletions mod/assign/lang/en/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@
$string['page-mod-assign-view'] = 'Assignment module main and submission page';
$string['paramtimeremaining'] = '{$a} remaining';
$string['participant'] = 'Participant';
$string['penaltyduedatechangemessage'] = 'Some grades have already been awarded. In order to change the due date, you must first choose whether or not to recalculate existing grades.';
$string['pluginadministration'] = 'Assignment administration';
$string['pluginname'] = 'Assignment';
$string['preventsubmissionnotingroup'] = 'Require group to make submission';
Expand Down
32 changes: 31 additions & 1 deletion mod/assign/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class mod_assign_mod_form extends moodleform_mod {
* @return void
*/
public function definition() {
global $CFG, $COURSE, $DB;
global $CFG, $COURSE, $DB, $OUTPUT;;
$mform = $this->_form;

$mform->addElement('header', 'general', get_string('general', 'form'));
Expand Down Expand Up @@ -95,9 +95,23 @@ public function definition() {
$mform->addElement('date_time_selector', 'allowsubmissionsfromdate', $name, $options);
$mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign');

// Add the option to recalculate the penalty if there is existing grade.
if (\mod_assign\penalty\helper::is_penalty_enabled($assignment->get_instance()->id) && $assignment->count_grades() > 0) {
// Create notification.
$notice = $OUTPUT->notification(get_string('penaltyduedatechangemessage', 'assign'), 'warning', false);
$mform->addElement('html', $notice);
$mform->addElement('select', 'recalculatepenalty', get_string('modgraderecalculatepenalty', 'grades'), [
'' => get_string('choose'),
'no' => get_string('no'),
'yes' => get_string('yes'),
]);
$mform->addHelpButton('recalculatepenalty', 'modgraderecalculatepenalty', 'grades');
}

$name = get_string('duedate', 'assign');
$mform->addElement('date_time_selector', 'duedate', $name, array('optional'=>true));
$mform->addHelpButton('duedate', 'duedate', 'assign');
$mform->disabledIf('duedate', 'recalculatepenalty', 'eq', '');

$name = get_string('cutoffdate', 'assign');
$mform->addElement('date_time_selector', 'cutoffdate', $name, array('optional'=>true));
Expand Down Expand Up @@ -255,6 +269,9 @@ public function definition() {

// Hide if the grade type is not set to point.
$mform->hideIf('gradepenalty', 'grade[modgrade_type]', 'neq', 'point');

// Disable if the recalculate penalty is not set.
$mform->disabledIf('gradepenalty', 'recalculatepenalty', 'eq', '');
}

$this->standard_coursemodule_elements();
Expand All @@ -263,6 +280,19 @@ public function definition() {
$this->add_action_buttons();
}

// /**
// * Override get_data to set to retrieve the data from the database if the recalculatepenalty is not set.
// */
// public function get_data() {
// $data = parent::get_data();
// if ($data && empty($data->recalculatepenalty) && empty($data->duedate)) {
// $cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST);
// $assign = new assign(context_module::instance($cm->id), $cm, $this->current->course);
// $data->duedate = $assign->get_instance()->duedate;
// }
// return $data;
// }

/**
* Perform minimal validation on the settings form
* @param array $data
Expand Down
40 changes: 40 additions & 0 deletions mod/assign/override_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,22 @@ protected function definition() {
get_string('allowsubmissionsfromdate', 'assign'), array('optional' => true));
$mform->setDefault('allowsubmissionsfromdate', $assigninstance->allowsubmissionsfromdate);

// Add the option to recalculate the penalty if there is existing grade.
if ($this->assign->count_grades() > 0) {
// Create notification.
$notice = $OUTPUT->notification(get_string('penaltyduedatechangemessage', 'assign'), 'warning', false);
$mform->addElement('html', $notice);
$mform->addElement('select', 'recalculatepenalty', get_string('modgraderecalculatepenalty', 'grades'), [
'' => get_string('choose'),
'no' => get_string('no'),
'yes' => get_string('yes'),
]);
$mform->addHelpButton('recalculatepenalty', 'modgraderecalculatepenalty', 'grades');
}

$mform->addElement('date_time_selector', 'duedate', get_string('duedate', 'assign'), array('optional' => true));
$mform->setDefault('duedate', $assigninstance->duedate);
$mform->disabledIf('duedate', 'recalculatepenalty', 'eq', '');

$mform->addElement('date_time_selector', 'cutoffdate', get_string('cutoffdate', 'assign'), array('optional' => true));
$mform->setDefault('cutoffdate', $assigninstance->cutoffdate);
Expand Down Expand Up @@ -286,6 +300,32 @@ protected function definition() {

}

/**
* Override to set to retrieve the data from the database if the recalculatepenalty is not set.
*/
function definition_after_data() {
$mform = $this->_form;

// Get recalculatepenalty value.
$recalculatepenalty = optional_param('recalculatepenalty', null, PARAM_TEXT);
}
// public function get_data() {
// global $DB;
// $data = parent::get_data();
// if ($data && empty($data->recalculatepenalty) && empty($data->duedate)) {
// $assignid = $this->assign->get_instance()->id;
// if ($this->groupmode) {
// // Get group override.
// $override = $DB->get_record('assign_overrides', ['assignid' => $assignid, 'groupid' => $this->groupid]);
// } else {
// // Get user override.
// $override = $DB->get_record('assign_overrides', ['assignid' => $assignid, 'userid' => $this->userid]);
// }
// $data->duedate = $override->duedate;
// }
// return $data;
// }

/**
* Validate the submitted form data.
*
Expand Down

0 comments on commit e7fcc43

Please sign in to comment.