1

I've a Moodle Quiz on 2 different pages (2 questions on the first and 1 on the second) and I'd like to retrieve those 3 questions.

I use this code :

function getQuiz(IdQuiz){
  ajaxRequest("mod_quiz_start_attempt",{quizid:IdQuiz,forcenew:1}).success(function(quiz){
    getQuestions(quiz.attempt.id,0);
  });
}

function getQuestions(idAttempt,currentPage){
  ajaxRequest("mod_quiz_get_attempt_data",{attemptid: idAttempt, page: currentPage}).success(function(response){
    console.log(response);
    if (response.nextpage > -1){
      getQuestions(idAttempt,currentPage+1);
    }else{
      console.log('stopped');
    }
  });
}

It correctly get the 2 first questions of the first page but then for the second page, the response does not give me the question but tells me this on the console :

Object {exception: "dml_missing_record_exception", errorcode: "invalidrecord", message: "Can not find data record in database table quiz_attempts."}

It is strange because I works when I modify the first function like that :

function getQuiz(IdQuiz){
  ajaxRequest("mod_quiz_start_attempt",{quizid:IdQuiz,forcenew:1}).success(function(quiz){
    getQuestions(quiz.attempt.id,0);
    getQuestions(quiz.attempt.id,1);
  });
}

(ajaxRequest is simply a function that send an Ajax request to Moodle)

1 Answers1

0

I solved it myself ! It was actually because I tried to access a quiz that was already finished (the code was executed multiple times without me knowing it)