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

New web Services for checking access requirements to quizzes and attempts

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.1
    • 3.0.2, 3.1
    • Quiz, Web Services
    • MOODLE_30_STABLE, MOODLE_31_STABLE
    • MOODLE_31_STABLE
    • MDL-52767-master
    • Hide
      1. Bump your /version.php file to force Moodle to reload the Mobile service
      2. Create a course with a student.
      3. Create a new quiz with 3 different question types, the last one should be a random question type pointing to a category with at least two different question types
      4. As admin, enable "Mobile services": Plugins ► Web Services ► Mobile
      5. Create a Token for the student user
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      6. Next, you can do a CURL REST call simulating a WS client with the student user .
        • You need to replace the wstoken, quizid (the quiz instance value) and the URL of your moodle instance

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_quiz_access_information&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed

      7. Confirm that
        • You see the following values to true: canattempt, canreviewmyattempts
      8. Execute the following curl request

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_quiz_required_qtypes&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed

      9. And check that you receive all the question types used, including the ones in the random category
      10. Now as admin or teacher edit the quiz settings, add a password restriction, limit the number of attempts two 1 and add a future date for time open and time close
      11. Run the WS again, check that now: in accessrules you see listed all the new settings you applied, in preventaccessreasons you see "This quiz is not currently available" (because is not open yet)
      12. Now, as admin, remove all the restrictions except the attempt number that must be 1
      13. Now, as the student, access the Moodle web interface and do the quiz one time (do one attempt and ensure that is finished)
      14. Run the following query using the student token again

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_attempt_access_information&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed

      15. You should see that preventnewattemptreasons says "No more attempts are allowed" and isfinished set to true
      Show
      Bump your /version.php file to force Moodle to reload the Mobile service Create a course with a student. Create a new quiz with 3 different question types, the last one should be a random question type pointing to a category with at least two different question types As admin, enable "Mobile services": Plugins ► Web Services ► Mobile Create a Token for the student user Click on Site administration ► Plugins ► Web services ► Manage tokens Next, you can do a CURL REST call simulating a WS client with the student user . You need to replace the wstoken, quizid (the quiz instance value) and the URL of your moodle instance curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_quiz_access_information&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed Confirm that You see the following values to true: canattempt, canreviewmyattempts Execute the following curl request curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_quiz_required_qtypes&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed And check that you receive all the question types used, including the ones in the random category Now as admin or teacher edit the quiz settings, add a password restriction, limit the number of attempts two 1 and add a future date for time open and time close Run the WS again, check that now: in accessrules you see listed all the new settings you applied, in preventaccessreasons you see "This quiz is not currently available" (because is not open yet) Now, as admin, remove all the restrictions except the attempt number that must be 1 Now, as the student, access the Moodle web interface and do the quiz one time (do one attempt and ensure that is finished) Run the following query using the student token again curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'quizid=2&wsfunction=mod_quiz_get_attempt_access_information&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' --compressed You should see that preventnewattemptreasons says "No more attempts are allowed" and isfinished set to true

      This function returns general access information, is basically a wrapper of the access manager class that returns some capabilities information too.

      Information returned will be:

      canmanage
      canattempt
      canreviewmine
      canpreview
      canviewreports
      canreviewmyattempts
      endtime
      isfinished
      ispreflightcheckrequired
      accessrules
      preventaccessreasons
      preventnewattemptreasons

      This web service also returns the question types used in the quiz, including the potential ones (in case random questions are used).
      This is necessary because we'll need to check the question types before starting a new attempt to determine if the quiz can be open in the app (initially the app won't support all question types or contrib add-ons)

      Please, note that we finally decided to split in 3 functions:

      • mod_quiz_get_quiz_access_information
      • mod_quiz_get_attempt_access_information
      • mod_quiz_get_quiz_required_qtypes

            jleyva Juan Leyva
            jleyva Juan Leyva
            Tim Hunt Tim Hunt
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Simey Lameze Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

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