Show
Enable webservices in site advanced features
create external webservice and enable it
add mod_h5pactivity_get_user_attempts function to it
create webservice user
create a token
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
Call a 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" : []
}