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

Create API for grade category (gradebook)

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Setup

      1) Enable web services for the site, and enable the rest protocol.

      2) Go to "Admin -> Plugins -> Web services -> External services" and add a service named 'gradecat, enabled, and add the function 'core_grades_create_gradecategory' to it.

      3) Go to "Admin -> Plugins -> Web services -> Manage tokens" and add a token for the Admin user account and the just created "gradecat" service, so there are no permission issues. Annotate it for later use.

      4) Create a blank test course to test the webservice in. Annotate its "courseid" from the url.

      5) Visit the gradebook setup page for the newly created course.

      Testing

      6) Open a terminal (with curl installed)

      7) Execute the following command to call the webservice with basic parameters

      curl "http://moodlecore.lan/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategory&moodlewsrestformat=json&courseid={COURSEID}&fullname=Test" | json_pp

      (replacing TOKEN and COURSEID with the values annotated above)

      8) Verify that the returned JSON in the terminal contains the field 'categoryid' with a number, and the warnings array is empty. Make note of the categoryid

      9) Reload the gradebook setup, and verify that there is now a grade category underneath the course grade category, called 'Test'.

      10) Execute the following command with the annotated token, courseid and categoryid from above.

      curl "http://moodlecore.lan/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategory&moodlewsrestformat=json&courseid={COURSEID}&fullname=Test2&options[parentcategoryid]={CATEGORYID}&options[idnumber]=IDNumber" | json_pp
      

       11) Verify the returned JSON contains a similar response to the above command, with no warnings

      12) Reload the gradebook setup and verify there is now a 'Test 2' category nested as a child of the 'Test category'

      13) Edit the Test2 Gradecategory settings and confirm that the ID number field is set to 'IDNumber'

      15) Repeat the same command as above, this time, specifying the idnumber of the parent category instead of the id.

      curl "http://moodlecore.lan/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategory&moodlewsrestformat=json&courseid={COURSEID}&fullname=Test3&options[parentcategoryidnumber]=IDNumber" | json_pp

      16) Verify there is now another category Test3 as a child of the Test2 category.

      17) Run one more curl command, with data that is invalid.

      curl "http://moodlecore.lan/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategory&moodlewsrestformat=json&courseid={COURSEID}&fullname=Test4&options[grademax]=1&options[grademin]=2" | json_pp

      18) Verify that there  is no category ID returned, and that there is a warning for invalidgrade for item grademax.

      19) Verify that there is no Test4 Category created in the gradebook setup page.

       

      The rest is covered by unit tests

       

       

      Show
      Setup 1) Enable web services for the site, and enable the rest protocol. 2) Go to "Admin -> Plugins -> Web services -> External services" and add a service named 'gradecat, enabled, and add the function 'core_grades_create_gradecategory' to it. 3) Go to "Admin -> Plugins -> Web services -> Manage tokens" and add a token for the Admin user account and the just created "gradecat" service, so there are no permission issues. Annotate it for later use. 4) Create a blank test course to test the webservice in. Annotate its "courseid" from the url. 5) Visit the gradebook setup page for the newly created course. Testing 6) Open a terminal (with curl installed) 7) Execute the following command to call the webservice with basic parameters curl "http://moodlecore.lan/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategory&moodlewsrestformat=json&courseid={COURSEID}&fullname=Test" | json_pp (replacing TOKEN and COURSEID with the values annotated above) 8) Verify that the returned JSON in the terminal contains the field 'categoryid' with a number, and the warnings array is empty. Make note of the categoryid 9) Reload the gradebook setup, and verify that there is now a grade category underneath the course grade category, called 'Test'. 10) Execute the following command with the annotated token, courseid and categoryid from above. curl "http://moodlecore.lan/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategory&moodlewsrestformat=json&courseid={COURSEID}&fullname=Test2&options[parentcategoryid]={CATEGORYID}&options[idnumber]=IDNumber" | json_pp  11) Verify the returned JSON contains a similar response to the above command, with no warnings 12) Reload the gradebook setup and verify there is now a 'Test 2' category nested as a child of the 'Test category' 13) Edit the Test2 Gradecategory settings and confirm that the ID number field is set to 'IDNumber' 15) Repeat the same command as above, this time, specifying the idnumber of the parent category instead of the id. curl "http://moodlecore.lan/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategory&moodlewsrestformat=json&courseid={COURSEID}&fullname=Test3&options[parentcategoryidnumber]=IDNumber" | json_pp 16) Verify there is now another category Test3 as a child of the Test2 category. 17) Run one more curl command, with data that is invalid. curl "http://moodlecore.lan/webservice/rest/server.php?wstoken={TOKEN}&wsfunction=core_grades_create_gradecategory&moodlewsrestformat=json&courseid={COURSEID}&fullname=Test4&options[grademax]=1&options[grademin]=2" | json_pp 18) Verify that there  is no category ID returned, and that there is a warning for invalidgrade for item grademax. 19) Verify that there is no Test4 Category created in the gradebook setup page.   The rest is covered by unit tests    
    • Affected Branches:
      MOODLE_310_STABLE, MOODLE_38_STABLE, MOODLE_400_STABLE
    • Fixed Branches:
      MOODLE_310_STABLE
    • Pull Master Branch:
      MDL-67306-create-grade-category

      Description

      We would like to automatically create courses with grade categories, using api.

      The information we would like to pass along via api is the grade category name and the weighting, the rest can be left as site defaults.

      The grade categories are shells which will be filled with activities by lecturers throughout the semester.

      Example:

      Grade Category  1 2 3
      Category name Quizzes Tests Exam
      category weighting 20% 30% 50%

      Stage 2)

      At the end of the semester, we need to export the grade totals of the categories to our Student Management System.

      This is discussed in the forum https://moodle.org/mod/forum/discuss.php?d=393663.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              peterburnett Peter Burnett
              Reporter:
              wklein Witali Klein
              Integrator:
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Tester:
              Janelle Barcega Janelle Barcega
              Participants:
              Component watchers:
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan
              Votes:
              5 Vote for this issue
              Watchers:
              9 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                9/Nov/20

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 hours, 25 minutes
                  2h 25m