Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am currently working on a custom "quiz" like module in Drupal 7. The way it works is as follows: a site administrator creates a bunch of reading assignments, and associated questions that go with those readings (the reading might be a downloadable PDF, or a link to some online content). I currently have an entity called "reading" which has a title, description, media type field (pdf or link), and a group of question text fields, where the admin can create an arbitrary number of questions. Thus, a constructed reading entity might look like this:

========= READING ENTITY ===========
Title:       Some Great Paper
Description: This great paper was written by Joe Schmo, and it is great.
Media Type:  PDF
File Field:  /path/to/the/uploaded/file.pdf
Questions:
             What did Joe mean by 'Persistence is necessary?'
             How would you apply these ideas to your life?

Now, I am trying to create the "Assignment" entity. This is an entity that an instructor would create by picking a reading from the pool of reading entities an administrator has created. The assigned reading entity would look very similar to the reading entity, however it would have some additional fields. For example, it would need an indicator that the student has submitted the answers, and a grade field for the instructor. It would also need fields for instructor notes, and student answers. Since there needs to be an attached answer and notes field for each of the questions, I also created an "AssignmentQA" entity.

Finally, there is a requirement that if an instructor creates an assignment, and later on an administrator updates the "Reading" entity (Say, changes questions, or the pdf file to be downloaded, etc..) that this change is NOT seen in already created assignments. Thus, everything would need to be cloned. I see the Assignment and AssignmentQA entities associated with the above reading as looking like this:

============== ASSIGNMENT ENTITY ===============
Title:       Some Great Paper    <--- cloned from the Reading entity
Description: This great paper... <--- cloned from the Reading entity
Media Type:  PDF                 <--- cloned from the reading entity
File Field:  /path/to...         <--- cloned from the reading entity
Instructor:  User reference to the instructor
Student:     User reference to the student
Status:      [Assigned, Completed, or Graded]
Notes:       General notes from the instructor to the student...
QAs:
             reference field to QA1
             reference field to QA2

============== ASSIGNMENTQA ENTITIES ==============
ID:          QA1
Question:    What did Joe mean by 'Persistence is necessary?' <--- Copied from Reading's Q1
Answer:      The student's answer to this question.
Notes:       Instructor's notes on this particular answer

ID:          QA2
Question:    How would you apply these ideas to your life? <--- Copied from Reading's Q2
Answer:      The student's answer to this question.
Notes:       Instructor's notes on this particular answer.

Of course those IDs for the AssignmentQA entities are pseudo-code used for clarity.

So with all that being said..

  1. Does this sound like a reasonable approach?
  2. Is there a better way to think about this/do this?
  3. If it is reasonable, is there a way to pass a reading entity to the Assignment Entity so that I can properly construct an assignment from the reading data?
  4. And, how do I go about cloning the pdf file field, such that the pdf file can't be deleted from the server if it is updated, but the old version has already been assigned to someone? (e.g.- I'd like to use the updated PDF for any new assignments created, but keep the old one around for old assignments).
share|improve this question

1 Answer 1

Does this sound like a reasonable approach?

You've put some thought into this, it doesn't sound unreasonable -- nor does it sound simple.

Is there a better way to think about this/do this?

If your reading Questions are simply textareas great, if they're radio boxes and select widgets look into leveraging an existing "quiz" or form builder like: webform, webform_entity or the quiz module.

If it is reasonable, is there a way to pass a reading entity to the Assignment Entity so that I can properly construct an assignment from the reading data?

I have cloned nodes before in Drupal 6/7, which isn't too hard. I think you need to really iron out a workflow for "if I make a reading -- I can create Assignment(s) and/or AssignmentQA entities". You could try creating this workflow logic for instructors using workflow, maestro or using a set of Rules.

If you try and just "I made a reading entity". You could always make a view that allows you to create a hook_menu() link to a new node edit form using a Reading Node as a menu argument -- then you could see the original node's fields easily for cloning.

And, how do I go about cloning the pdf file field, such that the pdf file can't be deleted from the server if it is updated, but the old version has already been assigned to someone? (e.g.- I'd like to use the updated PDF for any new assignments created, but keep the old one around for old assignments).

In D7 the file_managed FAPI element allows you to set an "owner" module for the FID, I believe only that module may deem the file as 'deleted'. So using a custom FAPI override you could specify a module you control as the enforcer for this ruling. The D7 file_entity module is seeking to add views to track individual file usage of FIDs i'm not sure if it's ready for prime time usage.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.