Commit 4925a0ec authored by Hong Truong's avatar Hong Truong
Browse files

Issue #2397081 by thehong: Split cloze question to separated project.

parent 5b058ad1
Loading
Loading
Loading
Loading
+0 −26
Original line number Diff line number Diff line
### Introduction

![](https://cloud.githubusercontent.com/assets/41143/5509202/37b989f2-87e8-11e4-8624-7a18e4fa5851.png)

The cloze module essentially adds a new question type to conduct Fill in the blanks
kind of Quiz. In eLearning parlance it is also known as cloze test.
See http://en.wikipedia.org/wiki/Cloze_test to know more about cloze test.

### Installation

1. Copy cloze folder to modules directory (usually sites/all/modules).
2. At admin/build/modules enable the Cloze module in the Quiz Question package.
3. Hit "Save configuration" button.

For detailed instructions on installing contributed modules see:
http://drupal.org/documentation/install/modules-themes/modules-7

### Usage

Check out blog post http://knackforge.com/blog/sivaji/cloze-module-drupal-quiz

### CREDIT

- Started by Sivaji http://drupal.org/user/328724
- Drupal 6 version of this module was sponsored by Anastasis Soc. Coop
- Ported to Quizz by @thehong. Sponsored by GO1 (www.go1.com.au)
+0 −13
Original line number Diff line number Diff line
.cloze-question .form-item {
  display: inline;
}

.cloze-instruction .correct,
.quiz-solution .correct,
.quiz-report .correct {
  color: #009900;
}

.quiz-report .incorrect {
  color: #FF0000;
}
+0 −38
Original line number Diff line number Diff line
(function ($, Drupal) {

  /**
   * The answer has been converted to upper case becaue the keys entered are
   * displayed as upper case. Hence to avoid case insensitive part, I have made
   * it to upper case.
   */
  var onKeyUp = function (e) {
    switch (e.keyCode) {
      case 9: // tab
      case 17: // ctrl
      case 18: // …
      case 91: // cmd
      case 16: // shift
        return true;
    }

    var id = this.id;
    var present_class = $('#' + id).attr('class').replace('form-text', '').trim();
    var field_answer = Drupal.settings.answer[present_class].toUpperCase();
    var input = $('#' + id).val();
    var reg = new RegExp('^' + input.toUpperCase() + '.*$', 'g');

    if (reg.test(field_answer)) {
      e.preventDefault();
    }
    else {
      $('#' + id).val(input.substr(0, input.length - 1));
    }
  };

  Drupal.behaviors.cloze = {
    attach: function (context) {
      $('.answering-form .cloze-question input', context).keyup(onKeyUp);
    }
  };

})(jQuery, Drupal);
+0 −8
Original line number Diff line number Diff line
name = Cloze
package = Quiz Question
description = Question with certain words removed the participant will have to fill-in the missing words.
core = 7.x
dependencies[] = quizz
dependencies[] = quizz_question

files[] = tests/QuestionClozeTestCase.test
+0 −88
Original line number Diff line number Diff line
<?php

/**
 * Implementation of hook_install().
 */
function quizz_cloze_install() {
  // variable_set('node_options_cloze', array('status'));
}

/**
 * Implementation of hook_schema().
 */
function quizz_cloze_schema() {
  $schema['quiz_cloze_user_answers'] = array(
      'description' => 'Store user\'s inputs.',
      'fields'      => array(
          'answer_id'    => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE,),
          'question_qid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
          'question_vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
          'result_id'    => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
          'score'        => array('type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0,),
          'answer'       => array('type' => 'text'),
      ),
      'primary key' => array('answer_id'),
      'unique keys' => array(
          'ids' => array('result_id', 'question_qid', 'question_vid'),
      ),
  );

  $schema['quiz_cloze_question_properties'] = array(
      'fields'      => array(
          'qid'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
          'vid'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
          'learning_mode' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0,),
      ),
      'primary key' => array('qid', 'vid'),
  );

  return $schema;
}

/**
 * Adding table {quiz_cloze_node_properties}
 */
function quizz_cloze_update_7401() {
  db_create_table('quiz_cloze_node_properties', drupal_get_schema_unprocessed('cloze', 'quiz_cloze_node_properties'));
  return 'Adding table {quiz_cloze_node_properties}';
}

/**
 * Implements hook_quiz_question_upgrade_schema_node_to_entity().
 */
function quizz_cloze_quiz_question_upgrade_schema_node_to_entity() {
  if (db_table_exists('quiz_cloze_node_properties')) {
    db_change_field('quiz_cloze_user_answers', 'question_nid', 'question_qid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
    db_rename_table('quiz_cloze_node_properties', 'quiz_cloze_question_properties');
    db_change_field('quiz_cloze_question_properties', 'nid', 'qid');
  }
}

/**
 * Implements hook_quiz_question_upgrade_pre_drop_temp_columns().
 */
function quizz_cloze_quiz_question_upgrade_pre_drop_temp_columns() {
  // quiz_cloze_question_properties
  db_query(
    "UPDATE {quiz_cloze_question_properties} as qp"
    . " INNER JOIN {quiz_question_revision} qr ON qp.vid = qr.node_vid"
    . " SET qp.qid = qr.qid, qp.vid = qr.vid"
    . " WHERE 1"
  );

  // quiz_cloze_user_answers
  db_query(
    "UPDATE {quiz_matching_properties} as ua"
    . " INNER JOIN {quiz_question_revision} qr ON ua.question_vid = qr.node_vid"
    . " SET ua.question_qid = qr.qid, ua.question_vid = qr.vid"
    . " WHERE 1"
  );
}

/**
 * Make sure update script from main module is run before all.
 */
function quizz_cloze_update_7600() {
  require_once drupal_get_path('module', 'quizz_question') . '/quizz_question.install';
  return quizz_question_update_7600();
}
Loading