Converting a Moodle 2.0 question type

Revision as of 08:01, 2 February 2013 by Jamie Pratt (talk | contribs) (oops, we don't need two titles)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

1. Change the class definition in questiontype.php from

class question_myqtype_qtype extends default_questiontype {

to

class qtype_myqtype extends question_type {


2. Create new renderer.php and question.php files, with a suitable blank class definition in them. (Perhaps copy the files from another question type, then delete everything in the class.)


3. Fill in the the question definition class, including:

3a. appropriate fields to store the question definition.

3b. create start_attempt, based on the old create_session_and_responses.

3c. create apply_attempt_state, based on the old restore_session_and_responses.

3d. Implement the grading logic get_expected_data, is_complete_response, is_gradable_response, is_same_response, grade_response, get_num_parts_right, clear_wrong_from_response. Some of this will be based on the old grade_responses method. You may also find some of the necessary code mixed into places like print_question_formulation_and_controls.

3e. Implement the reporting functionality get_correct_response, get_question_summary, summarise_response. Some of this may be related to the old grading methods.

3f. Write a test helper class to create one or more typical test instances of your question definition class.

3g. Write unit tests for the grading and reporting methods.


4. Copy all the code from print_question_formulation_and_controls and display.html, and related methods, and split it into the appropriate methods in the renderer class.


5. Write one or more walk-through tests that take instances of your question with different behaviours.


6. Implement initialise_question_instance to populate instances of your question definition class from the data returned by get_question_options.


7. Copy check_file_access from the question type class to the question definition class, and update it.


8. Delete all the old qtype_myqtype_question methods that are no longer used.

9. Add things like hints to the question_edit_myqtype_form class. Look for opportunities to improve the existing code by using the helper methods like add_combined_feedback_fields, data_preprocessing_answers.

10. Note that question_type::get_editing_head_contributions no longer exists, because it is no longer necessary with the new mechanisms for handling CSS and JavaScript in Moodle 2.x. Any styles you put in question/type/mytype/styles.css will be included on every page anyway, and you can use $PAGE->requires->js_init_call() in, for example, the form definition, to load your JavaScript.