Skip to content

Commit

Permalink
MDL-13831 course: add gradepass field to mod_form
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-or authored and marinaglancy committed Mar 23, 2015
1 parent a149d6a commit 8164fad
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 0 deletions.
4 changes: 4 additions & 0 deletions course/modedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@
'iteminstance'=>$data->instance, 'courseid'=>$course->id))) {
// add existing outcomes
foreach ($items as $item) {
if (!empty($item->gradepass)) {
$decimalpoints = $item->get_decimals();
$data->gradepass = format_float($item->gradepass, $decimalpoints);
}
if (!empty($item->outcomeid)) {
$data->{'outcome_'.$item->outcomeid} = 1;
}
Expand Down
8 changes: 8 additions & 0 deletions course/modlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,16 @@ function edit_module_post_actions($moduleinfo, $course) {
// Sync idnumber with grade_item.
if ($hasgrades && $grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$moduleinfo->modulename,
'iteminstance'=>$moduleinfo->instance, 'itemnumber'=>0, 'courseid'=>$course->id))) {
$gradeupdate = false;
if ($grade_item->idnumber != $moduleinfo->cmidnumber) {
$grade_item->idnumber = $moduleinfo->cmidnumber;
$gradeupdate = true;
}
if (isset($moduleinfo->gradepass) && $grade_item->gradepass != $moduleinfo->gradepass) {
$grade_item->gradepass = $moduleinfo->gradepass;
$gradeupdate = true;
}
if ($gradeupdate) {
$grade_item->update();
}
}
Expand Down
21 changes: 21 additions & 0 deletions course/moodleform_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,19 @@ function validation($data, $files) {
$errors['assessed'] = get_string('scaleselectionrequired', 'rating');
}

// Grade to pass: ensure that the grade to pass is valid for points and scales.
// If we are working with a scale, convert into a positive number for validation.
if (isset($data['grade'])) {
if ($data['grade'] < 0) {
$grade = $data['grade'] * -1;
} else {
$grade = $data['grade'];
}
if (isset($data['gradepass']) && $data['gradepass'] > $grade) {
$errors['gradepass'] = get_string('gradepassgreaterthangrade', 'grades');
}
}

// Completion: Don't let them choose automatic completion without turning
// on some conditions. Ignore this check when completion settings are
// locked, as the options are then disabled.
Expand Down Expand Up @@ -645,6 +658,14 @@ public function standard_grading_coursemodule_elements() {
grade_get_categories_menu($COURSE->id, $this->_outcomesused));
$mform->addHelpButton('gradecat', 'gradecategoryonmodform', 'grades');
}
if (!empty($this->current->gradepass)) {
$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
$mform->addHelpButton('gradepass', 'gradepass', 'grades');
$mform->setDefault('gradepass', '');
$mform->setType('gradepass', PARAM_FLOAT);
$mform->addRule('gradepass', null, 'numeric', null, 'client');
$mform->disabledIf('gradepass', 'grade[modgrade_type]', 'eq', 'none');
}
}
}

Expand Down
76 changes: 76 additions & 0 deletions grade/tests/behat/grade_to_pass.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
@core @core_grades
Feature: We can set the grade to pass value
In order to set the grade to pass value
As a teacher
I assign a grade to pass to an activity while editing the activity.
I need to ensure that the grade to pass is visible in the gradebook.

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@asd.com |
And the following "courses" exist:
| fullname | shortname | format | numsections |
| Course 1 | C1 | weeks | 5 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Assignment" to section "1" and I fill the form with:
| Assignment name | Test Assignment 1 |
| Description | Submit your online text |
| assignsubmission_onlinetext_enabled | 1 |

@javascript
Scenario: Validate that switching the type of grading used correctly disables grade to pass
When I follow "Test Assignment 1"
And I follow "Edit settings"
And I expand all fieldsets
And I set the field "grade[modgrade_type]" to "Point"
Then the "Grade to pass" "field" should be enabled
And I set the field "grade[modgrade_type]" to "None"
Then the "Grade to pass" "field" should be disabled
And I press "Save and return to course"

@javascript
Scenario: Create an activity with a Grade to pass value greater than the maximum grade
When I follow "Test Assignment 1"
And I follow "Edit settings"
And I expand all fieldsets
And I set the field "grade[modgrade_type]" to "Point"
And I set the field "grade[modgrade_point]" to "50"
And I press "Save and display"
And I follow "Edit settings"
And I expand all fieldsets
And I set the field "Grade to pass" to "100"
And I press "Save and display"
Then I should see "The grade to pass is greater than the grade"
And I press "Cancel"

