partly managing difficulty

master
Fabien Benetou 14 years ago
parent 03c37db619
commit deee57aa01
  1. 36
      pmwiki_recipes/exercises.php

@ -23,14 +23,16 @@ SDV($HandleAuth['Exercises'],'read');
function Exercises($pagename, $auth){ function Exercises($pagename, $auth){
$type = $_GET["type"]; $type = $_GET["type"];
$counter = (int) $_GET["counter"];
$difficulty = (int) $_GET["difficulty"];
list($group,$page) = explode(".",$pagename);
$availableexercisetypes = array("pagelink", "expressioninpage"); $availableexercisetypes = array("pagelink", "expressioninpage", "pagehasexpression");
if ($type=="random") if ($type=="random")
$type= $availableexercisetypes[rand(0,count($availableexercisetypes)-1)]; $type= $availableexercisetypes[rand(0,count($availableexercisetypes)-1)];
switch ($type){ switch ($type){
case "pagelink": case "pagelink":
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"){
// equivalent to getting ALL pages // equivalent to getting ALL pages
@ -53,27 +55,31 @@ function Exercises($pagename, $auth){
//consider pilling up potential in $answers[] //consider pilling up potential in $answers[]
//randomly pick a page amongst the linked pages //randomly pick a page amongst the linked pages
$pageA = $links_array[rand(0,count($links_array)-1)]; $answers[] = $links_array[rand(0,count($links_array)-1)];
unset($pages[array_search($pageA,$links_array)]); unset($pages[array_search($answers[0],$links_array)]);
unset($pages[array_search($pageA,$pages)]); unset($pages[array_search($answers[0],$pages)]);
//randomly pick 2 others pages which are not amongst the list of linked page
$pageB = $pages[rand(0,count($pages)-1)]; //randomly pick n-1 others pages which may not be amongst the list of linked page
unset($pages[array_search($pageB,$pages)]); // n should be based on $difficulty, e.g. n=2+$difficulty or n=2^$difficulty
$pageC = $pages[rand(0,count($pages)-1)]; $n=3;
unset($pages[array_search($pageC,$pages)]); for ($i=1;$i<$n;$i++) {
$answers[] = $pages[rand(0,count($pages)-1)];
unset($pages[array_search($answers[$i],$pages)]);
}
//display //display
$result .="Is page [[$sourcepage]] linked to "; $result .="Is page [[$sourcepage]] linked to ";
$counter = (int) $_GET["counter"];
$counterparam = ""; $counterparam = "";
if ( $counter > 0) { if ( $counter > 0) {
$counterparam = "counter=$counter&"; $counterparam = "counter=$counter&";
} }
$answers = array ($pageA,$pageB,$pageC); // there should now be at least 1 needle in the haystack, the first one
// note that there might be more but this is not a problem as long as the question is stated clearly.
shuffle($answers); shuffle($answers);
for ($i=0;$i<count($answers);$i++) { for ($i=0;$i<count($answers);$i++) {
if ($answers[$i] != "") { if ($answers[$i] != "") {
if ( $i == count($answers) -1 ) if ( $i == count($answers) -1 )
@ -92,9 +98,13 @@ function Exercises($pagename, $auth){
$result .="? "; $result .="? ";
$result .="\n\nClick on the answer."; $result .="\n\nClick on the answer.";
break; break;
case "pagehasexpression":
// explode content by line "%0a" or word " "
$result .= "Does the page 'PAGE' has expression 'EXPRESSIONA', 'EXPRESSIONB' or 'EXPRESSIONC?";
break;
case "expressioninpage": case "expressioninpage":
// explode content by line "%0a" or word " " // explode content by line "%0a" or word " "
$result .= "Does the expression 'EXPRESSION' come from PAGEA PAGEB or PAGEC?"; $result .= "Does the expression 'EXPRESSION' come from PAGEA, PAGEB or PAGEC?";
break; break;
default: default:
$result .= "Exercise type unknown."; $result .= "Exercise type unknown.";

Loading…
Cancel
Save