Hide
Note: Version number is bumped because a new web service is added into the Mobile app service.
- create a course with a choice/activity
- set timeopen and timeclose as a future dates
- mark the Show Preview checkbox
- create 3 possible options for this choice
- create a student (student1)
- enroll student1 to this course
- Create a Token for the Student1:
- Click on Site administration ► Plugins ► Web services ► Manage tokens
- Next, you can do a couple of CURL REST call simulating a WS client as Student
- As student1 call get_choice_options()
- using a curl call as in the following example:
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' -H 'Pragma: no-cache' -H 'Origin: file://' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: es,en;q=0.8,de-DE;q=0.6,de;q=0.4,nb;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1798.0 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, /; q=0.01' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data 'wsfunction=mod_choice_get_choice_options&choiceinstanceid=4&wstoken=19d196c6b5e94efb8c84dd534c1f9018' --compressed
- The webservice should return this kind of result:
{"options":[{"id":1,"text":"PIZZA MARGHERITA","maxanswers":3,"displaylayout":false,"countanswers":1,"checked":false,"disabled":false},{"id":2,"text":"PIZZA 4 FORMAGGI","maxanswers":2,"displaylayout":false,"countanswers":2,"checked":false,"disabled":true},{"id":3,"text":"PIZZA DIAVOLA","maxanswers":2,"displaylayout":false,"countanswers":1,"checked":true,"disabled":false}],"warnings":[]}
|
- The webservice will return all the options (but the disabled property will be true)
- disabled = true, means we can see options but we cannot submit a response
- Open the choice activity by setting the timeclose as a future date
- Now as student1 choose a response between the available options
- call the webservice
- now the "checked" property will be true for that option you just choosed
- When the activity option setting: "Allow choice to be updated" is set as NO but you already submitted your response, you will also see all options as disabled=true
- If you close the activity by setting timeclose as a past day and call the webservice, you will receive a warning message advising you this activity has expired
- set the activity option setting "Publish Results" as "Show results to students only after the choice is closed"
- in this case the webservice will return an exception error, as we cannot see results until the activity closes
- set the activity option setting "Privacy of results" as "Publish anonymous results, do not show student names" will make the webservice hiding the userresponses
( you will still be able to see useful properties like numberofuser and percentageamount )
Show
Note: Version number is bumped because a new web service is added into the Mobile app service.
create a course with a choice/activity
set timeopen and timeclose as a future dates
mark the Show Preview checkbox
create 3 possible options for this choice
create a student (student1)
enroll student1 to this course
Create a Token for the Student1:
Click on Site administration ► Plugins ► Web services ► Manage tokens
Next, you can do a couple of CURL REST call simulating a WS client as Student
As student1 call get_choice_options()
using a curl call as in the following example:
curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' -H 'Pragma: no-cache' -H 'Origin: file:// ' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: es,en;q=0.8,de-DE;q=0.6,de;q=0.4,nb;q=0.2' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1798.0 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, / ; q=0.01' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data 'wsfunction=mod_choice_get_choice_options&choiceinstanceid=4&wstoken=19d196c6b5e94efb8c84dd534c1f9018' --compressed
The webservice should return this kind of result:
{"options":[{"id":1,"text":"PIZZA MARGHERITA","maxanswers":3,"displaylayout":false,"countanswers":1,"checked":false,"disabled":false},{"id":2,"text":"PIZZA 4 FORMAGGI","maxanswers":2,"displaylayout":false,"countanswers":2,"checked":false,"disabled":true},{"id":3,"text":"PIZZA DIAVOLA","maxanswers":2,"displaylayout":false,"countanswers":1,"checked":true,"disabled":false}],"warnings":[]}
The webservice will return all the options (but the disabled property will be true)
disabled = true, means we can see options but we cannot submit a response
Open the choice activity by setting the timeclose as a future date
Now as student1 choose a response between the available options
call the webservice
now the "checked" property will be true for that option you just choosed
When the activity option setting: "Allow choice to be updated" is set as NO but you already submitted your response, you will also see all options as disabled=true
If you close the activity by setting timeclose as a past day and call the webservice, you will receive a warning message advising you this activity has expired
set the activity option setting "Publish Results" as "Show results to students only after the choice is closed"
in this case the webservice will return an exception error, as we cannot see results until the activity closes
set the activity option setting "Privacy of results" as "Publish anonymous results, do not show student names" will make the webservice hiding the userresponses
( you will still be able to see useful properties like numberofuser and percentageamount )