support for multiple types of exercises

master
Fabien Benetou 14 years ago
parent 5821b36d0b
commit a617218f07
  1. 36
      pmwiki_recipes/exercises.php

@ -22,8 +22,12 @@ SDV($HandleActions['Exercises'], 'Exercises');
SDV($HandleAuth['Exercises'],'read'); SDV($HandleAuth['Exercises'],'read');
function Exercises($pagename, $auth){ function Exercises($pagename, $auth){
$type = $_GET["type"];
$availableexercisetypes = array("pagelink", "expressioninpage");
$exercisetype="pagelink"; switch ($type){
case "pagelink":
list($group,$page) = explode(".",$pagename); list($group,$page) = explode(".",$pagename);
// the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ... // the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ...
if ($group == "AllPages"){ if ($group == "AllPages"){
@ -35,8 +39,7 @@ function Exercises($pagename, $auth){
} }
//randomly pick a page in the possible pages //randomly pick a page in the possible pages
$sourcepage = $pages[rand(0,count($pages))]; $sourcepage = $pages[rand(0,count($pages)-1)];
// -1?
$content = ReadPage($sourcepage,READPAGE_CURRENT); $content = ReadPage($sourcepage,READPAGE_CURRENT);
//$text = $content["text"]; //$text = $content["text"];
@ -77,17 +80,36 @@ function Exercises($pagename, $auth){
if ($group != "AllPages") { if ($group != "AllPages") {
list($currentgroup,$currentpage) = explode(".",$answers[$i]); list($currentgroup,$currentpage) = explode(".",$answers[$i]);
$result .="[[$pagename?action=ExercisesCheck&".$counterparam $result .="[[$pagename?action=ExercisesCheck&".$counterparam
."type=$exercisetype&source=$sourcepage&answer=".$answers[$i]."|".$currentpage."]], "; ."type=$type&source=$sourcepage&answer=".$answers[$i]."|".$currentpage."]], ";
} else { } else {
$result .="[[$pagename?action=ExercisesCheck&".$counterparam $result .="[[$pagename?action=ExercisesCheck&".$counterparam
."type=$exercisetype&source=$sourcepage&answer=".$answers[$i]."|".$answers[$i]."]], "; ."type=$type&source=$sourcepage&answer=".$answers[$i]."|".$answers[$i]."]], ";
} }
} }
} }
$result .="? "; $result .="? ";
$result .="\n\nClick on the answer."; $result .="\n\nClick on the answer.";
break;
case "expressioninpage":
// explode content by line "%0a" or word " "
$result .= "Does the expression 'EXPRESSION' come from PAGEA PAGEB or PAGEC?";
break;
default:
$result .= "Exercise type unknown.";
}
$result .= "\n\nGenerated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]]"; $result .= "\n\nGenerated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]]. ";
unset($availableexercisetypes[array_search($type,$availableexercisetypes)]);
if (count($availableexercisetypes) > 0) {
$result .= " Try other types of exercises:";
foreach ($availableexercisetypes as $e) {
$result .= " [[$pagename?action=Exercises&type=$e|$e]],";
}
$result .= ".";
}
if ( $counter > 0) {
$result .= " (note that it resets the counter)";
}
$renderedresult = MarkupToHTML($pagename, $result); $renderedresult = MarkupToHTML($pagename, $result);
print $renderedresult; print $renderedresult;
@ -135,6 +157,8 @@ function ExercisesCheck($pagename, $auth){
$result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises|trying another time]]. "; $result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises|trying another time]]. ";
} }
break; break;
default:
$result .= "Exercise type unknown.";
} }
$result .= "\n\nGenerated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]]"; $result .= "\n\nGenerated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]]";
$renderedresult = MarkupToHTML($pagename, $result); $renderedresult = MarkupToHTML($pagename, $result);

Loading…
Cancel
Save