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

Web Services for mod_choice

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.9
    • Fix Version/s: 3.0
    • Component/s: Choice, Web Services
    • Labels:
    • Testing Instructions:
      Hide

      Note: Version number is bumped because a new web service is added into the Mobile app service.

      1. create a course with a choice/activity
      2. set timeopen as a past date and timeclose as a future date
      3. set the activity option Publish Results as "Show results to students after they answer"
      4. set the activity option Privacy of results as "Publish full results, showing names and their choices"
      5. Set Show column for unanswered to yes
      6. create 3 possible options for this choice
      7. create two students (student1 and student2)
      8. enroll both students to the course
      9. as student1 choose a response between the possible options
      10. Create a Token for the Student1 and Student2:
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      11. Next, you can do a couple of CURL REST call simulating a WS client as Student
      12. As student1 call get_choice_results()
      13. using a curl call as in the following example:

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_choice_get_choice_results&choiceid=2&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed | python -m "json.tool"

      14. the result of the webservice call should show all the possible options, plus the option (ID = 0) which reports a list of users who did not answered yet
      15. verify that student1 is listed into the option's userresponses property for the correct option
      16. verify that student2 is listed into the option's userresponses property of the option zero (as he did not choose any response)
      17. set the activity option Publish Results as "Show results to students only after the choice is closed"
      18. in this case the webservice will not return the results (only empty data)
      19. set the activity option 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 )
      20. As student1 call get_choice_options()
      21. using a curl call as in the following example:

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_choice_get_choice_options&choiceid=2&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed | python -m "json.tool"

      22. The webservice will return all the options (but the disabled property will be true for you already answered option)
      23. disabled = true, means we can see options but we cannot submit a response
      24. 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
      25. 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
      26. Now, you are going to submit a response. Ensure that the choice settings allow to submit responses.
      27. Do a CURL REST call simulating a WS client as Student2 (remember to use the token for student2), replace the responses[] value with a valid id from the choice_options table

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_choice_submit_choice_response&choiceid=2&responses[]=2&wstoken=951d09b2dab585a8e3141ad66744206f' --compressed

      28. The webservice should return this kind of result:

        {"answers":[{"id":12,"choiceid":1,"userid":8,"optionid":3,"timemodified":1433516029}],"warnings":[]}
        

      29. For each response you successfully submitted you will receive back those records the webservice just added into the answers table.
      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 as a past date and timeclose as a future date set the activity option Publish Results as "Show results to students after they answer" set the activity option Privacy of results as "Publish full results, showing names and their choices" Set Show column for unanswered to yes create 3 possible options for this choice create two students (student1 and student2) enroll both students to the course as student1 choose a response between the possible options Create a Token for the Student1 and Student2: 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_results() using a curl call as in the following example: curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_choice_get_choice_results&choiceid=2&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed | python -m "json.tool" the result of the webservice call should show all the possible options, plus the option (ID = 0) which reports a list of users who did not answered yet verify that student1 is listed into the option's userresponses property for the correct option verify that student2 is listed into the option's userresponses property of the option zero (as he did not choose any response) set the activity option Publish Results as "Show results to students only after the choice is closed" in this case the webservice will not return the results (only empty data) set the activity option 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 ) 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' --data 'wsfunction=mod_choice_get_choice_options&choiceid=2&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed | python -m "json.tool" The webservice will return all the options (but the disabled property will be true for you already answered option) disabled = true, means we can see options but we cannot submit a response 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 Now, you are going to submit a response. Ensure that the choice settings allow to submit responses. Do a CURL REST call simulating a WS client as Student2 (remember to use the token for student2), replace the responses[] value with a valid id from the choice_options table curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_choice_submit_choice_response&choiceid=2&responses[]=2&wstoken=951d09b2dab585a8e3141ad66744206f' --compressed The webservice should return this kind of result: {"answers":[{"id":12,"choiceid":1,"userid":8,"optionid":3,"timemodified":1433516029}],"warnings":[]} For each response you successfully submitted you will receive back those records the webservice just added into the answers table.
    • Affected Branches:
      MOODLE_29_STABLE
    • Fixed Branches:
      MOODLE_30_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-50944-master

      Description

      Implement a set of Web Services for the mod_choice:

      1. mod_choice_get_choice_options
      2. mod_choice_submit_choice_response
      3. mod_choice_get_choice_results
      4. mod_choice_view_choice

      This will fix issues: MDL-50137 MDL-50138 and MDL-50139

        Attachments

          Activity

            People

            • Assignee:
              jleyva Juan Leyva
              Reporter:
              jleyva Juan Leyva
              Peer reviewer:
              Adrian Greeve
              Integrator:
              Dan Poltawski
              Tester:
              Dan Poltawski
              Participants:
              Component watchers:
              Dan Marsden, Jake Dallimore, Jun Pataleta, Ryan Wyllie, Juan Leyva, Jake Dallimore, Jun Pataleta, Ryan Wyllie
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                16/Nov/15