You are here

function theme_multichoice_answer_node_view in Quiz 8.4

Same name and namespace in other branches
  1. 8.6 question_types/quiz_multichoice/theme/multichoice.theme.inc \theme_multichoice_answer_node_view()
  2. 8.5 question_types/quiz_multichoice/theme/multichoice.theme.inc \theme_multichoice_answer_node_view()
  3. 6.4 question_types/multichoice/theme/multichoice.theme.inc \theme_multichoice_answer_node_view()
  4. 7.6 question_types/multichoice/theme/multichoice.theme.inc \theme_multichoice_answer_node_view()
  5. 7 question_types/multichoice/theme/multichoice.theme.inc \theme_multichoice_answer_node_view()
  6. 7.4 question_types/multichoice/theme/multichoice.theme.inc \theme_multichoice_answer_node_view()
  7. 7.5 question_types/multichoice/theme/multichoice.theme.inc \theme_multichoice_answer_node_view()

Theme the answer part of the node view

Parameters

$alternatives: Array of alternatives. Each alternative is also an array with all the data for each alternative.

$show_correct: True if the user is allowed to view the solution

1 theme call to theme_multichoice_answer_node_view()
MultichoiceQuestion::getNodeView in question_types/multichoice/lib/Drupal/multichoice/MultichoiceQuestion.php
Implementation of getNodeView

File

question_types/multichoice/multichoice.theme.inc, line 49
The theme file for multichoice.

Code

function theme_multichoice_answer_node_view($variables) {
  $alternatives = $variables['alternatives'];
  $show_correct = $variables['show_correct'];
  $header = array(
    '',
    '',
  );
  $p = drupal_get_path('module', 'multichoice');
  drupal_add_css($p . '/css/multichoice.css');
  foreach ($alternatives as $i => $short) {
    $answer_markup = check_markup($short['answer'], $short['answer_format']);

    // Find the is_correct status
    $is_correct = $short['score_if_chosen'] > $short['score_if_not_chosen'];
    $image = $is_correct ? 'correct' : 'wrong';
    if (!$show_correct) {
      $image = 'unknown';
    }
    $rows[] = array(
      array(
        'data' => array(
          '#theme' => 'html_tag',
          '#tag' => 'span',
          '#attributes' => array(
            'class' => array(
              'multichoice-icon',
              $image,
            ),
            'title' => $show_correct ? t('Score if chosen: @sc Score if not chosen: @nc', array(
              '@sc' => $short['score_if_chosen'],
              '@nc' => $short['score_if_not_chosen'],
            )) : t('You are not allowed to view the solution for this question'),
          ),
        ),
        'class' => array(
          'multichoice-icon-cell',
        ),
      ),
      $answer_markup,
    );
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
}