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

mod_survey_get_surveys_by_courses

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 2.9
    • Survey, Web Services
    • None
    • MOODLE_29_STABLE
    • MDL-50548-master
    • Hide

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

      1. Create 2 courses and enroll student1 to the first course (FIRST-COURSE)
      2. add a Survey to the first course
      3. add a Survey to the second course
      4. as student1 call mod_survey_get_surveys_by_courses(array())
      5. when you do not specify any courseid, you will retrieve all Surveys belonging to your enrolled courses
      1. Create a Token for Student1 :
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      2. Next, you can do a couple of CURL REST call simulating a WS client as Student

      curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_survey_get_surveys_by_courses&wstoken=55a2a34c00e88f0b8765cc16c66b421e' --compressed

      1. The webservice should return this kind of result:

      {"surveys":[{"id":6,"coursemodule":16,"course":"2","name":"Survey Attitudes","intro":"<p><span style=\"color:rgb(89,89,89);font-family:'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:24px;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;background-color:rgb(255,255,255);\">Attitudes to Thinking and Learning Survey<\/span><br \/><\/p>","introformat":1,"template":4,"days":0,"timecreated":"1436451446","timemodified":"1436451446","questions":"65,67,68","section":0,"visible":true,"groupmode":0,"groupingid":0}],"warnings":[]}
      

      1. Some properties are reserved to admins (who posses moodle/course:manageactivities capability)
        section
        visible
        groupmode
        groupingid
      2. You need mod/survey:participate capability to see see this activity,
      3. when you miss this capability a warning message (warningcode=2) will be returned
      4. In order to verify the WS really uses this capability:
      5. Go to the Dashboard / ► Courses / ► FIRST-COURSE / ► Users / ► Permissions / ► Override roles
        and set the "mod/survey:participate" as Prohibit for Students
      6. Now, when you try to call this WS again (as student) you should receive a warningcode=2
      7. as student, you can also try to pass a course->id you are not enrolled in, in this case you will receive a warningcode=1

        {"surveys":[],"warnings":[{"item":"course","itemid":3,"warningcode":"1","message":"No access rights in course context Course or activity not accessible."}]}
        

      8. When an inexistent course id is specified the WS returns an empty result
      Show
      Note: Version number is bumped because a new web service is added into the Mobile app service. Create 2 courses and enroll student1 to the first course (FIRST-COURSE) add a Survey to the first course add a Survey to the second course as student1 call mod_survey_get_surveys_by_courses(array()) when you do not specify any courseid, you will retrieve all Surveys belonging to your enrolled courses Create a Token for 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 curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_survey_get_surveys_by_courses&wstoken=55a2a34c00e88f0b8765cc16c66b421e' --compressed The webservice should return this kind of result: {"surveys":[{"id":6,"coursemodule":16,"course":"2","name":"Survey Attitudes","intro":"<p><span style=\"color:rgb(89,89,89);font-family:'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:24px;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;background-color:rgb(255,255,255);\">Attitudes to Thinking and Learning Survey<\/span><br \/><\/p>","introformat":1,"template":4,"days":0,"timecreated":"1436451446","timemodified":"1436451446","questions":"65,67,68","section":0,"visible":true,"groupmode":0,"groupingid":0}],"warnings":[]} Some properties are reserved to admins (who posses moodle/course:manageactivities capability) section visible groupmode groupingid You need mod/survey:participate capability to see see this activity, when you miss this capability a warning message (warningcode=2) will be returned In order to verify the WS really uses this capability: Go to the Dashboard / ► Courses / ► FIRST-COURSE / ► Users / ► Permissions / ► Override roles and set the "mod/survey:participate" as Prohibit for Students Now, when you try to call this WS again (as student) you should receive a warningcode=2 as student, you can also try to pass a course->id you are not enrolled in, in this case you will receive a warningcode=1 {"surveys":[],"warnings":[{"item":"course","itemid":3,"warningcode":"1","message":"No access rights in course context Course or activity not accessible."}]} When an inexistent course id is specified the WS returns an empty result

      Retrieve a list of surveys from several courses

            jleyva Juan Leyva
            ccito Costantino Cito
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

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