quiz_take_quiz needs to be rewritten to follow FAPI best practices, and also to allow for more advanced quiz taking features like multiple questions on a page and forced retaking of a question until it has been answered correctly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

djdevin’s picture

Version: 6.x-5.x-dev » 6.x-4.x-dev

Here is a patch against the latest 4.x-dev from CVS to illustrate how changes to quiz_question, the question types, and quiz_take_quiz can be used to administer a FAPI-enhanced quiz. It should patch cleanly with patch -p0 in the root of quiz.

Some notes:
1) I broke a lot of things, for the time being (feedback, question jumping)
2) FAPI is used to render and validate the questions, in one question per page and all questions on a page (#503228: All questions in a single page)
3) Only the multichoice question type has been changed (I figure that is the hardest one). The others won't work yet.
4) In the process of moving as much as possible out of quiz_take_quiz
5) Taking quizzes and storing results *should* be functional

The patch is a little dirty now but I'll be cleaning it up as I go along :) Feedback appreciated!

Active development efforts are being sponsored by DLC Solutions, LLC.

falcon’s picture

Did you forget the patch? We'll commit your patch to the 5.x branch as soon as it gets created. Our policy is to avoid big changes like this one in RC. It will potentially break modules that extend quiz or changes how quiz behaves.

If your patch does what you say it does we'll be celebrating the day it gets committed!

djdevin’s picture

FileSize
30.64 KB

Ugh I swear something is wrong with that file upload.

Here it is, but it's rolled against 4.x-dev so not sure how it will work with 5 yet.

djdevin’s picture

If there's no chance of this making it into 4.x, I'm going to re-roll against 5.x.

Edit: 5.x is missing some of the functionality in 4.x (that I patched against) - not sure what to do.

falcon’s picture

I'll start a D7 branch when Quiz RC10 is out. I hope it will happen this weekend. Your patch should be rolled against the D7 branch.

The Quiz 5 branch and HEAD is outdated.

falcon’s picture

Ok, you can now roll you patch against HEAD and I will commit it. HEAD will be used to develop the D7 version of quiz.

falcon’s picture

Please provide a new patch here, and I'll commit it asap.

djdevin’s picture

Ok will do, going to try and clean it up and restore some of the functionality I broke to get something somewhat stable in there.

Artusamak’s picture

Do we have an exhaustive list of update we need to have to be "drupal compliant"?
I'd like to jump in the project to help but it's quite hard to have a global vision.
We need two steps before having a D7 version.
First we need to clean the code, second we need to adapt quiz to D7 new concepts.
My guess is that we need to list (maybe it's done) every feature we want in core, start from scratch with the new entities concept and reuse some code when we know that the existing code is clean and usable.
I'm again saying that we should split quiz in several modules (core + contrib) to have less code to maintain.
My point is that the tasks sounds big from here. :)

falcon’s picture

I agree, but do we need to do absolutely everything at once? If we can slay the biggest monsters now we can take care of the smaller ones later. quiz_take_quiz is the biggest monster in my opinion. If we get rid of that one (and all its helpers) we will be a lot closer to following best practices. After quiz_take_quiz is out of the way the architecture is a lot more drupal friendly, and we just need to take care of smaller portions of code here and there. (By quiz_take_quiz I don't just mean that one function, I mean the entire quiz taking logic. It will probably affect 30 - 50 % of the code... The quiz taking logic was untouched in Quiz 3 AFAIK, and it has been untouched in Quiz 4, but we've added a lot more code to it making it an even bigger monster to kill.)

I'm not quite sure why entities in core should make a big difference for quiz, but I haven't studied D7 yet. As far as I know nodes are entities in D7, and I see no reason to make questions or tests into custom entities. They will work a lot better as node entities in my opinion, but maybe I've misunderstood something along the way here?

A complete feature list for Quiz would be great! I don't have time to write it but I will be able to write down the features I want to move out of core in the D7 issue.

djdevin’s picture

FileSize
37.64 KB

Merry Christmas!

