Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-51552

"Single View" bulk insert for empty grades overwrites non-empty grades

    Details

    • Testing Instructions:
      Hide

      Testing instructions

      1. Set up a course and have enrolled at least 4 students (10 is good number).
      2. Create multiple assessments (assignments are easy to create).
      3. Create a grade item that has a different rawgrade and final grade and hasn't been overridden.
        1. Create a database activity.
        2. Under "Ratings" set the aggregate type to "Average of ratings"
        3. Add a field.
        4. Save the template.
        5. Log in as a student and add an entry.
        6. Log out and log in as a teacher and rate the entry.
        7. Edit the setting for the database activity and change the "Maximum points" under "Ratings" to something different.
      4. Go to the gradebook and enter the setup page.
      5. Create a category and move a couple of assessments into it.
      6. Create a grade item.
      7. Create a grade item and then make it a calculated item based on another assessment.
      8. Manually grade a student through the activity (don't give a grade through the gradebook).
      9. Go to the single view grade report.

      Single view (grade item)

      1. Select a normal grade item (not the manually generated one from the gradebook setup screen) such as an assignment that you graded before.
      2. At least one of the students should have a grade (if not then go and grade them and come back).
      3. Override one of the students grades.
      4. Change the URL at the top and set perpage=5 (some number that will give you two pages). If there is no perpage in the URL then put one in '&perpage=5'.
      5. Select a page that doesn't have student grades yet set (the idea is to check that the grades on the other page have not been overriden from the bulk grade change), check the 'perform bulk insert' box, check that 'Empty grades' is selected, and set the 'insert value' to 1.
      6. Hit save and check that values on page one and two are correct. The previous grades that were set should still be the same.
      7. Select the manual grade item this time.
      8. Set grades for one or two students.
      9. Make sure that the students are on two pages.
      10. Make sure that you are on a page different to the one that has a student with a grade.
      11. check the 'perform bulk insert' box, check that 'Empty grades' is selected, and set the 'insert value' to 1.
      12. Once again check that the students that had grades set before have not been overridden with the new grade value.

      Single view (user)

      1. Select a student, perferably the one that you marked earlier.
      2. Override one grade.
      3. Set the paging like in the previous exercise.
      4. Bulk override the empty grades from a page that has no preset grades.
      5. Check that only the empty grades were updated. This includes the calculated grade items and the category totals, but not the course total (only because it had an existing value). I have an issue created for this already (MDL-51722).
      Show
      Testing instructions Set up a course and have enrolled at least 4 students (10 is good number). Create multiple assessments (assignments are easy to create). Create a grade item that has a different rawgrade and final grade and hasn't been overridden. Create a database activity. Under "Ratings" set the aggregate type to "Average of ratings" Add a field. Save the template. Log in as a student and add an entry. Log out and log in as a teacher and rate the entry. Edit the setting for the database activity and change the "Maximum points" under "Ratings" to something different. Go to the gradebook and enter the setup page. Create a category and move a couple of assessments into it. Create a grade item. Create a grade item and then make it a calculated item based on another assessment. Manually grade a student through the activity (don't give a grade through the gradebook). Go to the single view grade report. Single view (grade item) Select a normal grade item (not the manually generated one from the gradebook setup screen) such as an assignment that you graded before. At least one of the students should have a grade (if not then go and grade them and come back). Override one of the students grades. Change the URL at the top and set perpage=5 (some number that will give you two pages). If there is no perpage in the URL then put one in '&perpage=5'. Select a page that doesn't have student grades yet set (the idea is to check that the grades on the other page have not been overriden from the bulk grade change), check the 'perform bulk insert' box, check that 'Empty grades' is selected, and set the 'insert value' to 1. Hit save and check that values on page one and two are correct. The previous grades that were set should still be the same. Select the manual grade item this time. Set grades for one or two students. Make sure that the students are on two pages. Make sure that you are on a page different to the one that has a student with a grade. check the 'perform bulk insert' box, check that 'Empty grades' is selected, and set the 'insert value' to 1. Once again check that the students that had grades set before have not been overridden with the new grade value. Single view (user) Select a student, perferably the one that you marked earlier. Override one grade. Set the paging like in the previous exercise. Bulk override the empty grades from a page that has no preset grades. Check that only the empty grades were updated. This includes the calculated grade items and the category totals, but not the course total (only because it had an existing value). I have an issue created for this already ( MDL-51722 ).
    • Affected Branches:
      MOODLE_28_STABLE
    • Fixed Branches:
      MOODLE_28_STABLE, MOODLE_29_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      wip-MDL-51552-master

      Description

      Here are the steps to reproduce the bug.
      1. Go to https://moodle.org/demo/
      2. Select "Moodle sandbox"
      3. Log in as admin
      4. Pick a course
      5. Enroll as many students as possible (you can probably do four without adding users). Make sure they are "students".
      6. Go to Grade Setup "Categories and Items"
      7. Create a manual item (Grade type=value)
      8. Go to Single View and select the manual item you just created
      9. Add "&perpage=2" to the URL and refresh the page (if the parameter is already there, change "&perpage=100" to "&perpage=2")
      10. Make sure you get the pagination.
      11. Go to the second page and add a grade (i.e. 20) to a student. Save.
      12. Go back to the first page and check "Perform bulk insert" for empty grades and hit Save.
      13. Go back to the second page and confirm that the previously entered grade, 20, has been overwritten by 0.

      Potential cause and solution:
      On 2.5, when you save a grade for a manual item, Moodle saves the value in both "rawgrade" and "finalgrade" columns in grade_grades table.
      On 2.8, Moodle only saves the value in the "finalgrade" column.

      The bulk execution code can be found in the process() function on \grade\report\singleview\classes\local\screen\grade.php.
      When the user hits "save" from the single view, the parameter values on the page (the new grades on the page) are sent to the server. However, the students' grades on the subsequent pages are not sent to the server as parameters.
      In the process(), if the bulk insert is checked and the student's grade cannot be found in the parameters, it fetches the existing grade from the database and stores it to $grade. (line #338)
      Then, it examines whether or not the override flag is there. If the flag is not there, it checks whether or not the rawgrade exists in $grade (this is the PROBLEM! line #349).
      If rawgrade is not set, it creates an entry with an empty grade, and add it to a list of parameters. Then later on, the bulk insert happens for the empty grades.

      Because Moodle does not use the rawgrade column to store grade values for the manual items any more, we need to modify line #349 to process grades differently for Manual items.
      Here is what I suggest.

      if (empty($data->$oldoverride)) {
      if($gradeitem->itemtype == 'manual')

      { $data->$field = (!isset($grade->finalgrade)) ? $null : $grade->finalgrade; }

      else

      { $data->$field = (!isset($grade->rawgrade)) ? $null : $grade->rawgrade; }

      }

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  7 Vote for this issue
                  Watchers:
                  15 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    9/Nov/15