Show
Note: Version numbers are bumped because a new web service is added into the Mobile app service and also in the module.
Create a new course enrolling a couple of users with student and teacher role.
Create a survey activity (for example, COLLES Preferred that includes different types of questions).
As student, complete the survey (be sure to remember or save the responses you choose)
As teacher, open the survey and go to "View 1 survey responses"
Now, go option by option and ensure that all the graphs in summary, scales and questions display correct data
Now, go to Participants to see the user responses and ensure that all the responses are correct and the graphs are correctly created and that you can see the rest of responses.
Now, create a different course with a teacher and a student.
Create a couple of survey activities (COLLES Preferred type). Hide one of the activities.
Enable "Mobile services": Plugins ► Web Services ► Mobile
Create a Token for the teacher and the student:
Click on Site administration ► Plugins ► Web services ► Manage tokens
Next, you can do a couple of CURL REST call simulating a WS client with the student and the teacher user.
You need to replace the wstoken and the URL of your moodle instance:
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_survey_get_surveys_by_courses&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool"
Confirm that
As student you only see the visible survey activity, and you see all the survey configuration settings except the one reserved for managers (you should see only: id, coursemodule, course, name, intro, introformat, template, days, questions, surveydone)
As a teacher you see all the survey activities and all the settings
You can also specify which courses to retrieve, (replace courseids..5 with a valid number in this request)
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'courseids%5B0%5D=5&wsfunction=mod_survey_get_surveys_by_courses&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool"
If you use a course id where you are not enrolled, you will receive a warning "No access rights in course context"
Now, log in as the student and visit the visible survey activity
Log in as teacher and check that the student action generated a new entry in the logs (activity -> logs)
Do the following request:
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'surveyid=10&wsfunction=mod_survey_view_survey&wstoken=ffbe3a3002f235bf9d01fd9369e10b66'
Confirm that
You can see new entries in the course log (survey course module viewed) for that course and the user. The origin for the new log entries is "ws"
Now, we are going to retrieve al the questions for the survey:
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'surveyid=10&wsfunction=mod_survey_get_questions&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool"
Confirm that you receive the same questions that are visible in the Moodle web interface
Now, we are going to submit the responses (note, that the answer key values may vary from installation if you are using a DB different that MySQL, I tested in MySQL and they are always the same qP1 to qP24 and q43 and q44):
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'surveyid=10&wsfunction=mod_survey_submit_answers&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&answers%5B0%5D%5Bkey%5D=qP1&answers%5B0%5D%5Bvalue%5D=1&answers%5B1%5D%5Bkey%5D=qP2&answers%5B1%5D%5Bvalue%5D=2&answers%5B2%5D%5Bkey%5D=qP3&answers%5B2%5D%5Bvalue%5D=3&answers%5B3%5D%5Bkey%5D=qP4&answers%5B3%5D%5Bvalue%5D=4&answers%5B4%5D%5Bkey%5D=qP5&answers%5B4%5D%5Bvalue%5D=1&answers%5B5%5D%5Bkey%5D=qP6&answers%5B5%5D%5Bvalue%5D=2&answers%5B6%5D%5Bkey%5D=qP7&answers%5B6%5D%5Bvalue%5D=3&answers%5B7%5D%5Bkey%5D=qP8&answers%5B7%5D%5Bvalue%5D=4&answers%5B8%5D%5Bkey%5D=qP9&answers%5B8%5D%5Bvalue%5D=1&answers%5B9%5D%5Bkey%5D=qP10&answers%5B9%5D%5Bvalue%5D=2&answers%5B10%5D%5Bkey%5D=qP11&answers%5B10%5D%5Bvalue%5D=3&answers%5B11%5D%5Bkey%5D=qP12&answers%5B11%5D%5Bvalue%5D=4&answers%5B12%5D%5Bkey%5D=qP13&answers%5B12%5D%5Bvalue%5D=1&answers%5B13%5D%5Bkey%5D=qP14&answers%5B13%5D%5Bvalue%5D=2&answers%5B14%5D%5Bkey%5D=qP15&answers%5B14%5D%5Bvalue%5D=3&answers%5B15%5D%5Bkey%5D=qP16&answers%5B15%5D%5Bvalue%5D=4&answers%5B16%5D%5Bkey%5D=qP17&answers%5B16%5D%5Bvalue%5D=1&answers%5B17%5D%5Bkey%5D=qP18&answers%5B17%5D%5Bvalue%5D=2&answers%5B18%5D%5Bkey%5D=qP19&answers%5B18%5D%5Bvalue%5D=3&answers%5B19%5D%5Bkey%5D=qP20&answers%5B19%5D%5Bvalue%5D=4&answers%5B20%5D%5Bkey%5D=qP21&answers%5B20%5D%5Bvalue%5D=1&answers%5B21%5D%5Bkey%5D=qP22&answers%5B21%5D%5Bvalue%5D=2&answers%5B22%5D%5Bkey%5D=qP23&answers%5B22%5D%5Bvalue%5D=3&answers%5B23%5D%5Bkey%5D=qP24&answers%5B23%5D%5Bvalue%5D=4&answers%5B24%5D%5Bkey%5D=q43&answers%5B24%5D%5Bvalue%5D=1&answers%5B25%5D%5Bkey%5D=q44&answers%5B25%5D%5Bvalue%5D=nocomments'
Confirm, that you recive status: true as response and empty warnings
Now, in the Web Interface go to the Participant -> your student report for the survey (/mod/survey/report.php?action=student&student=106&id=141) and check that for each group of questions (Relevance, Reflective thinking, Interactivity, etc...) the responses go from 1 to 4 (almost never -> often), increasing one level per question in the group (see attached screenshot)