Attached is a present/patch against Quiz HEAD to move it towards full FAPI functionality. There have been some very radical changes, so the best way to check them out is to use a program like Kompare or some other diff viewing tool.

- Feedback is broken
- Quiz navigation works (back/skip/jump) using FAPI #submit callbacks
- Skip status probably not stored correctly. Working on that

Quiz taking and storing results, both in single and multi page form, should be functional.

quiz_take_quiz still exists, but it's main function will be to prepare the question nodes that it will be passing to drupal_get_form to generate output. The quiz_question_answering_form form function can take either 1 node or many nodes, and process them individually using #element_validate - so this opens up the door for having single question per page or variable-page quizzes (not just 1).

The only question type that works is multichoice. If the community decides that this is a good way to implement full FAPI in the question types, we can apply it to the rest of the types :)

falcon’s picture

Thanks for contributing, lots of stuff will be fixed with that patch! There is one thing I would like to discuss(and think about). I think we should make the quiz taking use a multistep form instead of $_SESSION. You've cleaned up the way $_SESSION is beeing used, and maybe we could remove it completely by using multistep forms? If we introduce multistep-forms we'll probably be able to make it easier to add features for having multiple questions on multiple pages. What do you think?

djdevin’s picture

Glad to contribute! I'm not sure multistep forms are the way to go, but I haven't worked with them long enough to have a strong opinion. My first thought is being too restrictive for what we want to do. For example, skipping to a question in the middle of a quiz might be difficult with a linear multistep form - having to create the entire quiz in a form and making sure you can skip back and forth, jump, etc. - something I think on-the-fly form generation would be better at. I think we still need to use $_SESSION to maintain randomly generated quizzes and current versions of quizzes in progress - but it's definitely easier to work with now.

We (myself, colleagues) were also discussing having a URL-accessible page for each question or question page, like the way that patch has jump-to-question set up. So instead of node/X/take being the quiz driver, it would send you to the current question: node/X/take/3, with 3 being the individual question number, or the number of the page. This way you could build a view of questions (or pages), and link directly to them if you were allowed to take questions out of order - otherwise, have logic to prevent skipping.

falcon’s picture

I don't think there will be a problem using multistep forms. You basically use $form_state['storage'] the way $_SESSION is beeing used today. You don't have to put all questions in the same form at once either, you just generate the form based on what data already exists in $form_state.

Regarding separate url's for each page I agree, but if we can't make that happen with multistep forms(and I think we can), I think using multistep forms is more important. Some high-traffic sites don't allow the use of $_SESSION.

Anyway, I'm considering going ahead on D7 without this patch. The community is asking for a D7 version ASAP in several channels. I'm considering just porting Quiz 4 to D7 asap, and when we have a Quiz 4 port working on D7 we can start working on Quiz 5. What do you think about this?

djdevin’s picture

I have a vested interest in this functionality happening for D6, so I'm pretty biased :\

xxm’s picture

Where is the 6.x-4.x-dev version to patch for single page view?

lejon’s picture

Looks like this would solve some of my other support requests if applied to a new 6.4 release.

I am voting for including this in 6.4 and not only implementing these changes in D7. It will be a long time before we move to D7 and I guess that might be the same for other sites.

Thanks!

stella’s picture

Component: Code » Code - Import/Export

subscribe

djdevin’s picture

Forked here for anyone who needs it: http://drupal.org/sandbox/devin/1287518

D6 version with single-page support for multichoice questions only.

drewbe121212’s picture

Are there any ideas when the D7 port of this will be available?

scottrigby’s picture

Title: quiz_take_quiz must be totally rewritten » Rewrite quiz_take_quiz() with FAPI
Version: 6.x-4.x-dev » 7.x-4.x-dev
Component: Code - Import/Export » Code - Quiz core
Status: Needs work » Needs review
Issue tags: +FAPI
FileSize
37.22 KB

