I'm working on a web based tutorial in four languages. When choosing questions for a quiz, since all the questions for all the previous quizzes are available to choose from, I only want to see those in the same language as the node.

I edited quiz.module...

added a helper function:

/**
 * Get the language of a node if i18n installed
 *
 * @return
 *  node language or ' '
 * 
 * @ingroup helper functions
 */
function _node_get_lang($node) {
	if (function_exists('i18n_node_get_lang')) {
		$node_lang = i18n_node_get_lang($node->nid);
		if (empty($node_lang)) {
			$node_lang = ' '; 
		}
	}		
	return $node_lang;
}

and edited the function _quiz_get_unused_questions($quiz_vid = NULL, $nid_keys = FALSE) { starting line 1667:

	
	// Only include questions in the same language as the node (if the node has an assigned language)
	$quiz_lang = _node_get_lang($quiz);
	
  // Create questions array.
  if ($nid_keys === FALSE) {
    while ($node = db_fetch_object($result)) {
			if ($quiz_lang == _node_get_lang($node)) {
				$questions[] = quiz_node_map($node);
			}
    }
  }
  else {
    while ($node = db_fetch_object($result)) {
			if ($quiz_lang == _node_get_lang($node)) {
	      $n = quiz_node_map($node);
	      $questions[$n->nid] = $n;
			}
    }
  }

  return $questions;
}

Maybe this would help other people

cheers,

Marcus

Comments

marcus_clements’s picture

Title: Only show questions in the same language as the node » Only show questions in the same language as the quiz

OK so I should have waited till it was a bit more useful before posting.
This version makes available to the quiz questions in any language if the language of the quiz is not set and any questions that do not have a language set.

Oh and I fixed a stupidity in the helper function :) (which I placed at the end of the module BTW)


/**
 * Get the language of a node if i18n installed
 *
 * @return
 *  node language or ' '
 * 
 * @ingroup helper functions
 */
function _node_get_lang($node) {
	$node_lang = "";
	if (function_exists('i18n_node_get_lang')) {
		$node_lang = i18n_node_get_lang($node->nid);
	}		
	return $node_lang;
}

in

function _quiz_get_unused_questions($quiz_vid = NULL, $nid_keys = FALSE) {

from line 1690:

	// Only include questions in the same language as the node (if the node has an assigned language)
	$quiz_lang = _node_get_lang($quiz);
	
  // Create questions array.
  if ($nid_keys === FALSE) {
    while ($node = db_fetch_object($result)) {
			$node_lang =  _node_get_lang($node);
			if (empty($quiz_lang) || empty ($node_lang) || $quiz_lang == $node_lang) {
				$questions[] = quiz_node_map($node);
			}
    }
  }
  else {
    while ($node = db_fetch_object($result)) {
			$node_lang =  _node_get_lang($node);
			if (empty($quiz_lang) || empty ($node_lang) || $quiz_lang == $node_lang) {
	      $n = quiz_node_map($node);
	      $questions[$n->nid] = $n;
			}
    }
  }
  return $questions;
}

cheers

Marcus

marcus_clements’s picture

Status: Active » Needs review
StatusFileSize
new1.47 KB

OK here's a patch for this issue against the 5.x-2.0-rc1 version. Please review and comment.

Marcus

marcus_clements’s picture

Version: 5.x-2.0-beta4 » 5.x-2.0-rc1
westwesterson’s picture

will test this when i have the chance, would be great for international users to test this as well.

hanskuiters’s picture

Tested it in a fresh install with three languages. All seems working fine. Thanks!

mbutcher’s picture

Status: Needs review » Fixed

I believe that this should have been marked "fixed" a while back. If anyone notices problems in the 6x-2.0 development builds, please re-open this and provide *lots* of information.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

hanskuiters’s picture

Status: Closed (fixed) » Active

Need to add something to this thread.

I tested when no user is logged in. Translation block breaks. I commented out the page refresh in line 886-888 and 949-951 which should prevent caching. Translation block is working right now.

But the prevent caching is there for a reason, right? No solution for that yet, but I don't seem to have caching problems.

falcon’s picture

Version: 5.x-2.0-rc1 » 6.x-5.x-dev

I think this still needs to be fixed for the new version of quiz. (I'm cleaning up the issue list)

eloivaque’s picture

Version: 6.x-5.x-dev » 7.x-4.0-alpha10
Component: Code » Code - Import/Export
StatusFileSize
new1.11 KB

I have a same problem with version 7. attatched patch.

borgewarvik’s picture

Version: 7.x-4.0-alpha10 » 7.x-4.x-dev
Component: Code - Import/Export » Code - Quiz core
Status: Active » Reviewed & tested by the community

We have tested latest patch and it works on a multilanguage site we are working on.

sivaji_ganesh_jojodae’s picture

Status: Reviewed & tested by the community » Fixed

@eloiv and @borgewarvik, i committed the patch to git.

kopryszard’s picture

I will test it and I will let you know in a few hours

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 980b63e on 7.x-4.x, 7.x-5.x authored by eloiv, committed by sivaji:
    Issue #285570 by eloiv: Added Only show questions in the same language...

  • Commit 980b63e on 7.x-4.x, 7.x-5.x, quiz-pages authored by eloiv, committed by sivaji:
    Issue #285570 by eloiv: Added Only show questions in the same language...

  • Commit 980b63e on 7.x-4.x, 7.x-5.x, quiz-pages, 2269219 authored by eloiv, committed by sivaji:
    Issue #285570 by eloiv: Added Only show questions in the same language...

  • Commit 980b63e on 7.x-4.x, 7.x-5.x, 2269219 authored by eloiv, committed by sivaji:
    Issue #285570 by eloiv: Added Only show questions in the same language...