(Hmm, not sure the best category for this. a Task?)

I know that there are numerous other tickets in the issue queue around this topic. For my project I needed to have ajax_quiz working.

I've worked on two patches that allow ajax_quiz to work in a way that utilizes the Drupal 7 AJAX framework and callbacks. There are two patches.

Patch 1: 2464087-quiz-quiz_questions-remove-args-1.patch

This patch removes the use of arg() from the various form functions used by the quiz_question.module . By using arg() (ex: arg(1), arg(3)) assumptions are being made about the url sturucture, which might not hold true (especially with the use of ajax callbacks. The data being retrieved from these arg() calls can be retrieved by other means.

The value attempting to be retrieved from arg(1) is the quiz nid. This patch adds the quiz nid & vid to the quiz_question_answering_form form object and places them in #quiz. This allows for all other form calls (the validation and submission functions) to retrieve the quiz from the form object.

The value attempting to be retrieve from arg(3) is a question number. This patch instead retrieves this from the $_SESSION['quiz'][]['current'] value.

Patch 2: 2464087-quiz-ajax_quiz-use-ajax-framework-1.patch

This patch requires patch 1. This patch updates ajax_quiz.module to add a wrapping div to the quiz_question_answering_form as well as ajax callbacks to all submission navigation buttons. When submitted the Drupal 7 AJAX framework will call a custom callback (function added to the ajax_quiz.module) which is triggered after the form validation/submission function. The callback implements logic to retrieve the correct question and re-render the form, as well as, update the quiz progress. It also handles redirecting the user to the final results page.

With this method the files ajax_quiz.admin.inc, ajax_quiz.js can be removed (but I have not removed them).

I've only done limited testing on these patches but they work for answering quiz questions, leaving questions blank and traversing bakcwards on a quiz.

I welcome input and feedback.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikemiles86’s picture

mikemiles86’s picture

Issue summary: View changes
mikemiles86’s picture

Issue summary: View changes
mikemiles86’s picture

FileSize
5.53 KB
djdevin’s picture

Hey thanks, this looks great. I was getting ready to abandon AJAX Quiz.

I'll give it a try soon but it looks like it works with pages too? Have you tried it with per-question feedback?

mikemiles86’s picture

@djdevin

I have not tested with pages, But since the method I implemented does not interfere with the submission/render process I think it should.

Feedback I'm not sure, my gut says it probably wont work (yet), but I have not tested it.

mikemiles86’s picture

There is a lot more to be done, but I think this is a step in the right direction.

mikemiles86’s picture

Confirmed that my last set of patches did not work with Feedback.

I have revised and updated.

First apply the quiz-remove-args-1.patch, then the quiz-ajax_quiz-user-ajax-framework-2.patch

lokapujya’s picture

If I can find some time, I'll help review this. I did some work on porting ajax quiz to 7.5 in https://www.drupal.org/node/1224448

djdevin’s picture

Version: 7.x-5.0-alpha9 » 7.x-5.x-dev
Status: Active » Needs review

The last submitted patch, 8: 2464087-quiz-remove-args-1.patch, failed testing.

djdevin’s picture

FileSize
5.18 KB

Rerolled the first patch.

Status: Needs review » Needs work

The last submitted patch, 12: 2464087-quiz-remove-args-2.patch, failed testing.

djdevin’s picture

Status: Needs work » Needs review
FileSize
16.3 KB

I just reviewed both patches and the AJAX functionality appears to work perfectly, with feedback too!

Using the ctools ajax functionality means we can get rid of the custom JS that was in there before.

Rolled everything up to one patch for a final test then I will commit this.

djdevin’s picture

FileSize
16.65 KB
1.85 KB

Updated to load the question by the passed VID.

djdevin’s picture

Status: Needs review » Fixed

Fixed! Thank you!

  • djdevin committed da89882 on 7.x-5.x authored by mikemiles86
    Issue #2464087 by mikemiles86, djdevin: Updating AJAX quiz to utilize...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.