Here's a reroll of the patch #11 for 7.x-4.x, including a fix for the D7 @todo in theme_quiz_progress(). This patch reflects current progress of the new 7.x-4.x branch in http://drupal.org/sandbox/devin/1287518 - squashing commits after cloning the 7.x-4.x branch from Quiz into one patch for review.

I work with djdevin, and as he said collectively we're invested in getting this in 6.x-4.x. However I realize that since Quiz 7.x went ahead, this now needs to be fixed in 7.x first, then backported to 6.x.

@falcon: This patch doesn't address your thoughts about multistep forms - personally i'd like to see that (djdevin described our thoughts about this in #13 - using a menu path to serve up the configured questions for each page, which IMO should work with multistep). Can we make a new issue for multistep though, and get this FAPI change committed? In the meantime we'll keep the sandbox updated, but would be good to get this part in so we don't have to keep our efforts separate…

drewbe121212’s picture

Hi Scottrigby,

I encountered a few error messages when applying that patch to the current 7-4.x-dev release:

PHP Fatal error: Call to undefined function db_result() in /var/aegir/platforms/SiteTool_Basic_12646/sites/pcmh-dev.osumc.edu/modules/quiz/quiz.module on line 1799

PHP Fatal error: Call to a member function getAnsweringForm() on a non-object in /var/aegir/platforms/SiteTool_Basic_12646/sites/pcmh-dev.osumc.edu/modules/quiz/question_types/quiz_question/quiz_question.module on line 177

scottrigby’s picture

Status: Needs review » Needs work

Whoops looks like i missed one. Will update soon, unless someone wants to fix and reroll sooner…

drewbe121212’s picture

When applying the single page setup and accessing node/%node/take, is anyone else losing the pages breadcrumbs / tabs?

It appears this was derived from quiz_menu for node/%node/take

  // Take quiz.
  $items['node/%node/take'] = array(
    'title' => 'Take',
    'page callback' => 'quiz_take',
    'page arguments' => array(1),
    'access callback' => 'quiz_take_access',
    'access arguments' => array(1),
    'type' => MENU_CALLBACK,
  );

Replaced with

  // Take quiz.
  $items['node/%node/take'] = array(
    'title' => 'Take',
    'page callback' => 'quiz_take',
    'page arguments' => array(1),
    'access callback' => 'quiz_take_access',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
  );

This adds the 'take' tab back in, but gives it it's context as well.

fille1000’s picture

I cannot seem to get the patch from #21 working when trying to apply it to 7.x-4.0-alpha4. Do you have the same problem? if so, Is there a new patch for version 7.x-4.0-alpha4 of the Quiz module?

Lloyd’s picture

Any update on this? Can we get this to work in 7.x-4

matdab’s picture

Subscribing!

amitgarg’s picture

Category: task » feature
Priority: Normal » Major

Hi, am looking forward to get an option for all questions on a single page on drupal 6 or drupal 7.

Thanks
Amit Garg

kurti’s picture

I can´t aplly correctly this patch for working module quiz v4.4...

sahilk’s picture

Any update on this...
Option for multiple questions on a single page in drupal 7.

okday’s picture

i want it too

thanks

bmango’s picture

I know there has been work done here on enabling multiple questions per page and I was just wondering what kind of functionality this may give?

I have just built a Drupal 7 website for people learning sign language. I am using quizzes so people can take a test answering questions on a video (of sign language). For the video, I created a custom video field and added it to the quiz's content type as well as the multiple-choice question content type. However, it is important that people answer several questions on the same video. So I was hoping to have a video at the top - that relates to a sub-set of questions within the quiz - and then have those questions all on the same page. Users taking the quiz, would then move on to the next video with the next set of questions.

Is this a feature, i.e. having multiple questions per page, where it is possible to define what questions belong to a single page, that this issue queue might eventually support?

Having written this, I'm thinking it may be a bit of a long shot...

Thanks

djdevin’s picture

@bmango a long shot at the moment, but that's the idea - if we're going to add single page quiz support we might as well add page break support as well.

drewbe121212’s picture

I know webform implemented something similar to this setup (page breaks with (1 to n pages)). It might be worth looking at as a guide in development.

bmango’s picture

Many thanks for the feedback.

Jimarick’s picture

I am keen to know if this issue is near completion or a long way away?

I would like to implement multiple questions on a single page for my site. I saw that there was a hack on another thead. Is this hack reliable, or should I hold out until the proper workaround is written?

Many thanks
James

drewbe121212’s picture

It is stable, however I think at this point it time it will have to be applied manually due to the patch date and the current release code updates. I am using the single page setup in two production environments right now, although granted, I have modified quiz well beyond what the last release was, so I can't really offer up any of my code for this.

m.kharrat’s picture

m.kharrat’s picture

Pere Orga’s picture

Status: Needs work » Needs review
djdevin’s picture

Status: Needs review » Needs work

Patch above is for #503228: All questions in a single page, not this issue.

Sivaji_Ganesh_Jojodae’s picture

Patch looks interesting but I couldn't apply it successfully yet. I'm trying to merge the changes manually.

Farrisimin’s picture

Will this be committed to git??

fleaslees’s picture

I haven't had any luck applying this single page patch on D7 so keen to know if anyone has been able to do so, or better still when the next release of quiz will be available? I have a client project which I can't complete until this is available. Many thanks.

mcpuddin’s picture

Is this rewrite intended for 7.x-4.x or 7.x-5.x? I feel like applying this to 4.x touches everything and might as well be held off to 5.x. For example, all the work done for #503228: All questions in a single page would be discarded.

djdevin’s picture

Category: Feature request » Task
Issue summary: View changes

So what is the release target here? Warning: long text below.

I noticed some D8 porting activity, which to me, doesn't make a lot of sense as D8 isn't done, Quiz 7.x isn't done, and mega importantly Quiz in Drupal 7 and seriously, Drupal 8 still doesn't use the Form API correctly for basic Quiz taking. This should be a 7.x-4.x release blocker or at least a 7.x-5.x blocker. If it's a 5.x blocker then D8 shouldn't even have a 4.x version. In my opinion D8 development should stop until quiz_take_quiz is fixed in D7.

Big education and enterprise sites that are slow to move aren't going to upgrade to D8 for a while so I feel like this is the time to fix critical architecture issues and large functionality gaps such as paginated questions in 7.x before the big 8.x push begins. I don't think 8.x-4.x being a straight port of Quiz 7.x-4.x is a good idea when it still lacks what a lot of other assessment engines have had for a while (Moodle and the big commercial ones).

Even if pagination wasn't on the roadmap I still feel like the architecture of quiz_take_quiz is so bad - falcon already said it in 2009 - that it warrants a critical blocker. This isn't a "feature request" as the issue states but more a task that I feel is entirely necessary to make up technical debt that has been accrued. There are probably a decent amount of users already running a patched version of Quiz, which is basically an unofficial fork. We can't measure that number, but judging by the people who actually came back and provided feedback, there are probably many more who found that patch and are using it quietly. In fact #503228: All questions in a single page was the most active feature request in the Quiz issue queue, with Drupal 5, 6, and 7 ports in between, then this one!

https://drupal.org/project/issues/quiz?status=All&text=&priorities=All&c...

That being said if we were to establish this as a release blocker I'd be willing to take leadership on this and dump literally all the time I can into it. We have a huge investment into using Quiz for our primary product and It would fill the gaps for our customers coming from other systems.

I'm also seriously concerned about the refactoring and moving forward in any direction because all Quiz unit tests are failing and there's no way to track regressions. For a project with 5500+ installs I feel we should write some working tests even before any of this happens.

tl;dr: Quiz isn't ready for D8 and should be fixed in D7 first.

scottrigby’s picture

Issue tags: +7.5 release blocker

Re #46 This should be done in a new minor branch, in line with the general rule of thumb for Drupal modules that make major API changes - this would qualify as that.

I would like to see djdevin added as a co-maintainer of the 7.x-5.x branch, which can focus on rewriting the FAPI (+ menu routing) part of quiz. This issue should then be marked as a 7.x-5.0 release blocker.

As djdevin mentioned, most of this was discussed earlier in #503228: All questions in a single page, specifically in #38, #66, #89, #133, and #134.

scottrigby’s picture

Version: 7.x-4.x-dev » 7.x-5.x-dev
Issue tags: -7.5 release blocker +7.x-5.0 release blocker
Pere Orga’s picture

I agree that all efforts should be put in the 7.x branches. If a D8 version has to be started, should be based on a non-broken D7 version. 7.x still carry too much 6.x heritage (including using nodes instead of entity types)

5k active installs it's not a very high number, specially when compared to the installs we had 3 years ago (3k) and the number of open issues (717)

scottrigby’s picture

Cross-posting #2220635: co-maintainer request for djdevin for those interested in #47.

djdevin’s picture

I branched 7.x-4.x to 7.x-5.x in my Github repo, and already got started on a ton of refactoring.

Anyone that wants to follow along, please to go https://github.com/djdevin/quiz

When it gets more stable I will move it to a Drupal sandbox. Currently most basic functionality works (Quiz taking, feedback) but it now uses less of the session, more of the Form API, and more of the menu system instead of quiz_take_quiz() for question navigation. Very soon to come will be all questions on a page/some questions per page.

Some more information about the refactoring is available here: https://drupal.org/sandbox/devin/1287518

djdevin’s picture

Refactoring work is in the 7.x-5.x branch now.

quiz_take_quiz is now only 50 lines :)

