You are here

multichoice-alternative.tpl.php in Quiz 6.4

Handles the layout of the multichoice answering form

Variables available:

  • $form

File

question_types/multichoice/theme/multichoice-alternative.tpl.php
View source
<?php

/**
 * @file
 * Handles the layout of the multichoice answering form
 *
 *
 * Variables available:
 * - $form
 */
$p = drupal_get_path('module', 'multichoice');
drupal_add_css($p . '/theme/multichoice.css', 'module', 'all');

// Add script for using the entire alternative row as a button
drupal_add_js("Drupal.behaviors.multichoiceAlternativeBehavior = function(context) {\n  \$('.multichoice_row')\n  .filter(':has(:checkbox:checked)')\n  .addClass('selected')\n  .end()\n  .click(function(event) {\n    \$(this).toggleClass('selected');\n    if (event.target.type !== 'checkbox') {\n      \$(':checkbox', this).attr('checked', function() {\n        return !this.checked;\n      });\n      \$(':radio', this).attr('checked', true);\n      if (\$(':radio', this).html() != null) {\n        \$('.multichoice_row').removeClass('selected');\n    \t  \$(this).addClass('selected');\n      }\n    }\n  });\n};", 'inline');

// We want to have the checkbox in one table cell, and the title in the next. We store the checkbox and the titles
$options = $form['#options'];
$fullOptions = array();
$titles = array();
foreach ($options as $key => $value) {
  $fullOptions[$key] = $form[$key];
  $titles[$key] = $form[$key]['#title'];
  $fullOptions[$key]['#title'] = '';
  unset($form[$key]);
}
unset($form['#options']);
print drupal_render($form);

// We use the stored checkboxes and titles to generate a table for the alternatives
foreach ($titles as $key => $value) {
  $row = array();
  $row[] = array(
    'data' => drupal_render($fullOptions[$key]),
    'width' => 35,
    'class' => 'selector-td',
  );
  $row[] = $value;
  $rows[] = array(
    'data' => $row,
    'class' => 'multichoice_row',
  );
}
print theme('table', NULL, $rows);