This is a huge undertaking so let's craft together a game plan.

Problem/Motivation

Entities are great. Quiz questions are already nodes, so this shouldn't be too big of a change but we will gain so much more functionality moving forward and will help us upgrade to D8.

Quiz questions are not "content" and we should separate them from "nodes".

Proposed resolution

Migrate Quiz question types to entities

Remaining tasks

1. Implement hook_entity_info for all question types, either through a sub-API or the question types themselves
- entity type = quiz question
- entity bundle = multichoice
2. Implement hook_entity_info for all question answer storage tables
- How would this work? The format of the answer is dependent on the question.
- entity type = quiz_question_response
- entity bundle = multichoice
- field "multichoice_answer"
3. Convert all db_** calls in quiz question metadata storage to entity operations
4. Convert all db_** calls in quiz question answer storage to entity operations
5. Provide migration path from question nodes + fields -> question entities
6. Provide migration path from question responses + fields -> question entities
7. Migrate tests.

User interface changes

None

API changes

Basically any node operations will be entity operations.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

djdevin’s picture

Issue summary: View changes
Issue tags: +7.x-5.1 release blocker

  • djdevin committed 0920ae7 on 7.x-5.x
    Issue #2378359: jumped the gun on questions entity api
    

  • djdevin committed 0920ae7 on 7.x-6.x
    Issue #2378359: jumped the gun on questions entity api
    
djdevin’s picture

djdevin’s picture

lakshminp’s picture

I was thinking if https://www.drupal.org/project/entity_bundle_plugin would be a good use case here. Here's how different entities would relate to each other:

Quiz - entity with the following properties:
name, created, metadata etc.

Question - entity with the following properties:
created, user, score, solution text etc.

QuizQuestion - relation, possibly using the https://www.drupal.org/project/relation. Reason being, we can add more metadata to the relationship, its extensible.

QuizAttempt - an entity with no bundles with the following properties:
quiz, user, is complete, start time, end time
question list(to preserve order of taking etc)

Question Attempt - entity, bundles created via entity bundle plugin
user, question, quiz.

Multichoice Question - bundle of Question, has question data.

Multichoice Question Attempt - bundle of Question Attempt via entity bundle plugin, evaluate(different implementation), score(different implementation)

Can you critique this approach?
I can probably add a block diagram if this is not a good explanation.

djdevin’s picture

Hi,

I actually just came upon that module when I was working on another project, #2491719: Refactor Course API using per-bundle classes which has a similar architecture. I didn't use the module, but I did use the pattern of having separate classes per bundle.

Originally I wanted to do something like that but didn't think it was possible to have a bundle per-class. But it definitely seems like this would be the way to go, it only makes sense that each question type should be a bundle.

Regarding the relationship, there is an entity type already called "quiz_question_relationship", It's the same idea as Relation module. Also internally most of the Quiz stuff uses the Entity API now (even though they are tied to nodes). Check out quiz_entity_info().

djdevin’s picture

Eliminating the difference between entity_load() and _quiz_question_get_instance/_quiz_question_response_get_instance().

djdevin’s picture

The last submitted patch, 8: convert_questions_to_d7-2378359-8.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 9: convert_questions_to_d7-2378359-8.patch, failed testing.

djdevin’s picture

Status: Needs review » Needs work

The last submitted patch, 12: convert_questions_to_d7-2378359-12.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 14: convert_questions_to_d7-2378359-14.patch, failed testing.

The last submitted patch, 8: convert_questions_to_d7-2378359-8.patch, failed testing.

The last submitted patch, 9: convert_questions_to_d7-2378359-8.patch, failed testing.

The last submitted patch, 12: convert_questions_to_d7-2378359-12.patch, failed testing.

The last submitted patch, 14: convert_questions_to_d7-2378359-14.patch, failed testing.

robpowell’s picture

Would love to see quizzes in D8. I see this is 1 year stale, is anyone pushing on this?

djdevin’s picture

Version: 7.x-5.x-dev » 8.x-5.x-dev
Status: Needs work » Fixed

Fixed in the D8 version. Questions are first class entities now.

Status: Fixed » Closed (fixed)

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