Mobile web service quiz documentation

Mobile web service quiz documentation

by Jan Philipp Weber -
Number of replies: 15
Hello!

At the moment I develop a webapp with PHP, designed for mobile devices and works with mobile web services. The quiz web service is really new, so the documentation is not helpful and I have the problem, that I don't know how can I response right way the quiz functions.

The main problem is, that if I get the respone from the "mod_quiz_get_attempt_data", in the data is the html field, but how can I get this in my view and how can I implement functions like autosave, finish test etc.?


I looked at the moodle mobile app(v2), but the project is too huge, where I cannot understand how the web services response and the

further processed works without documentation.

https://github.com/moodlehq/moodlemobile2
own Moodle site: API Documentation

Average of ratings: -
In reply to Jan Philipp Weber

Re: Mobile web service quiz documentation

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Jan Philipp,

the quiz is a really complex module and it's really hard to understand how everything works. I agree that the documentation could be better, but even if it was you'd still have to look at some code to be able to understand how everything works.

My first advice is to play with the WebServices, create several quizzes with different configurations and then call the WebServices and see what they're returning. I guess you already know it, but you can see the WebServices details in:

Site administration ▶︎ Plugins ▶︎ Web services ▶︎ API Documentation

The first thing you need to know is that the quiz depends on questions, a different component. Questions have some subplugins: question type and question behaviour. Also, the quiz itself has some subplugins: access rules.

We implemented all that in the app:

  • Question component: www/core/components/question
  • Question types: www/addons/qtype
  • Question behaviour: www/addons/qbehaviour
  • Quiz access rules: www/addons/mod/quiz/accessrules
  • Quiz component: www/addons/mod/quiz

All the WebService calls are performed in the following files:

www/addons/mod/quiz/services/quiz.js
www/addons/mod/quiz/services/quiz_online.js

In the app what we do is parse the HTML of the questions and then render it in the view. It's important to keep the same name as the original inputs. When the user clicks submit, we get the data of all the inputs and send it to Moodle.

If you want to implement this you'll have to take a look at how Moodle quiz works and try to simulate it, it's what we do when we implement something in the app.

I'm sorry for not being able to explain it in more detail, but it's really complex and it's impossible to explain it all. You should try to look at each feature by itself and try to mimic it in your system.

Kind regards,

Dani

In reply to Dani Palou

Re: Mobile web service quiz documentation

by Jan Philipp Weber -

Thanks for your fast answer Daniel.

Your explanations are helpful and I'll try to understanding the construction with testing and simulatingsmile

Best regards,

Jan Philipp


In reply to Dani Palou

Re: Mobile web service quiz documentation

by Jan Philipp Weber -

I have a question regarding to the get quiz and save quiz.

To get the quiz content,I call "mod_quiz_get_attempt_data", all right here.

But on the view, if I change the answer for example to true and save it with "mod_quiz_save_attempt" ( the response of the function is true,  and I trigger it with "mod_quiz_view_attempt")  and go to next page and back, the stored answer will (load with "mod_quiz_get_attempt_data") not display.


What is here my error? How can I display my stored answer?


A second question regarding to picture/videos.


If I request the quiz question with "mod_quiz_get_attempt_data", the URL of the picture/videos is not right. Normally it should have "webservice/pluginfile.php/..." but it is not the webservice link. A API bug? With the URL which I get, I cannot view the picture/video.

In reply to Jan Philipp Weber

Re: Mobile web service quiz documentation

by Jan Philipp Weber -
I solved question one, I forget to save "sequencecheck". mixed
In reply to Jan Philipp Weber

Re: Mobile web service quiz documentation

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Jan Philipp,

please make sure you're sending this parameter to the WebService:

moodlewssettingfilter=true

Can you please paste one of the URLs in here so I can see how it looks like? You can remove your domain if you want to, I'm interested in the path.

Cheers,

Dani

In reply to Dani Palou

Re: Mobile web service quiz documentation

by Jan Philipp Weber -

Hello Daniel,


thanks for your suggestion, I have implemented it, but the link is the same in 'html':

https://mymoodle.com/pluginfile.php/27/question/questiontext/851/1/18/WP_20151224_18_29_03_Pro__highres.jpg


best greetings,

Jan Philipp

Attachment function.jpg
In reply to Jan Philipp Weber

Re: Mobile web service quiz documentation

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Jan Philipp,

I checked the WebService response and I'm receiving the URLs without the webservice folder too. I guess this is because the WebService uses the same rendering functions as Moodle web.

