From cc68c44175c38739ece1fcdf93baf33999676790 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Fri, 12 Aug 2011 17:24:03 +0200 Subject: [PATCH] added the first version of the PIM exercising recipe --- pmwiki_recipes/exercises.php | 134 +++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 pmwiki_recipes/exercises.php diff --git a/pmwiki_recipes/exercises.php b/pmwiki_recipes/exercises.php new file mode 100644 index 0000000..def8d78 --- /dev/null +++ b/pmwiki_recipes/exercises.php @@ -0,0 +1,134 @@ +B>C? A>C>B? B>C>A? B>A>C? C>B>A? C>A>B? +# e.g. size, frequency update, last edition, ... +# which of those page corresponds the updates visualization V, A, B or C? +# keyword or URL in pages +# page linked to other page +# to display, especially the current and past score in +# http://fabien.benetou.fr/Content/MentalExercises +# display global or related to the current page, or group (based on parameters) +# cf also early August discussion on ##pim +# +# update http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM when it is working +# also push to the code repository + + +$RecipeInfo['Exercises']['Version'] = '2011-12-08'; + +$HandleActions['Exercises'] = 'Exercises'; # if url contains action=myaction call HandleMyAction timely +$HandleAuth['Exercises'] = 'read'; # authorization level $auth for HandleMyAction + +function Exercises($pagename, $auth){ + + $exercisetype="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); + //$text = $content["text"]; + // to use later on for expression exercises + $links = $content["targets"]; + $links_array = explode(",",$links); + + //$answers = array(); + //consider pilling up potential in $answers[] + + //randomly pick a page amongst the linked pages + $pageA = $links_array[rand(0,count($links_array)-1)]; + + unset($pages[array_search($pageA,$links_array)]); + unset($pages[array_search($pageA,$pages)]); + //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 + $result .="Is page [[$sourcepage]] linked to "; + $counter = (int) $_GET["counter"]; + + $counterparam = ""; + if ( $counter > 0) { + $counterparam = "counter=$counter&"; + } + + $answers = array ($pageA,$pageB,$pageC); + shuffle($answers); + for ($i=0;$i 0) { + $counter++; + $result .="See if you can [[$pagename?action=Exercises&counter=$counter|solve yet another one]]. "; + } else { + $result .="See if you can [[$pagename?action=Exercises&counter=1|solve yet another one]]. "; + } + } else { + $result .="No, [[$sourcepage]] is not linked to [[$answer]] "; + $result .="but $links are. "; + $result .="Try to redeem yourself by [[$pagename?action=Exercises|trying another time]]. "; + } + $renderedresult = MarkupToHTML($pagename, $result); + print $renderedresult; + + //$text = RetrieveAuthSection($pagename,$auth); + //$content = MarkupToHTML($pagename, $text); + //print $content; +} + +?>