diff --git a/question_types/quiz_question/quiz_question.core.inc b/question_types/quiz_question/quiz_question.core.inc index f396612bc0e18501ef4697af155ac9c3b53daaf9..6957a04c641f5f158b2524f24d1ec8f11aa1c212 100644 --- a/question_types/quiz_question/quiz_question.core.inc +++ b/question_types/quiz_question/quiz_question.core.inc @@ -615,9 +615,9 @@ abstract class QuizQuestion { $may_view_answers = in_array(TRUE, $results); return $may_view_answers; } - + /** - * Utility function that returns the format of the node body + * Utility function that returns the format of the node body */ protected function getFormat() { $body = field_get_items('node', $this->question, 'body'); @@ -642,6 +642,7 @@ abstract class QuizQuestionResponse { protected $answer = NULL; protected $score; public $is_skipped; + public $is_doubtful; /** * Create a new user response. @@ -658,8 +659,12 @@ abstract class QuizQuestionResponse { $this->rid = $result_id; $this->question = $question_node; $this->answer = $answer; - $this->is_skipped = db_query('SELECT is_skipped FROM {quiz_node_results_answers} - WHERE result_id = :result_id AND question_nid = :question_nid AND question_vid = :question_vid', array(':result_id' => $result_id, ':question_nid' => $question_node->nid, ':question_vid' => $question_node->vid))->fetchField(); + $result = db_query('SELECT is_skipped, is_doubtful FROM {quiz_node_results_answers} + WHERE result_id = :result_id AND question_nid = :question_nid AND question_vid = :question_vid', array(':result_id' => $result_id, ':question_nid' => $question_node->nid, ':question_vid' => $question_node->vid))->fetch(); + if (is_object($result)) { + $this->is_doubtful = $result->is_doubtful; + $this->is_skipped = $result->is_skipped; + } } /** @@ -748,6 +753,7 @@ abstract class QuizQuestionResponse { $obj->is_correct = (int) $this->isCorrect(); $obj->is_evaluated = $this->isEvaluated(); $obj->is_skipped = 0; + $obj->is_doubtful = isset($_POST['is_doubtful']) ? $_POST['is_doubtful'] : 0; $obj->is_valid = $this->isValid(); return $obj; } @@ -929,9 +935,9 @@ abstract class QuizQuestionResponse { $this->is_skipped = FALSE; $this->save(); } - + /** - * Utility function that returns the format of the node body + * Utility function that returns the format of the node body */ protected function getFormat() { $body = field_get_items('node', $this->question, 'body'); diff --git a/question_types/quiz_question/quiz_question.module b/question_types/quiz_question/quiz_question.module index 4a20e44ae9af24224be85a4871580c519edd1ab0..650e0a3435f40dfba1c4bc4537b5ebab5e403173 100644 --- a/question_types/quiz_question/quiz_question.module +++ b/question_types/quiz_question/quiz_question.module @@ -183,6 +183,23 @@ function quiz_question_answering_form($form, $form_state, $node, $include_nid_in $is_last = _quiz_is_last_question(); $form['navigation']['#theme'] = 'quiz_question_navigation_form'; + if ($quiz->mark_doubtful) { + $form['is_doubtful'] = array( + '#type' => 'checkbox', + '#title' => t('doubtful'), + '#weight' => 1, + '#prefix' => '
', + '#suffix' => '
', + '#default_value' => 0, + '#attached' => array( + 'js' => array(drupal_get_path('module', 'quiz') . '/theme/quiz_take.js'), + ), + ); + if (isset($node->rid)) { + $form['is_doubtful']['#default_value'] = db_query('SELECT is_doubtful FROM {quiz_node_results_answers} WHERE result_id = :result_id AND question_nid = :question_nid AND question_vid = :question_vid', array(':result_id' => $node->rid, ':question_nid' => $node->nid, ':question_vid' => $node->vid))->fetchField(); + } + } + if (!empty($quiz->backwards_navigation) && !empty($node->question_number)) { $form['navigation']['back'] = array( '#type' => 'submit', @@ -280,7 +297,12 @@ function quiz_question_skip_question($question, $result_id) { $response->vid = $question->vid; $response->rid = $result_id; $response->is_skipped = TRUE; - + if (isset($_POST['is_doubtful'])) { + $response->is_doubtful = $_POST['is_doubtful']; + } + else { + $response->is_doubtful = db_query('SELECT is_doubtful FROM {quiz_node_results_answers} WHERE result_id = :result_id AND question_nid = :question_nid AND question_vid = :question_vid', array(':result_id' => $result_id, ':question_nid' => $question->nid, ':question_vid' => $question->vid))->fetchField(); + } return $response; } diff --git a/quiz.css b/quiz.css index 6817106fc986c13fdd0f8ec60ea5e70cc9dadff2..fd01491cc4297cb64a6df9410b80592cc09bf7d9 100644 --- a/quiz.css +++ b/quiz.css @@ -1,6 +1,3 @@ - - - /* * Definitions that apply while viewing questions */ @@ -252,3 +249,80 @@ input.q-skip-button:hover, input#edit-back:hover { max-height: 300px; } +.mark-doubtful .toggle { + margin: auto; + position: relative; + width: 100px; + overflow: hidden; + height: 18px; + line-height: 18px; + font-size: 11px; + text-align: center; + cursor: pointer; + border: 1px solid #ccc; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + -khtml-border-radius: 3px; + border-radius: 3px; + -moz-box-shadow: 0 0 10px rgba(0,0,0,0.50) inset; + -webkit-box-shadow: 0 0 10px rgba(0,0,0,0.50) inset; + box-shadow: 0 0 10px rgba(0,0,0,0.50) inset; +} + +.mark-doubtful .toggle.off { + background-clip: padding-box; + background-image: -webkit-gradient(linear, 0% 0%, 100% 0%, color-stop(50%, red), color-stop(50%, white), color-stop(100%, white)); + background-image: -moz-linear-gradient(left, red 50%, white 50%, white 100%); + background-image: linear-gradient(left, red 50%, white 50%, white 100%); +} + +.mark-doubtful .toggle { + background-image: -webkit-gradient(linear, 0% 0%, 100% 0%, color-stop(50%, white), color-stop(50%, green), color-stop(100%, green)); + background-image: -moz-linear-gradient(left, white 50%, green 50%, green 100%); + background-image: linear-gradient(left, white 50%, green 50%, green 100%); +} + +.mark-doubtful .toggle div { + position: relative; + color: #777; + width: 52px; + -moz-border-radius: 2px; + -webkit-border-radius: 2px; + -khtml-border-radius: 2px; + border-radius: 2px; + background: white; + text-shadow: 1px 1px 0 white; + background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(0%, #FEFEFE), color-stop(100%, #EAEAEA)); + background-image: -moz-linear-gradient(top, #FEFEFE 0%, #EAEAEA 100%); + background-image: linear-gradient(top, #FEFEFE 0%, #EAEAEA 100%); + -webkit-transition: left 0.2s; + -mox-transition: left 0.2s; + -o-transition: left 0.2s; + transition: left 0.2s; +} + + +.mark-doubtful .toggle div:after, +.mark-doubtful .toggle div:before { + color: white; + text-shadow: none; + width: 50px; + position: absolute; + top: 0; + font-size: 9px; + font-weight: bold; +} + +.mark-doubtful .toggle div:before { + content: "Doubtful"; + left: -48px; +} + +.mark-doubtful .toggle div:after { + content: "Clear"; + right: -48px; +} +.mark-doubtful .toggle.off div { + left: 48px; +} + diff --git a/quiz.install b/quiz.install index 80d708f4629e74634840ca5b37acdc1e2f505e15..1c44d728ff7d93c91b2cc8fd363540041fc24d92 100644 --- a/quiz.install +++ b/quiz.install @@ -216,6 +216,12 @@ function quiz_schema() { 'not null' => TRUE, 'default' => 1, ), + 'mark_doubtful' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), ), 'primary key' => array('vid'), // 'unique keys' => array('vid'), @@ -366,7 +372,7 @@ function quiz_schema() { 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, - ), + ), 'question_nid' => array( 'type' => 'int', 'unsigned' => TRUE, @@ -414,6 +420,12 @@ function quiz_schema() { 'not null' => TRUE, 'default' => 1, ), + 'is_doubtful' => array( + 'type' => 'int', + 'not null' => TRUE, + 'default'=> 0, + 'size'=> 'tiny' + ), ), 'primary key' => array('result_id', 'question_nid', 'question_vid'), 'indexes' => array( @@ -742,6 +754,22 @@ function quiz_update_7405() { return t('Removed unsigned attribute from field time_start and time_end in quiz_node_results table'); } +/** + * Adding columns mark answers as doubtful + */ +function quiz_update_7406(&$sandbox) { + $spec = array( + 'type' => 'int', + 'not null' => TRUE, + 'default'=> 0, + 'size'=> 'tiny' + ); + db_add_field('quiz_node_results_answers','is_doubtful', $spec); + db_add_field('quiz_node_properties', 'mark_doubtful', $spec); + return t('Added new format fields to the tables'); +} + + /** * Implements hook_uninstall(). */ diff --git a/quiz.module b/quiz.module index 39549b023a2cf9a70247b5d397edb4a7f481823b..ceb74974aa2e856671a9dc01dd806ed46ee4f2e3 100644 --- a/quiz.module +++ b/quiz.module @@ -742,7 +742,8 @@ function quiz_insert($node) { 'allow_skipping' => $node->allow_skipping, 'allow_resume' => $node->allow_resume, 'allow_jumping' => $node->allow_jumping, - 'show_passed' => $node->show_passed + 'show_passed' => $node->show_passed, + 'mark_doubtful' => $node->mark_doubtful )) ->execute(); @@ -799,7 +800,8 @@ function quiz_update($node) { 'allow_skipping' => $node->allow_skipping, 'allow_resume' => $node->allow_resume, 'allow_jumping' => $node->allow_jumping, - 'show_passed' => $node->show_passed + 'show_passed' => $node->show_passed, + 'mark_doubtful' => $node->mark_doubtful )) ->condition('vid', $node->vid) ->condition('nid', $node->nid) @@ -933,6 +935,7 @@ function _quiz_get_node_defaults() { 'show_passed' => 1, 'quiz_open' => _quiz_form_prepare_date(), 'quiz_close' => _quiz_form_prepare_date(NULL, variable_get('quiz_default_close', 30)), + 'mark_doubtful' => 0, ); } @@ -968,7 +971,6 @@ function quiz_load($nodes) { $fetched_additions = (array) $query->execute()->fetch(); $additions = ($fetched_additions) ? (object) ($fetched_additions += $default_additions) : NULL; - // Fetching result options. $query = db_select('quiz_node_result_options', 'qnro'); $query->fields('qnro'); @@ -1139,7 +1141,12 @@ function quiz_form(&$node, &$form_state) { '#default_value' => $node->repeat_until_correct, '#description' => t('Require the user to re-try the question until they answer it correctly.'), ); - + $form['taking']['mark_doubtful'] = array( + '#type' => 'checkbox', + '#title' => t('Mark Doubtful'), + '#default_value' => $node->mark_doubtful, + '#description' => t('Allow user to mention if they are not sure about the answer'), + ); $form['taking']['show_passed'] = array( '#type' => 'checkbox', '#title' => t('Show passed status'), @@ -2335,6 +2342,7 @@ function quiz_store_question_result($quiz, $result, $options) { 'points_awarded' => $points, 'answer_timestamp' => REQUEST_TIME, 'is_skipped' => (int) $result->is_skipped, + 'is_doubtful' => (int) $result->is_doubtful, 'tid' => ($quiz->randomization == 3 && $result->tid) ? $result->tid : 0, )); @@ -2346,7 +2354,7 @@ function quiz_store_question_result($quiz, $result, $options) { } else { $insert = db_insert('quiz_node_results_answers') - ->fields(array('question_nid', 'question_vid', 'result_id', 'is_correct', 'points_awarded', 'answer_timestamp', 'is_skipped', 'number', 'tid')) + ->fields(array('question_nid', 'question_vid', 'result_id', 'is_correct', 'points_awarded', 'answer_timestamp', 'is_skipped', 'is_doubtful', 'number', 'tid')) ->values(array( 'question_nid' => $result->nid, 'question_vid' => $result->vid, @@ -2355,6 +2363,7 @@ function quiz_store_question_result($quiz, $result, $options) { 'points_awarded' => $points, 'answer_timestamp' => REQUEST_TIME, 'is_skipped' => (int) $result->is_skipped, + 'is_doubtful' => (int) $result->is_doubtful, 'number' => $options['question_data']['number'], 'tid' => ($quiz->randomization == 3 && $result->tid) ? $result->tid : 0, ))