Hi,

I have a system where users answer randomly generated exams and I want to create a view that displays for each participant their answer key, e.g. AABBCCEAB, and their (individual) correct answer key, e.g. AABBECBAB.

This is no problem and I have done this successfully, but now I would like to make things easier for me and put the rows in bold when the keys match. How should I do this? Currently I have a content type "exam" with fields "student-name", "entered-key" and "correct-key", but when creating a view I cannot find any option to do conditional things with them, like putting the row in bold when the keys match.

E.g. desired output:

Stu Dent AABCC AABCC
Stu Pid EAAAB DCBEA
Smart One AABCC AABCC
Al Most CEBAB CEDAB
Pri Mus DDEAB DDEAB

Comments

webviper’s picture

This would be pretty straightforward with jQuery, or if you want to do it on the Views side you could use the Views PHP module. If you install the Views PHP module go through the following steps -

1. Exclude the "entered-key" and "correct-key" fields from display, but dont remove them as you need their values for the next step.
2. Add two Global: PHP fields (that will serve to display the text from the "entered-key" and "correct-key" in bolded or normal font).
3. In each of these fields you can use code like this -

// If they are equal, use a span, or class, or strong to bold them, using span in this case
if ($data->field_field_entered_key[0]['raw']['value'] == $data->field_field_correct_key[0]['raw']['value']) {
  echo '<span style="font-weight: bold">' . field_field_entered_key[0]['raw']['value'] . '</span>';
}
else {
  echo field_field_entered_key[0]['raw']['value'];
}

That will take care of bolding one field, to bold the other one just use the same code in the other Global: PHP field, except this time output the correct-key field (field_field_correct_key[0]['raw']['value'])

Borris’s picture

Aha! Yes, the $data->field_field_... did the trick, thanks!
I had already tried Views PHP with the $row->field_... as suggested by that module, but that didn't work for some reason (it's still quite buggy apparently).