Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Quiz web services

From MoodleDocs

This is only Development Proposal. Functionality is not currently developed.

Comments ? Please join the discussion topic in the forum.

Summary / Purpose

The Quiz web services would allow an external application to retrieve some quiz's questions (and attempt(s) optionally) for an user. The original idea behind this is to be able to build a flash application that would build the quiz dynamically depending on what data moodle sends it, however it might have other applications, since it would allow any application to request questions from moodle in any export format available.

API

get_quiz(format, quiz_id [, summary_view ])

  • returns a quiz with all questions

get_quizzes_by_course(format, course_id)

  • returns an array of quizzes in summary view (only an array of question ids/title and not all the questions)

get_question(format, question_id)

  • returns a question

get_questions_by_course(format, course_id [, summary_view ])

  • returns all questions for the given course, with all details or only titles if summary is true

get_questions_by_quiz(format, quiz_id [, load_attempt [, user_id [, summary_view ]]])

  • returns all questions for the given quiz, with all details or only titles if summary is true
  • user attempt (if set to -1 -> last attempt, if set to a positive integer -> attempt based on that id, 0 = don't load) is loaded and overrides default values for questions
  • user attempt is loaded for the currently authenticated user, or the given user id (if authenticated as admin only)

get_questions_by_category(format, category_id [, summary_view ])

  • returns all questions for the given category, with all details or only titles if summary is true

get_category(format, id)

  • returns one category with all details (is this useful?)

get_categories_by_course(format, course_id)

  • returns all categories for the given course

get_categories_by_quiz(format, quiz_id)

  • returns all categories for the given quiz

Security Concerns

Access to answers should be restricted to the current user, otherwise someone could gain access to answers of other people, which would allow cheating and possible access to answers that contain private data.

Therefore, unless someone can be authenticated as an admin, he probably shouldn't have access to any attempt except his, and if the user has no authentication whatsoever, I am not sure what should happen ? Is it okay to send the question data ? I guess that depends on the context.

I am not certain how authentication is handled at the moment in other web services, I guess it can be a problem depending on where the request is coming from.. I know that with flash it is not a problem because if the browser has a cookie for your domain, it will send it with the request and moodle can authentify the user with that.

Implementation Details

  • I am not sure whether this should reside within /mod/quiz or /questions, since it uses a bit of both.
  • The export format, which is a parameter in the API, would ideally be one of the various export format that questions support. In our case we need IMS QTI2, and that standard can handle "attempts" data, but I'm not sure about other formats, nor if we should re-use the questions's export formats or just build new ones from scratch to support all of this, since the question stuff doesn't support attempts and we can't really modify it to do so because questions are exported without attempts data in moodle's admin section.


Comments ? Please join the discussion topic in the forum.