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

Create H5P activity web service to get the list of students that attempted an activity

XMLWordPrintable

    • MOODLE_39_STABLE
    • MOODLE_311_STABLE
    • MDL-69259-master
    • Hide
      1. Create a new user
      2. Navigate to site administration -> Users -> Permissions -> Define roles
      3. Create a new role with:
        • No archetyle
        • Contexts: System
        • Capabilities: mod/h5pactivity:reviewattempts
      4. Navigate to site administration -> Users -> Permissions -> Assign system roles
      5. Assign the new user to the role
      6. Enable webservices in site advanced features
      7. create a new external webservice
      8. Edit the web service
      9. Ensure that the "Enable" checkbox is ticked
      10. Save changes
      11. Click on the "Functions" link for the service
      12. add mod_h5pactivity_get_user_attempts function to it
      13. Save changes
      14. Navigate to site administration -> Plugins -> Web services -> External tokens
      15. Create a new token for the user against the new service
      16. Create a course
      17. Add h5pactivity to a course
      18. enrolL 3 users (with names Jake A, Bake B, Cake C)
      19. Add 2 attempts for user 1, 1 attempt for user 2 for h5pactivity
      20. Open the database and find the new activityid:

        select id from mdl_h5pactivity order by id desc limit 1;
        

      21. Call the webservice:

        curl 'http://YOURMOODLE/webservice/rest/server.php?moodlewsrestformat=json&wstoken=WSTOKEN&wsfunction=mod_h5pactivity_get_user_attempts&h5pactivityid=H5PACTIVITYID' | python -m "json.tool"
        

      22. Ensure result has following structure

        {
            "activityid": 4,
            "usersattempts": [
                {
                    "userid": 5,
                    "attempts": [
                        {
                            "id": 3,
                            "h5pactivityid": 4,
                            "userid": 5,
                            "timecreated": 1608124755,
                            "timemodified": 1608124755,
                            "attempt": 1,
                            "rawscore": 0,
                            "maxscore": 13,
                            "duration": 4,
                            "completion": 1,
                            "success": 0,
                            "scaled": 0
                        }
                    ],
                    "scored": {
                        "title": "Highest score attempt",
                        "grademethod": "1",
                        "attempts": [
                            {
                                "id": 3,
                                "h5pactivityid": 4,
                                "userid": 5,
                                "timecreated": 1608124755,
                                "timemodified": 1608124755,
                                "attempt": 1,
                                "rawscore": 0,
                                "maxscore": 13,
                                "duration": 4,
                                "completion": 1,
                                "success": 0,
                                "scaled": 0
                            }
                        ]
                    }
                },
                {
                    "userid": 19,
                    "attempts": []
                },
                {
                    "userid": 42,
                    "attempts": [
                        {
                            "id": 1,
                            "h5pactivityid": 4,
                            "userid": 42,
                            "timecreated": 1608124674,
                            "timemodified": 1608124674,
                            "attempt": 1,
                            "rawscore": 0,
                            "maxscore": 13,
                            "duration": 8,
                            "completion": 1,
                            "success": 0,
                            "scaled": 0
                        },
                        {
                            "id": 2,
                            "h5pactivityid": 4,
                            "userid": 42,
                            "timecreated": 1608124724,
                            "timemodified": 1608124725,
                            "attempt": 2,
                            "rawscore": 0,
                            "maxscore": 13,
                            "duration": 4,
                            "completion": 1,
                            "success": 0,
                            "scaled": 0
                        }
                    ],
                    "scored": {
                        "title": "Highest score attempt",
                        "grademethod": "1",
                        "attempts": [
                            {
                                "id": 2,
                                "h5pactivityid": 4,
                                "userid": 42,
                                "timecreated": 1608124724,
                                "timemodified": 1608124725,
                                "attempt": 2,
                                "rawscore": 0,
                                "maxscore": 13,
                                "duration": 4,
                                "completion": 1,
                                "success": 0,
                                "scaled": 0
                            }
                        ]
                    }
                }
            ],
            "warnings": []
        }

      23. Ensure it returns info for 3 users (you can see all userids)
      24. Ensure User 1 has 2 attempts, User 2 has 1 attempt and User 3 has no attempts returned
      25. Call a webservice with firstname filter:

        curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json&wstoken=YOURTOKEN&wsfunction=mod_h5pactivity_get_user_attempts&h5pactivityid=H5PACTIVITYID&firstinitial=L' | python -m "json.tool"
        
        

      26. Ensure only user 1 is returned
      27. Ensure result has following structure

        {
            "activityid": 4,
            "usersattempts": [
                {
                    "userid": 42,
                    "attempts": [
                        {
                            "id": 1,
                            "h5pactivityid": 4,
                            "userid": 42,
                            "timecreated": 1608124674,
                            "timemodified": 1608124674,
                            "attempt": 1,
                            "rawscore": 0,
                            "maxscore": 13,
                            "duration": 8,
                            "completion": 1,
                            "success": 0,
                            "scaled": 0
                        },
                        {
                            "id": 2,
                            "h5pactivityid": 4,
                            "userid": 42,
                            "timecreated": 1608124724,
                            "timemodified": 1608124725,
                            "attempt": 2,
                            "rawscore": 0,
                            "maxscore": 13,
                            "duration": 4,
                            "completion": 1,
                            "success": 0,
                            "scaled": 0
                        }
                    ],
                    "scored": {
                        "title": "Highest score attempt",
                        "grademethod": "1",
                        "attempts": [
                            {
                                "id": 2,
                                "h5pactivityid": 4,
                                "userid": 42,
                                "timecreated": 1608124724,
                                "timemodified": 1608124725,
                                "attempt": 2,
                                "rawscore": 0,
                                "maxscore": 13,
                                "duration": 4,
                                "completion": 1,
                                "success": 0,
                                "scaled": 0
                            }
                        ]
                    }
                }
            ],
            "warnings": []
        }
        

      Show
      Create a new user Navigate to site administration -> Users -> Permissions -> Define roles Create a new role with: No archetyle Contexts: System Capabilities: mod/h5pactivity:reviewattempts Navigate to site administration -> Users -> Permissions -> Assign system roles Assign the new user to the role Enable webservices in site advanced features create a new external webservice Edit the web service Ensure that the "Enable" checkbox is ticked Save changes Click on the "Functions" link for the service add mod_h5pactivity_get_user_attempts function to it Save changes Navigate to site administration -> Plugins -> Web services -> External tokens Create a new token for the user against the new service Create a course Add h5pactivity to a course enrolL 3 users (with names Jake A, Bake B, Cake C) Add 2 attempts for user 1, 1 attempt for user 2 for h5pactivity Open the database and find the new activityid: select id from mdl_h5pactivity order by id desc limit 1; Call the webservice: curl 'http://YOURMOODLE/webservice/rest/server.php?moodlewsrestformat=json&wstoken=WSTOKEN&wsfunction=mod_h5pactivity_get_user_attempts&h5pactivityid=H5PACTIVITYID' | python -m "json.tool" Ensure result has following structure { "activityid" : 4 , "usersattempts" : [ { "userid" : 5 , "attempts" : [ { "id" : 3 , "h5pactivityid" : 4 , "userid" : 5 , "timecreated" : 1608124755 , "timemodified" : 1608124755 , "attempt" : 1 , "rawscore" : 0 , "maxscore" : 13 , "duration" : 4 , "completion" : 1 , "success" : 0 , "scaled" : 0 } ], "scored" : { "title" : "Highest score attempt" , "grademethod" : "1" , "attempts" : [ { "id" : 3 , "h5pactivityid" : 4 , "userid" : 5 , "timecreated" : 1608124755 , "timemodified" : 1608124755 , "attempt" : 1 , "rawscore" : 0 , "maxscore" : 13 , "duration" : 4 , "completion" : 1 , "success" : 0 , "scaled" : 0 } ] } }, { "userid" : 19 , "attempts" : [] }, { "userid" : 42 , "attempts" : [ { "id" : 1 , "h5pactivityid" : 4 , "userid" : 42 , "timecreated" : 1608124674 , "timemodified" : 1608124674 , "attempt" : 1 , "rawscore" : 0 , "maxscore" : 13 , "duration" : 8 , "completion" : 1 , "success" : 0 , "scaled" : 0 }, { "id" : 2 , "h5pactivityid" : 4 , "userid" : 42 , "timecreated" : 1608124724 , "timemodified" : 1608124725 , "attempt" : 2 , "rawscore" : 0 , "maxscore" : 13 , "duration" : 4 , "completion" : 1 , "success" : 0 , "scaled" : 0 } ], "scored" : { "title" : "Highest score attempt" , "grademethod" : "1" , "attempts" : [ { "id" : 2 , "h5pactivityid" : 4 , "userid" : 42 , "timecreated" : 1608124724 , "timemodified" : 1608124725 , "attempt" : 2 , "rawscore" : 0 , "maxscore" : 13 , "duration" : 4 , "completion" : 1 , "success" : 0 , "scaled" : 0 } ] } } ], "warnings" : [] } Ensure it returns info for 3 users (you can see all userids) Ensure User 1 has 2 attempts, User 2 has 1 attempt and User 3 has no attempts returned Call a webservice with firstname filter: curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json&wstoken=YOURTOKEN&wsfunction=mod_h5pactivity_get_user_attempts&h5pactivityid=H5PACTIVITYID&firstinitial=L' | python -m "json.tool" Ensure only user 1 is returned Ensure result has following structure { "activityid" : 4 , "usersattempts" : [ { "userid" : 42 , "attempts" : [ { "id" : 1 , "h5pactivityid" : 4 , "userid" : 42 , "timecreated" : 1608124674 , "timemodified" : 1608124674 , "attempt" : 1 , "rawscore" : 0 , "maxscore" : 13 , "duration" : 8 , "completion" : 1 , "success" : 0 , "scaled" : 0 }, { "id" : 2 , "h5pactivityid" : 4 , "userid" : 42 , "timecreated" : 1608124724 , "timemodified" : 1608124725 , "attempt" : 2 , "rawscore" : 0 , "maxscore" : 13 , "duration" : 4 , "completion" : 1 , "success" : 0 , "scaled" : 0 } ], "scored" : { "title" : "Highest score attempt" , "grademethod" : "1" , "attempts" : [ { "id" : 2 , "h5pactivityid" : 4 , "userid" : 42 , "timecreated" : 1608124724 , "timemodified" : 1608124725 , "attempt" : 2 , "rawscore" : 0 , "maxscore" : 13 , "duration" : 4 , "completion" : 1 , "success" : 0 , "scaled" : 0 } ] } } ], "warnings" : [] }
    • Moppies Kanban

      We need a WS for the teacher to get the list of students that attempted an H5P activity similar to what they can view in the web interface.

            ilyatregubov Ilya Tregubov
            dpalou Dani Palou
            Carlos Escobedo Carlos Escobedo
            Andrew Lyons Andrew Lyons
            Anna Carissa Sadia Anna Carissa Sadia
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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