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

New Web Service gradereport_user_get_grade_items

XMLWordPrintable

    • MOODLE_31_STABLE
    • MOODLE_32_STABLE
    • MDL-55928-master
    • Hide
      1. Enrol a couple of users as students and teacher in a course
      2. In that course, configure a complex gradebook:
        • Include activities with outcomes (like assignment or forum), you must add first outcomes to the course (add some grades for the student user)
        • Include grade categories and subcategories
        • Include manual grade items
        • Include hidden grade items (edit a grade item and hide it)
        • Force the course language to spanish, french or another language where the decimal separator is the comma ',' and not the period '.'
      3. As admin, enable "Mobile services": Plugins ► Web Services ► Mobile
      4. Create a Token for the student and teacher users:
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      5. Next, you can do a CURL REST call simulating a WS client with the user.
        • You need to replace the wstoken with the student one, userid with the student one, courseid with the course one and the URL of your moodle instance

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'courseid=14&userid=106&wsfunction=gradereport_user_get_grade_items&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool"

      6. Check that you:
        • Receive all the grade items visible by the user, you can compare it with the Grade user report that the user should see in the Moodle web version
        • Check that all the grade items field values are equals to the web version ones
        • Check that the raw version for values are using the period for decimals but the formatted one the comma
      7. Now, hide one grade for the student user (in the grader report, activate edition, and in the cell for the activity/user click on the settings wheel)
      8. Execute the curl command again and check that you don't see the grade hidden
      9. Run the same curl command but using the Teacher token, and check that you can see the hidden grade
      10. Run the same curl command (teacher token) but using userid=0, you should retrieve all the users
      11. Now, you can check another security/restrictions. Like disabling grades in the course settings, using separate groups, etc..
      Show
      Enrol a couple of users as students and teacher in a course In that course, configure a complex gradebook: Include activities with outcomes (like assignment or forum), you must add first outcomes to the course (add some grades for the student user) Include grade categories and subcategories Include manual grade items Include hidden grade items (edit a grade item and hide it) Force the course language to spanish, french or another language where the decimal separator is the comma ',' and not the period '.' As admin, enable "Mobile services": Plugins ► Web Services ► Mobile Create a Token for the student and teacher users: Click on Site administration ► Plugins ► Web services ► Manage tokens Next, you can do a CURL REST call simulating a WS client with the user. You need to replace the wstoken with the student one, userid with the student one, courseid with the course one and the URL of your moodle instance curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'courseid=14&userid=106&wsfunction=gradereport_user_get_grade_items&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool" Check that you: Receive all the grade items visible by the user, you can compare it with the Grade user report that the user should see in the Moodle web version Check that all the grade items field values are equals to the web version ones Check that the raw version for values are using the period for decimals but the formatted one the comma Now, hide one grade for the student user (in the grader report, activate edition, and in the cell for the activity/user click on the settings wheel) Execute the curl command again and check that you don't see the grade hidden Run the same curl command but using the Teacher token, and check that you can see the hidden grade Run the same curl command (teacher token) but using userid=0, you should retrieve all the users Now, you can check another security/restrictions. Like disabling grades in the course settings, using separate groups, etc..

      This new Web Service will be a good replacement for core_grades_get_grades, basically, it will allow a user or manager (teacher/admin) to retrieve all the grate items from the course gradebook:

      • Grades
      • Outcomes
      • Manual
      • Categories
        among with feedback, rank, range etc..

      Including the final course grade and aggregations.

      We have to base the new WS on the user report code because is the only one taking care of advanced gradebook features like hiding affected grades, adjust bounds, etc..

      A first view of the user grader report reflects its complexity, the more sensible approach (under my opinion) would be not to touch any single line of code and just add a new data structure (rawgradeitemdata) that will be filled in the recursive process of building the grades table. (Basically, in the fill_table_recursive function).
      At the end, the report class will generate two data structures: tabledata ready for printing the table and the rawgradeitemdata, with a representation of the gradebook ready to be used by external functions.

      The ideal thing would be to split the code into one function generating a templatable/renderable and then another one for build the table, but looking at the actual code this will be very complex, will require a lot of code duplication and I'm afraid of possible regressions.

            jleyva Juan Leyva
            jleyva Juan Leyva
            Adrian Greeve Adrian Greeve
            Andrew Lyons Andrew Lyons
            Jun Pataleta Jun Pataleta
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.