We have a function in the mobile app to fix these URLs and make them work, we apply it to all URLs received from Moodle:

https://github.com/moodlehq/moodlemobile2/blob/master/www/core/lib/util.js#L224

I guess you'll have to do something similar.

Cheers,

Dani

In reply to Dani Palou

Re: Mobile web service quiz documentation

by Jan Philipp Weber -

Hi Daniel,

thanks, I implemented it and it worked, nice is something elselächelnd

But this cannot be the final solution, because it is practically a bug by the WebService? Normally, if I request something from the WebService, it should be send correct in the right format.


Best regards,

Jan Philipp



In reply to Jan Philipp Weber

Re: Mobile web service quiz documentation

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi Jan,

in this case the rendering of the quiz questions is done by the question API that is not aware that the request is coming from Moodle Web or the Web Service server.

We are aware of that issue but it doesn't have an easy solution, since is not a big deal and is something common in old APIs, the fix that we applied is just fix the urls when they are received.

Is far from ideal, but I said before, refactoring the complete question API for that will be a huge task (more than implementing the quiz player itself)

Regards, Juan

In reply to Juan Leyva

Re: Mobile web service quiz documentation

by Jan Philipp Weber -

Hi Juan,

okay, thanks for your explanation, I understand.


I have one more question regards to resume a quiz. For example if I start a quiz at the Moodle website and want to complete it in my app, how can I do this? Because I have a web client application, the problem is that I cannot determine what the attemptid is, at the function "quiz_start_attempt" I get only the error with "attemptisstillinprogress" and without offline save of the quiz the determination of attemptid is confused.


Best regards,

Jan Philipp

In reply to Jan Philipp Weber

Re: Mobile web service quiz documentation

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Jan Philipp,

I also found this a bit confusing when I developed the Mobile app smile

To determine the attempt to use we use the WebService mod_quiz_get_user_attempts.

If we don't receive any attempt, it means we need to start a new one. Also, if the last attempt is finished (state is 'finished' or 'abandoned') we also start a new attempt. Otherwise we use the attemptid of the last one without calling start attempt.

Kind regards,

Dani


In reply to Dani Palou

Re: Mobile web service quiz documentation

by Jan Philipp Weber -

Hi Danielsmile,

I thought to myself that it is work with mod_quiz_get_user_attempts, but in my cases, it doesn't work because the attempt which is in progress is not listed. mixed


mod_quiz_get_attempt_access_information:
object(stdClass)#21 (5) { ["endtime"]=> int(0) ["isfinished"]=> bool(false) ["ispreflightcheckrequired"]=> bool(false) ["preventnewattemptreasons"]=> array(0) { } ["warnings"]=> array(0) { } }
mod_quiz_get_user_attempts:
 object(stdClass)#22 (2) { ["attempts"]=> array(0) { } ["warnings"]=> array(0) { } }
mod_quiz_start_attempt:
 object(stdClass)#23 (3) { ["exception"]=> string(21) "moodle_quiz_exception" ["errorcode"]=> string(22) "attemptstillinprogress" ["message"]=> string(22) "Versuch dauert noch an" }
Best regards,
Jan Philipp

In reply to Jan Philipp Weber

Re: Mobile web service quiz documentation

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Jan Philipp,

that's really weird, it's always working for us. Can you please verify you're sending the right parameters to the WebServices? Also, we always send the user id to mod_quiz_get_user_attempts, but it should still work without sending it...

Juan Leyva is the one who developed the WebServices but he isn't here this week, so you'll have to wait until next week to get a better response sad

Kind regards,

Dani

In reply to Dani Palou

Re: Mobile web service quiz documentation

by Jan Philipp Weber -

Hi Daniel,

I send quizid and userid with REST to the Web Service, here is my function from my Web Service test project:

    public function getQuizUserAttempts($token,$quizid,$userid)
    {
        $domainname = 'https://mymoodle.com';
        $functionname = 'mod_quiz_get_user_attempts';
        $restformat = 'json';
        $params = array('quizid' => $quizid,'userid' => $userid);
        $serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
        $this->load->library('Curl');
        $curl = new Curl();
        $restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
        $resp = $curl->post($serverurl . $restformat, $params);
        return $resp;
    }


For me, the whole thing is very mysterious.

Best regards,
Jan Philipp
In reply to Jan Philipp Weber

Re: Mobile web service quiz documentation

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi again,

that seems right. Can you please check if everything works fine using the Moodle Mobile app? Access the quiz and check if the attempts look exactly as in Moodle web.

Kind regards,

Dani