-
Improvement
-
Resolution: Duplicate
-
Minor
-
None
-
1.6
-
None
-
All
-
MOODLE_16_STABLE
not really a bug as such but quizzes are dependent on Javascript support.
I've started to tackle this. Included here is code to make the latest cvs build as of
13:50 23rd March 2005 GMT a bit less dependent.
Problem - On multipage quizes the form requires javascripted links to navigate between questions.
Solution - replace the links with an accessible select box.
/****** function in /mod/quiz/locallib.php ***********/
function quiz_print_navigation_panel($questions, $questionsperpage, $navigation) {
global $QUIZ_QTYPES;
$numberinglayout = array();
$nextqnumber = 1;
foreach ($questions as $question) {
if ($qnumberinc = $QUIZ_QTYPES[$question->qtype]
->actual_number_of_questions($question))
{ $numberinglayout[] = $nextqnumber; $nextqnumber += $qnumberinc; }}
if ($nextqnumber - $qnumberinc <= $questionsperpage)
{ /// The total number of questions does not exceed the maximum /// number of allowed questions per page so... return 0; }/// else - Navigation menu will be printed!
///////////////////////////////////////////////
/// Determine the layout of the navigation menu
///////////////////////////////////////////////
if (1 == $questionsperpage)
{ /// The simple case: $pagelinkagelayout = $pagenavigationlayout = $numberinglayout; }else {
/// More complicated:
$pagenavigationlayout = array();
$pagelinkagelayout = array($currentpagestart = 1);
foreach ($numberinglayout as $questionnumber) {
if ($questionnumber - $currentpagestart >= $questionsperpage) {
$pagenavigationlayout[] = $currentpagestart
.'-'. ($questionnumber - 1);
if ($currentpagestart < $navigation
&& $navigation < $questionnumber)
{ // $navigation is out of sync so adjust for robustness $navigation = $currentpagestart; }$pagelinkagelayout[] = $currentpagestart = $questionnumber;
}
}
$pagenavigationlayout[] = $currentpagestart .'-'. ($nextqnumber - 1);
if ($currentpagestart < $navigation)
{ // $firstquestion is out of sync so adjust it for robustness... $navigation = $currentpagestart; }}
foreach ($pagelinkagelayout as $key => $link) {
if ($link < $navigation)
{ $previouspagelink = $link; }else if ($link == $navigation)
{ $currentnavigationtitle = $pagenavigationlayout[$key]; }else {
$endpagelink = $link;
if (false == isset($nextpagelink))
{ $nextpagelink = $link; }}
}
$nav_str = '<label>After saving';
$nav_str .= '<select name=navigation title=select a destination after you submit this form.>';
$nav_str .= '<option value=0>Exit Quiz</option>';
if (isset($previouspagelink))
{ $nav_str .= '<option value='.$previouspagelink.' '.(!isset($nextpagelink) ? 'selected=selected':'').'>'.get_string('previous').'</option>'; }if (isset($nextpagelink))
{ $nav_str .= '<option value='.$nextpagelink.' '.'selected=selected>'.get_string('next').'</option>'; }foreach ($pagelinkagelayout as $key => $link)
{ $nav_str .= '<option value='.$link.'>Question '.$pagenavigationlayout[$key].'</option>'; }$nav_str .= '</select></label>';
echo $nav_str;
return $navigation;
}
/****************/
Issue - in the javascripted version it was perfectly ok to have the links display across the top and bottom of the question. However, as this is a form element we can only logically display one of them (otherwise the value of the upper one won't matter because it'll be overwritten by the bottom one on submission). The second call to quiz_print_navigation_panel in quiz_print_quiz_questions (locallib.php ~1055) should be removed.
The quiz_print_navigation_panel has to be called before the question is printed and thus the select box ends up being displayed above the question when really it ought to be displayed next to the submit button.
To this end I've made a second version of quiz_print_navigation_panel which returns a 2 index array consisting of [0] => $navigation and [1]=>$nav_select_box and DOES NOT print out the select box. This allows me to hold the nav element until later where I echo it next to the submit box.
In this version the final two lines of the new version of quiz_print_navigation_panel should be replaced with
//don't echo out the $nav_str
return array($navigation, $nav_str
This in turn effects quiz_print_quiz_questions.....
// first call ~1004
list($navigation, $nav_widget) = quiz_print_navigation_panel($questions,
$quiz->questionsperpage, $navigation);
//we now have the navigation select box stored in $nav_widget
......
/*
~1046 we remove the second call to print the navigation as before and replace it as follows
*/
if($navigation)
{ echo $nav_widget; //print list of nav options. }else
{ echo <input type=\hidden\ name=\navigation\ value='0' />\n; //save == exit }This code removes the javascript dependence for pagination of a quiz. Tested with 1 q per page, 2 q per page and unlimited q per page.
Obviously, the quiz module is still highly dependent on JS but I'll continue to work to remove this if it's approved.
My apologies if this doesn't format properly. It's my first post here and if it's not clear what I mean I'll post the full files.
Gav
- duplicates
-
MDL-8182 make javascript optional in quiz UI
-
- Closed
-