Hi,

Love this module! We are using it with much success in our regular training sessions!

We are currently printing out (or at least saving to HTML) results for each trainee. It would be great if you could show username of the user that took the quiz at the top of the page.

Would this be difficult to implement?

Thanks!!!

CommentFileSizeAuthor
#3 quiz.admin_.inc_.txt98.89 KBratinakage
#1 quiz.admin_.inc_.txt98.74 KBratinakage
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ratinakage’s picture

FileSize
98.74 KB

Hi all,

I went into the code to see if I could fix this myself.

Before is said:

This person got 12 of 17 possible points.
Total score: 71 %

Now it says:

John Smith got 12 of 17 possible points.
Total score: 71 %

I think its much more user-friendly this way. I am not 100% sure how to create a patch so I just attached the quiz.admin_inc.txt file for review.

I added this line in function quiz_admin_results(...) line 359

$score[result_username] = db_result(db_query('SELECT name FROM {quiz_node_results} INNER JOIN {users} ON {quiz_node_results.uid = users.uid} WHERE result_id = %d', $rid));

And much further down in theme_quiz_admin_summary(...) line 1911

I changed the code to:

$params = array('%num_correct' => $score['numeric_score'], '%question_count' => $score['possible_score'], '%user_name' => $score['result_username']);
$output .= '<div id="quiz_score_possible">'. t('%user_name got %num_correct of %question_count possible points.', $params) .'</div>'."\n";

I am quite new to PHP and Drupal module development so please let me know if I have done anything wrong. I have tested and it seems to work nicely for me. Would you add this to the release?

Thanks!!

ratinakage’s picture

Status: Active » Needs review
ratinakage’s picture

Component: Code » Code - Import/Export
FileSize
98.89 KB

Bump!

Hey guys, I'm not great with adding patches but this seems to work nicely for me at least.

I've patched the latest version of the quiz with my change and its still working. Its a pretty small fix.

Hopefully one of you can help me submit it to dev??

Thanks!

rennsix’s picture

As of 6.x-4.4 you can add this little line to quiz/quiz.pages.inc after line 527

$output .= (check_plain($user->name));

Here is the whole function with new output to spit out the username.

function theme_quiz_user_summary($quiz, $questions, $score, $summary) {
  // Set the title here so themers can adjust.
  drupal_set_title(check_plain($quiz->title));

  if (!$score['is_evaluated']) {
    $msg = t('Parts of this @quiz have not been evaluated yet. The score below is not final.', array('@quiz' => QUIZ_NAME));
    drupal_set_message($msg, 'status');
  }

  global $user;
 
  // Display overall result.
  $output = '';
  $output .= (check_plain($user->name)); 
  $output .= '<div id="quiz_score_possible">'. t('You got %num_correct of %question_count possible points.', array('%num_correct' => $score['numeric_score'], '%question_count' => $score['possible_score'])) .'</div>'."\n";
  $output .= '<div id="quiz_score_percent">'. t('Your score was: @score %', array('@score' => $score['percentage_score'])) .'</div>'."\n";
  if (isset($summary['passfail']))
    $output .= '<div id="quiz_summary">'. $summary['passfail'] .'</div>'."\n";
  if (isset($summary['result']))
    $output .= '<div id="quiz_summary">'. $summary['result'] .'</div>'."\n";
  // Get the feedback for all questions.
  $output .= drupal_get_form('quiz_report_form', $questions, FALSE, TRUE);
  return $output;
}
ezraw’s picture

Version: 6.x-4.0 » 7.x-5.x-dev
Component: Code - Import/Export » Code - Quiz core
Issue summary: View changes
MBroberg’s picture

The code in #1 and #3 worked for me in v. 6x-4.4. I can see username on the admin pages.
The code in #4 is for the logged in user and only works for that user to see his own results.

djdevin’s picture

Status: Needs review » Closed (fixed)

Was fixed #2386103: Decouple quiz result/scoring

!username got %num_correct of %question_count possible points.