The goals right now are to get the existing behavior stable (one question per page) and update all the unit tests. A lot of the $_POST and $_GETs are gone and replaced with the form API and menu system.

After everything gets stable the next step will be paginated questions.

Currently with the API it's possible to pass quiz_question_answering_form() a list of arbitrary questions, and have them display and be taken. We just need a way through the UI to set up 1 page or multiple pages of questions.

drewbe121212’s picture

This is awesome Devin. This has been a long time coming and much needed, and I thank you for your time refactoring this into a more stable drupal-like experience.

For what it's worth, for multi page, it may be worth taking a look at webform as they have implemented something similar.

vinmassaro’s picture

@djdevin: thanks for all your work on this, we are following along for single page quizzes.

djdevin’s picture

If anyone can test their existing Quiz installations (please not your live site!!) on the 7.x-5.x branch that would help me a lot as well. Any issues should be opened with the 7.x-5.x version.

ksiebel’s picture

Thanks for your work!
We are going to test the 7.x-5.x branch next week.

djdevin’s picture

FileSize
155.5 KB

I've been working on quiz pagination in the quiz-pages branch and will push it to 7.x-5.x when it's functionality. I have the UI set up to set parent/child relationships.

I created a new quiz question type called Quiz Pages, so we do not have to rewrite the {quiz_node_relationships} table. There were a few other options, like adding a "page" selector to each question or "pagebreak", which would have been easier to introduce but less flexible. Although we are creating a node for each page, this gives us the most flexibility if we were ever to convert quiz questions to entities.

jadhavdevendra’s picture

Looks like @djdevin git repo works well with FAPI but, all questions on single page is not implemented yet.

djdevin’s picture

It's coming! There is a branch called "quiz-pages" but it is very experimental right now. I will merge everything to 7.x-5.x when it's a bit more ready for general testing.

djdevin’s picture

More code added to 7.x-5.x

Summary

1) Replaced question browser with a View, VBO actions
2) Added a module "quiz_page" which provides a paginated quiz question
3) Schema change to store parentage
4) Updated drag and drop UI to allow for question nesting under quiz pages
5) Multi-page quiz-taking workflow

Still tons of bugs but quiz taking is mostly OK.

djdevin’s picture

Status: Needs work » Fixed

quiz_take_quiz has been rewritten. closing this issue, bugs will go under the 5.x branch.

Status: Fixed » Closed (fixed)

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