1

There is a template file in the quiz/template/quiz-report-form.tpl.php of Quiz module. this is the code:

<?php

/**
 * @file
 * Themes the question report
 *
 * Available variables:
 * $form - FAPI array
 *
 * All questions are in form[x] where x is an integer.
 * Useful values:
 * $form[x]['question'] - the question as a FAPI array(usually a form field of type "markup")
 * $form[x]['score'] - the users score on the current question.(FAPI array usually of type "markup" or "textfield")
 * $form[x]['max_score'] - the max score for the current question.(FAPI array of type "value")
 * $form[x]['response'] - the users response, usually a FAPI array of type markup.
 * $form[x]['#is_correct'] - If the users response is correct(boolean)
 * $form[x]['#is_evaluated'] - If the users response has been evaluated(boolean)
 */
// $td_classes = array('quiz-report-odd-td', 'quiz-report-even-td');
// $td_class_i = 0;
$p = drupal_get_path('module', 'quiz') .'/theme/';
$q_image = $p. 'question_bg.png';
?>
<h2><?php print t('Question Results');?></h2>
<div class="quiz-report">
<?php
foreach ($form as $key => $sub_form):
  if (!is_numeric($key) || isset($sub_form['#no_report'])) continue;
  unset($form[$key]);
  $c_class = ($sub_form['#is_evaluated']) ? ($sub_form['#is_correct']) ? 'q-correct' : 'q-wrong' : 'q-waiting';
  $skipped = $sub_form['#is_skipped'] ? '<span class="quiz-report-skipped">'. t('(skipped)') .'</span>' : ''?>

    <div class="dt">
      <div class="quiz-report-score-container <?php print $c_class?>">
        <span>
          <?php print t('Score')?>
        <?php print drupal_render($sub_form['score'])?>
        <?php print t('of') .' '. $sub_form['max_score']['#value']?>
        <?php print '<br><em>'. $skipped .'</em>'?>
      </span>
    </div>
      <p class="quiz-report-question"><strong><?php print t('Question')?>: </strong></p>
      <?php print drupal_render($sub_form['question']);?>
    </div>
  <div class="dd">
    <p><strong><?php print t('Response')?>: </strong></p>
    <?php print drupal_render($sub_form['response']); ?>
  </div>
  <div class="dd">
    <?php print drupal_render($sub_form['answer_feedback']); ?>
  </div>
<?php endforeach; ?>
</div>
<div class="quiz-score-submit"><?php print drupal_render_children($form);?></div>

Now I want to change this codes and I need a function to return the nid(number of id) of quiz that the user is seeing. please help me.

  • have u check this thread drupal.org/node/1989052 it may help u – Ali Nouman Aug 2 '13 at 18:21
  • Do you only want the quiz' NID, then arg(1) is all you need. But if you need the NID of the current question, then this answer may help you. – leymannx Sep 28 '15 at 12:47
0

Here is a very simple way to get the nid of the node currently being viewed:

$path = current_path();
list($entity_type, $entity_id) = explode('/', $path);

After this, you will have the entity id (the nid in the case of nodes) in the variable $entity_id.

  • Or menu_get_object()? (anything that avoids using the awful list() function goes in the win column for me). Bear in mind this will only work for nodes, and entities who specifically define their URI as entity_type/%, and entities whose URI callback function hasn't been overwritten to move the identifier within the path. It also won't work for entities like taxonomy terms, whose path is taxonomy/term/%. menu_get_object() is considered the best solution for nodes specifically. – Clive Oct 1 '13 at 13:07
  • You are right, but since the OP specifically asked for an nid, IMO generic application isn't a high priority concern here. And since it will go into a template file, there is effectively 0 risk of a misfire. As for list(), I find it simple and concise. – Jovean Oct 1 '13 at 14:02
  • 1
    Sure, there are quite a few ways to skin that particular cat - it's just menu_get_object() is the recommended one. – Clive Oct 1 '13 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.