| 1 |
<?php
|
| 2 |
// $Id: quiz.install,v 1.28 2009/08/13 16:48:17 sivaji Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Quiz install schema for installing the quiz module
|
| 7 |
*
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_update_N().
|
| 12 |
* Adding a new field to save timer status for a timed quiz.
|
| 13 |
*/
|
| 14 |
function quiz_update_6306() {
|
| 15 |
$result = array();
|
| 16 |
db_add_field($result, 'quiz_node_results', 'time_left', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
|
| 17 |
return $result;
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Implementation of hook_update_N().
|
| 22 |
* Adding new field to integrate quiz node and userpoints modules
|
| 23 |
*/
|
| 24 |
function quiz_update_6305() {
|
| 25 |
$result = array();
|
| 26 |
|
| 27 |
db_add_field($result, 'quiz_node_properties', 'has_userpoints', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
|
| 28 |
|
| 29 |
return $result;
|
| 30 |
}
|
| 31 |
|
| 32 |
/**
|
| 33 |
* Implementation of hook_update_N().
|
| 34 |
*
|
| 35 |
*/
|
| 36 |
|
| 37 |
function quiz_update_6304() {
|
| 38 |
$result = array();
|
| 39 |
db_add_field($result, 'quiz_node_relationship', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
|
| 40 |
|
| 41 |
return $result;
|
| 42 |
}
|
| 43 |
|
| 44 |
/**
|
| 45 |
* Implementation of hook_update_N().
|
| 46 |
* Add new field for invalidating entire quizzes. Use it on those mean cheaters.
|
| 47 |
*/
|
| 48 |
function quiz_update_6303() {
|
| 49 |
$result = array();
|
| 50 |
|
| 51 |
// Add a field that allows an admin to mark a quiz as invalid.
|
| 52 |
db_add_field($result, 'quiz_node_results', 'is_invalid', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
|
| 53 |
|
| 54 |
return $result;
|
| 55 |
}
|
| 56 |
|
| 57 |
/**
|
| 58 |
* Implementation of hook_update_N().
|
| 59 |
* Add and rearrange indexes across several of the tables.
|
| 60 |
*/
|
| 61 |
function quiz_update_6302() {
|
| 62 |
$result = array();
|
| 63 |
db_add_index($result, 'quiz_node_result_options', 'quiz_id', array('vid, nid'));
|
| 64 |
db_add_index($result, 'quiz_node_properties', 'quiz_id', array('vid, nid'));
|
| 65 |
db_add_index($result, 'quiz_node_results', 'user_results', array('uid', 'vid', 'nid'));
|
| 66 |
|
| 67 |
return $result;
|
| 68 |
}
|
| 69 |
/**
|
| 70 |
* Implementation of hook_update_N().
|
| 71 |
* Add is_skipped column to quiz answer field. This allows questions to be skipped.
|
| 72 |
*/
|
| 73 |
function quiz_update_6301() {
|
| 74 |
$result = array();
|
| 75 |
|
| 76 |
// Do this:
|
| 77 |
//'is_skipped' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 78 |
db_add_field($result, 'quiz_node_results_answers', 'is_skipped', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
|
| 79 |
return $result;
|
| 80 |
}
|
| 81 |
|
| 82 |
/**
|
| 83 |
* Implementation of hook_update_N().
|
| 84 |
* Add aid to quiz_node_properties table.
|
| 85 |
*/
|
| 86 |
function quiz_update_6300() {
|
| 87 |
$result = array();
|
| 88 |
db_add_field($result, 'quiz_node_properties', 'aid', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
|
| 89 |
return $result;
|
| 90 |
}
|
| 91 |
|
| 92 |
/**
|
| 93 |
* Implementation of hook_install()
|
| 94 |
*/
|
| 95 |
function quiz_install() {
|
| 96 |
// Create Tables
|
| 97 |
drupal_install_schema('quiz');
|
| 98 |
// Default the "Show Author and Date" for quiz nodes to OFF.
|
| 99 |
$temp_array = variable_get('theme_settings', array());
|
| 100 |
$temp_array['toggle_node_info_quiz'] = 0;
|
| 101 |
variable_set('theme_settings', $temp_array);
|
| 102 |
drupal_set_message(t('Quiz module has been enabled. To !create_a_quiz go to Content Management -> Create Content -> Quiz.', array('!create_a_quiz' => l(t('create a quiz'), 'node/add/quiz'))));
|
| 103 |
}
|
| 104 |
|
| 105 |
/**
|
| 106 |
* Implementation of hook_schema().
|
| 107 |
*/
|
| 108 |
function quiz_schema() {
|
| 109 |
$schema = array();
|
| 110 |
/**
|
| 111 |
* Connect all the quiz specific properties to the correct version of a quiz.
|
| 112 |
*/
|
| 113 |
// Create the quiz node properties table
|
| 114 |
$schema['quiz_node_properties'] = array(
|
| 115 |
'fields' => array(
|
| 116 |
'property_id' => array(
|
| 117 |
'type' => 'serial',
|
| 118 |
'unsigned' => TRUE,
|
| 119 |
'not null' => TRUE,
|
| 120 |
),
|
| 121 |
'vid' => array(
|
| 122 |
'type' => 'int',
|
| 123 |
'unsigned' => TRUE,
|
| 124 |
'not null' => TRUE,
|
| 125 |
),
|
| 126 |
'nid' => array(
|
| 127 |
'type' => 'int',
|
| 128 |
'unsigned' => TRUE,
|
| 129 |
'not null' => TRUE,
|
| 130 |
),
|
| 131 |
'aid' => array(
|
| 132 |
'type' => 'varchar',
|
| 133 |
'length' => 255,
|
| 134 |
'not null' => TRUE,
|
| 135 |
),
|
| 136 |
'number_of_random_questions' => array(
|
| 137 |
'type' => 'int',
|
| 138 |
'size' => 'tiny',
|
| 139 |
'unsigned' => TRUE,
|
| 140 |
'not null' => TRUE,
|
| 141 |
'default' => 0,
|
| 142 |
),
|
| 143 |
'pass_rate' => array(
|
| 144 |
'type' => 'int',
|
| 145 |
'size' => 'tiny',
|
| 146 |
'unsigned' => TRUE,
|
| 147 |
'not null' => TRUE,
|
| 148 |
),
|
| 149 |
'summary_pass' => array(
|
| 150 |
'type' => 'text',
|
| 151 |
),
|
| 152 |
'summary_default' => array(
|
| 153 |
'type' => 'text',
|
| 154 |
),
|
| 155 |
'shuffle' => array(
|
| 156 |
'type' => 'int',
|
| 157 |
'size' => 'tiny',
|
| 158 |
'unsigned' => TRUE,
|
| 159 |
'not null' => TRUE,
|
| 160 |
),
|
| 161 |
'backwards_navigation' => array(
|
| 162 |
'type' => 'int',
|
| 163 |
'size' => 'tiny',
|
| 164 |
'unsigned' => TRUE,
|
| 165 |
'not null' => TRUE,
|
| 166 |
),
|
| 167 |
'feedback_time' => array(
|
| 168 |
'type' => 'int',
|
| 169 |
'size' => 'tiny',
|
| 170 |
'unsigned' => TRUE,
|
| 171 |
'not null' => TRUE,
|
| 172 |
),
|
| 173 |
'quiz_open' => array(
|
| 174 |
'type' => 'int',
|
| 175 |
'unsigned' => TRUE,
|
| 176 |
'not null' => TRUE,
|
| 177 |
'default' => 0,
|
| 178 |
),
|
| 179 |
'quiz_close' => array(
|
| 180 |
'type' => 'int',
|
| 181 |
'unsigned' => TRUE,
|
| 182 |
'not null' => TRUE,
|
| 183 |
'default' => 0,
|
| 184 |
),
|
| 185 |
'takes' => array(
|
| 186 |
'type' => 'int',
|
| 187 |
'size' => 'tiny',
|
| 188 |
'unsigned' => TRUE,
|
| 189 |
'not null' => TRUE,
|
| 190 |
),
|
| 191 |
'time_limit' => array(
|
| 192 |
'type' => 'int',
|
| 193 |
'unsigned' => TRUE,
|
| 194 |
'not null' => TRUE,
|
| 195 |
'default' => 0,
|
| 196 |
),
|
| 197 |
'quiz_always' => array(
|
| 198 |
'type' => 'int',
|
| 199 |
'size' => 'tiny',
|
| 200 |
'not null' => TRUE,
|
| 201 |
'default' => 0
|
| 202 |
),
|
| 203 |
'tid' => array(
|
| 204 |
'type' => 'int',
|
| 205 |
'unsigned' => TRUE,
|
| 206 |
'not null' => TRUE,
|
| 207 |
'default' => 0,
|
| 208 |
),
|
| 209 |
'has_userpoints' => array(
|
| 210 |
'type' => 'int',
|
| 211 |
'size' => 'tiny',
|
| 212 |
'unsigned' => TRUE,
|
| 213 |
'not null' => TRUE,
|
| 214 |
'default' => 0
|
| 215 |
),
|
| 216 |
'time_left' => array(
|
| 217 |
'type' => 'int',
|
| 218 |
'size' => 'small',
|
| 219 |
'not null' => TRUE,
|
| 220 |
'default' => 0
|
| 221 |
),
|
| 222 |
),
|
| 223 |
'primary key' => array('property_id'),
|
| 224 |
// 'unique keys' => array('vid'),
|
| 225 |
'indexes' => array('quiz_id' => array('vid', 'nid')),
|
| 226 |
);
|
| 227 |
|
| 228 |
/*
|
| 229 |
* Both a quiz and a quiz question are nodes with versions. A quiz is a parent node of a quiz question,
|
| 230 |
* making the quiz question the child.
|
| 231 |
*
|
| 232 |
* The quiz_node_relationship table stores this relationship in a way that allows a quiz question to be
|
| 233 |
* the child of multiple quizzes without losing version history.
|
| 234 |
*
|
| 235 |
* Future functionality will allow a quiz question to be a parent of another quiz question with the same
|
| 236 |
* data model. This will make adaptive quiz functionality possible without redesign.
|
| 237 |
*/
|
| 238 |
// Create the quiz node relationship table
|
| 239 |
$schema['quiz_node_relationship'] = array(
|
| 240 |
'fields' => array(
|
| 241 |
'parent_nid' => array(
|
| 242 |
'type' => 'int',
|
| 243 |
'unsigned' => TRUE,
|
| 244 |
'not null' => TRUE,
|
| 245 |
),
|
| 246 |
'parent_vid' => array(
|
| 247 |
'type' => 'int',
|
| 248 |
'unsigned' => TRUE,
|
| 249 |
'not null' => TRUE,
|
| 250 |
),
|
| 251 |
'child_nid' => array(
|
| 252 |
'type' => 'int',
|
| 253 |
'unsigned' => TRUE,
|
| 254 |
'not null' => TRUE,
|
| 255 |
),
|
| 256 |
'child_vid' => array(
|
| 257 |
'type' => 'int',
|
| 258 |
'unsigned' => TRUE,
|
| 259 |
'not null' => TRUE,
|
| 260 |
),
|
| 261 |
'question_status' => array(
|
| 262 |
'type' => 'int',
|
| 263 |
'size' => 'tiny',
|
| 264 |
'unsigned' => TRUE,
|
| 265 |
'not null' => TRUE,
|
| 266 |
'default' => 1,
|
| 267 |
),
|
| 268 |
'weight' => array(
|
| 269 |
'type' => 'int',
|
| 270 |
'not null' => TRUE,
|
| 271 |
'default' => 0
|
| 272 |
),
|
| 273 |
),
|
| 274 |
'primary key' => array('parent_nid', 'parent_vid', 'child_nid', 'child_vid'),
|
| 275 |
);
|
| 276 |
|
| 277 |
/*
|
| 278 |
* This connects all the quiz question specific properties to the correct version of a quiz question.
|
| 279 |
*/
|
| 280 |
// Create the quiz node question properties table
|
| 281 |
// XXX: This should be considered deprecated, as it is highly specific to multichoice.
|
| 282 |
$schema['quiz_node_question_properties'] = array(
|
| 283 |
'fields' => array(
|
| 284 |
'nid' => array(
|
| 285 |
'type' => 'int',
|
| 286 |
'unsigned' => TRUE,
|
| 287 |
'not null' => TRUE,
|
| 288 |
),
|
| 289 |
'vid' => array(
|
| 290 |
'type' => 'int',
|
| 291 |
'unsigned' => TRUE,
|
| 292 |
'not null' => TRUE,
|
| 293 |
),
|
| 294 |
'number_of_answers' => array(
|
| 295 |
'type' => 'int',
|
| 296 |
'size' => 'tiny',
|
| 297 |
'unsigned' => TRUE,
|
| 298 |
'not null' => TRUE,
|
| 299 |
'default' => 1,
|
| 300 |
),
|
| 301 |
//'multianswer' => array('type' => 'int', 'size' =>'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 302 |
),
|
| 303 |
);
|
| 304 |
|
| 305 |
/**
|
| 306 |
* Quiz specific options concerning availability and access to scores.
|
| 307 |
*/
|
| 308 |
// Create the quiz node results table
|
| 309 |
$schema['quiz_node_results'] = array(
|
| 310 |
'fields' => array(
|
| 311 |
'result_id' => array(
|
| 312 |
'type' => 'serial',
|
| 313 |
'size' => 'normal',
|
| 314 |
'unsigned' => TRUE,
|
| 315 |
'not null' => TRUE,
|
| 316 |
),
|
| 317 |
'nid' => array(
|
| 318 |
'type' => 'int',
|
| 319 |
'unsigned' => TRUE,
|
| 320 |
'not null' => TRUE,
|
| 321 |
),
|
| 322 |
'vid' => array(
|
| 323 |
'type' => 'int',
|
| 324 |
'unsigned' => TRUE,
|
| 325 |
'not null' => TRUE,
|
| 326 |
),
|
| 327 |
'uid' => array(
|
| 328 |
'type' => 'int',
|
| 329 |
'unsigned' => TRUE,
|
| 330 |
'not null' => TRUE,
|
| 331 |
),
|
| 332 |
'time_start' => array(
|
| 333 |
'type' => 'int',
|
| 334 |
'unsigned' => TRUE,
|
| 335 |
'default' => 0,
|
| 336 |
),
|
| 337 |
'time_end' => array(
|
| 338 |
'type' => 'int',
|
| 339 |
'unsigned' => TRUE,
|
| 340 |
'default' => 0,
|
| 341 |
),
|
| 342 |
'released' => array(
|
| 343 |
'type' => 'int',
|
| 344 |
'unsigned' => TRUE,
|
| 345 |
'default' => 0,
|
| 346 |
),
|
| 347 |
'score' => array(
|
| 348 |
'type' => 'int',
|
| 349 |
'size' => 'tiny',
|
| 350 |
'not null' => TRUE,
|
| 351 |
'default' => 0,
|
| 352 |
),
|
| 353 |
'is_invalid' => array(
|
| 354 |
'type' => 'int',
|
| 355 |
'size' => 'tiny',
|
| 356 |
'unsigned' => TRUE,
|
| 357 |
'not null' => TRUE,
|
| 358 |
'default' => 0
|
| 359 |
),
|
| 360 |
'time_left' => array(
|
| 361 |
'type' => 'int',
|
| 362 |
'size' => 'small',
|
| 363 |
'not null' => TRUE,
|
| 364 |
'default' => 0
|
| 365 |
),
|
| 366 |
),
|
| 367 |
'primary key' => array('result_id'),
|
| 368 |
'indexes' => array(
|
| 369 |
'user_results' => array('uid', 'vid', 'nid'),
|
| 370 |
),
|
| 371 |
);
|
| 372 |
|
| 373 |
/**
|
| 374 |
* Information about a particular question in a result
|
| 375 |
*/
|
| 376 |
$schema['quiz_node_results_answers'] = array(
|
| 377 |
'fields' => array(
|
| 378 |
'result_id' => array(
|
| 379 |
'type' => 'int',
|
| 380 |
'unsigned' => TRUE,
|
| 381 |
'not null' => TRUE,
|
| 382 |
),
|
| 383 |
'question_nid' => array(
|
| 384 |
'type' => 'int',
|
| 385 |
'unsigned' => TRUE,
|
| 386 |
'not null' => TRUE,
|
| 387 |
),
|
| 388 |
'question_vid' => array(
|
| 389 |
'type' => 'int',
|
| 390 |
'unsigned' => TRUE,
|
| 391 |
'not null' => TRUE,
|
| 392 |
),
|
| 393 |
'is_correct' => array(
|
| 394 |
'type' => 'int',
|
| 395 |
'size' => 'tiny',
|
| 396 |
'unsigned' => TRUE,
|
| 397 |
'not null' => TRUE,
|
| 398 |
'default' => 0,
|
| 399 |
),
|
| 400 |
'is_skipped' => array(
|
| 401 |
'type' => 'int',
|
| 402 |
'size' => 'tiny',
|
| 403 |
'unsigned' => TRUE,
|
| 404 |
'not null' => TRUE,
|
| 405 |
'default' => 0
|
| 406 |
),
|
| 407 |
'points_awarded' => array(
|
| 408 |
'type' => 'int',
|
| 409 |
'size' => 'tiny',
|
| 410 |
'unsigned' => TRUE,
|
| 411 |
'not null' => TRUE,
|
| 412 |
'default' => 0,
|
| 413 |
),
|
| 414 |
'answer_timestamp' => array(
|
| 415 |
'type' => 'int',
|
| 416 |
'unsigned' => TRUE,
|
| 417 |
'not null' => TRUE,
|
| 418 |
),
|
| 419 |
),
|
| 420 |
'primary key' => array('result_id', 'question_nid', 'question_vid')
|
| 421 |
);
|
| 422 |
|
| 423 |
/**
|
| 424 |
* Allows custom feedback based on the results of a user completing a quiz.
|
| 425 |
*/
|
| 426 |
// Create the quiz node result options table
|
| 427 |
$schema['quiz_node_result_options'] = array(
|
| 428 |
'fields' => array(
|
| 429 |
'option_id' => array(
|
| 430 |
'type' => 'serial',
|
| 431 |
'size' => 'normal',
|
| 432 |
'unsigned' => TRUE,
|
| 433 |
'not null' => TRUE,
|
| 434 |
),
|
| 435 |
'nid' => array(
|
| 436 |
'type' => 'int',
|
| 437 |
'unsigned' => TRUE,
|
| 438 |
'not null' => TRUE,
|
| 439 |
),
|
| 440 |
'vid' => array(
|
| 441 |
'type' => 'int',
|
| 442 |
'unsigned' => TRUE,
|
| 443 |
'not null' => TRUE,
|
| 444 |
),
|
| 445 |
'option_name' => array(
|
| 446 |
'type' => 'varchar',
|
| 447 |
'length' => 255,
|
| 448 |
'not null' => TRUE,
|
| 449 |
),
|
| 450 |
'option_summary' => array(
|
| 451 |
'type' => 'text',
|
| 452 |
),
|
| 453 |
'option_start' => array(
|
| 454 |
'type' => 'int',
|
| 455 |
'unsigned' => TRUE,
|
| 456 |
'default' => 0,
|
| 457 |
),
|
| 458 |
'option_end' => array(
|
| 459 |
'type' => 'int',
|
| 460 |
'unsigned' => TRUE,
|
| 461 |
'default' => 0,
|
| 462 |
),
|
| 463 |
),
|
| 464 |
'primary key' => array('option_id'),
|
| 465 |
'indexes' => array(
|
| 466 |
'quiz_id' => array('vid, nid'),
|
| 467 |
)
|
| 468 |
);
|
| 469 |
return $schema;
|
| 470 |
}
|
| 471 |
|
| 472 |
/**
|
| 473 |
* Implementation of hook_uninstall()
|
| 474 |
*/
|
| 475 |
function quiz_uninstall() {
|
| 476 |
drupal_uninstall_schema('quiz');
|
| 477 |
$var = array(
|
| 478 |
'quiz_name',
|
| 479 |
'quiz_default_close',
|
| 480 |
'quiz_use_passfail',
|
| 481 |
'quiz_default_pass_rate',
|
| 482 |
'quiz_action_type',
|
| 483 |
'quiz_action_type',
|
| 484 |
'quiz_email_results',
|
| 485 |
'quiz_email_results_body',
|
| 486 |
'quiz_email_results_subject',
|
| 487 |
'quiz_has_timer',
|
| 488 |
'quiz_has_userpoints',
|
| 489 |
'quiz_max_result_options',
|
| 490 |
'quiz_remove_partial_quiz_record',
|
| 491 |
'quiz_show_allowed_times',
|
| 492 |
'quiz_autotitle_length'
|
| 493 |
);
|
| 494 |
foreach ($var as $v) {
|
| 495 |
variable_del($v);
|
| 496 |
}
|
| 497 |
}
|