@javascript
Scenario: Set a valid grade to pass for an assignment and workshop activity
When I follow "Test Assignment 1"
And I follow "Edit settings"
And I expand all fieldsets
And I set the field "grade[modgrade_type]" to "point"
And I set the field "grade[modgrade_point]" to "50"
And I set the field "Grade to pass" to "25"
And I press "Save and display"
And I follow "View gradebook"
And I turn editing mode on
And I click on "Edit assign Test Assignment 1" "link"
Then I should see "Edit grade item"
Then the field "Grade to pass" matches value "25"
And I follow "Course 1"
And I add a "Workshop" to section "1" and I fill the form with:
| Workshop name | Test Workshop 1 |
| Description | Test workshop |
| grade | 80 |
| Grade to pass for submission | 40 |
| gradinggrade | 20 |
| Grade to pass for assessment | 10 |
And I follow "Grades"
And I click on "Edit workshop Test Workshop 1 (submission)" "link"
Then the field "Grade to pass" matches value "40"
1 change: 1 addition & 0 deletions lang/en/grades.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
$string['gradeoutcomescourses'] = 'Course outcomes';
$string['gradepass'] = 'Grade to pass';
$string['gradepass_help'] = 'This setting determines the minimum grade required to pass. The value is used in activity and course completion, and in the gradebook, where pass grades are highlighted in green and fail grades in red.';
$string['gradepassgreaterthangrade'] = 'The grade to pass entered is greater than the maximum grade';
$string['gradepointdefault'] = 'Grade point default';
$string['gradepointdefault_help'] = 'This setting determines the default value for the grade point value available in an activity.';
$string['gradepointdefault_validateerror'] = 'This setting must be an integer between 1 and the grade point maximum.';
Expand Down
3 changes: 3 additions & 0 deletions mod/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
This files describes API changes in /mod/* - activity modules,
information provided here is intended especially for developers.

=== 2.9 ===
* Added Grade to pass field to mod_form for activities that support grading.

=== 2.8 ===

* Constant FEATURE_GROUPMEMBERSONLY is deprecated. Modules should remove this
Expand Down
2 changes: 2 additions & 0 deletions mod/workshop/lang/en/workshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
$string['gradesreport'] = 'Workshop grades report';
$string['gradereceivedfrom'] = '&lt;';
$string['gradeinfo'] = 'Grade: {$a->received} of {$a->max}';
$string['gradetopasssubmission'] = 'Submission grade to pass';
$string['gradetopassgrading'] = 'Assessment grade to pass';
$string['gradinggrade'] = 'Grade for assessment';
$string['gradinggrade_help'] = 'This setting specifies the maximum grade that may be obtained for submission assessment.';
$string['gradinggradecalculated'] = 'Calculated grade for assessment';
Expand Down
8 changes: 8 additions & 0 deletions mod/workshop/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1140,10 +1140,18 @@ function workshop_grade_item_category_update($workshop) {
if (!empty($gradeitems)) {
foreach ($gradeitems as $gradeitem) {
if ($gradeitem->itemnumber == 0) {
if ($gradeitem->gradepass != $workshop->submissiongradepass) {
$gradeitem->gradepass = $workshop->submissiongradepass;
$gradeitem->update();
}
if ($gradeitem->categoryid != $workshop->gradecategory) {
$gradeitem->set_parent($workshop->gradecategory);
}
} else if ($gradeitem->itemnumber == 1) {
if ($gradeitem->gradepass != $workshop->gradinggradepass) {
$gradeitem->gradepass = $workshop->gradinggradepass;
$gradeitem->update();
}
if ($gradeitem->categoryid != $workshop->gradinggradecategory) {
$gradeitem->set_parent($workshop->gradinggradecategory);
}
Expand Down
24 changes: 24 additions & 0 deletions mod/workshop/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public function definition() {
$mform->setDefault('grade', $workshopconfig->grade);
$mform->addHelpButton('submissiongradegroup', 'submissiongrade', 'workshop');

$mform->addElement('text', 'submissiongradepass', get_string('gradetopasssubmission', 'workshop'));
$mform->addHelpButton('submissiongradepass', 'gradepass', 'grades');
$mform->setDefault('submissiongradepass', '');
$mform->setType('submissiongradepass', PARAM_FLOAT);
$mform->addRule('submissiongradepass', null, 'numeric', null, 'client');

$label = get_string('gradinggrade', 'workshop');
$mform->addGroup(array(
$mform->createElement('select', 'gradinggrade', '', $grades),
Expand All @@ -105,6 +111,12 @@ public function definition() {
$mform->setDefault('gradinggrade', $workshopconfig->gradinggrade);
$mform->addHelpButton('gradinggradegroup', 'gradinggrade', 'workshop');

$mform->addElement('text', 'gradinggradepass', get_string('gradetopassgrading', 'workshop'));
$mform->addHelpButton('gradinggradepass', 'gradepass', 'grades');
$mform->setDefault('gradinggradepass', '');
$mform->setType('gradinggradepass', PARAM_FLOAT);
$mform->addRule('gradinggradepass', null, 'numeric', null, 'client');

$options = array();
for ($i=5; $i>=0; $i--) {
$options[$i] = $i;
Expand Down Expand Up @@ -296,7 +308,10 @@ public function definition_after_data() {
foreach ($gradeitems as $gradeitem) {
// here comes really crappy way how to set the value of the fields
// gradecategory and gradinggradecategory - grrr QuickForms
$decimalpoints = $gradeitem->get_decimals();
if ($gradeitem->itemnumber == 0) {
$submissiongradepass = $mform->getElement('submissiongradepass');
$submissiongradepass->setValue(format_float($gradeitem->gradepass, $decimalpoints));
$group = $mform->getElement('submissiongradegroup');
$elements = $group->getElements();
foreach ($elements as $element) {
Expand All @@ -305,6 +320,8 @@ public function definition_after_data() {
}
}
} else if ($gradeitem->itemnumber == 1) {
$gradinggradepass = $mform->getElement('gradinggradepass');
$gradinggradepass->setValue(format_float($gradeitem->gradepass, $decimalpoints));
$group = $mform->getElement('gradinggradegroup');
$elements = $group->getElements();
foreach ($elements as $element) {
Expand Down Expand Up @@ -355,6 +372,13 @@ public function validation($data, $files) {
}
}

if ($data['submissiongradepass'] > $data['grade']) {
$errors['submissiongradepass'] = get_string('gradepassgreaterthangrade', 'grades');
}
if ($data['gradinggradepass'] > $data['gradinggrade']) {
$errors['gradinggradepass'] = get_string('gradepassgreaterthangrade', 'grades');
}

return $errors;
}
}

0 comments on commit 8164fad

Please sign in to comment.