support for multiple types of exercises

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

@ -22,72 +22,94 @@ SDV($HandleActions['Exercises'], 'Exercises');
SDV($HandleAuth['Exercises'],'read'); SDV($HandleAuth['Exercises'],'read');
function Exercises($pagename, $auth){ function Exercises($pagename, $auth){
$type = $_GET["type"];
$exercisetype="pagelink"; $availableexercisetypes = array("pagelink", "expressioninpage");
list($group,$page) = explode(".",$pagename);
// the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ...
if ($group == "AllPages"){
// equivalent to getting ALL pages
$pages = ListPages();
} else {
$pages = ListPages("/$group\./e");
} switch ($type){
case "pagelink":
list($group,$page) = explode(".",$pagename);
// the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ...
if ($group == "AllPages"){
// equivalent to getting ALL pages
$pages = ListPages();
} else {
$pages = ListPages("/$group\./e");
//randomly pick a page in the possible pages }
$sourcepage = $pages[rand(0,count($pages))];
// -1?
$content = ReadPage($sourcepage,READPAGE_CURRENT); //randomly pick a page in the possible pages
//$text = $content["text"]; $sourcepage = $pages[rand(0,count($pages)-1)];
// to use later on for expression exercises
$links = $content["targets"];
$links_array = explode(",",$links);
//$answers = array(); $content = ReadPage($sourcepage,READPAGE_CURRENT);
//consider pilling up potential in $answers[] //$text = $content["text"];
// to use later on for expression exercises
$links = $content["targets"];
$links_array = explode(",",$links);
//randomly pick a page amongst the linked pages //$answers = array();
$pageA = $links_array[rand(0,count($links_array)-1)]; //consider pilling up potential in $answers[]
unset($pages[array_search($pageA,$links_array)]); //randomly pick a page amongst the linked pages
unset($pages[array_search($pageA,$pages)]); $pageA = $links_array[rand(0,count($links_array)-1)];
//randomly pick 2 others pages which are not amongst the list of linked page
$pageB = $pages[rand(0,count($pages)-1)];
unset($pages[array_search($pageB,$pages)]);
$pageC = $pages[rand(0,count($pages)-1)];
unset($pages[array_search($pageC,$pages)]);
//display unset($pages[array_search($pageA,$links_array)]);
$result .="Is page [[$sourcepage]] linked to "; unset($pages[array_search($pageA,$pages)]);
$counter = (int) $_GET["counter"]; //randomly pick 2 others pages which are not amongst the list of linked page
$pageB = $pages[rand(0,count($pages)-1)];
unset($pages[array_search($pageB,$pages)]);
$pageC = $pages[rand(0,count($pages)-1)];
unset($pages[array_search($pageC,$pages)]);
$counterparam = ""; //display
if ( $counter > 0) { $result .="Is page [[$sourcepage]] linked to ";
$counterparam = "counter=$counter&"; $counter = (int) $_GET["counter"];
}
$answers = array ($pageA,$pageB,$pageC); $counterparam = "";
shuffle($answers); if ( $counter > 0) {
for ($i=0;$i<count($answers);$i++) { $counterparam = "counter=$counter&";
if ($answers[$i] != "") {
if ( $i == count($answers) -1 )
$result .= " or ";
//display the groupname everytime only if using AllPages
if ($group != "AllPages") {
list($currentgroup,$currentpage) = explode(".",$answers[$i]);
$result .="[[$pagename?action=ExercisesCheck&".$counterparam
."type=$exercisetype&source=$sourcepage&answer=".$answers[$i]."|".$currentpage."]], ";
} else {
$result .="[[$pagename?action=ExercisesCheck&".$counterparam
."type=$exercisetype&source=$sourcepage&answer=".$answers[$i]."|".$answers[$i]."]], ";
} }
}
$answers = array ($pageA,$pageB,$pageC);
shuffle($answers);
for ($i=0;$i<count($answers);$i++) {
if ($answers[$i] != "") {
if ( $i == count($answers) -1 )
$result .= " or ";
//display the groupname everytime only if using AllPages
if ($group != "AllPages") {
list($currentgroup,$currentpage) = explode(".",$answers[$i]);
$result .="[[$pagename?action=ExercisesCheck&".$counterparam
."type=$type&source=$sourcepage&answer=".$answers[$i]."|".$currentpage."]], ";
} else {
$result .="[[$pagename?action=ExercisesCheck&".$counterparam
."type=$type&source=$sourcepage&answer=".$answers[$i]."|".$answers[$i]."]], ";
}
}
}
$result .="? ";
$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 .="? ";
$result .="\n\nClick on the answer.";
$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