keeping scores and displaying them

master
Fabien Benetou 14 years ago
parent 6c09afa602
commit 507900f991
  1. 48
      pmwiki_recipes/exercises.php

@ -29,11 +29,6 @@ error_reporting(0);
# e.g. increasing the number of possibilities (at least 1 out of 5 pages instead of at least 1 out of 3)
# consider doing a trip rather than random jumps
# i.e. if pick randomly from the linked pages or from the group or from the the whole wiki of the previous page
# markup to display results
# MentalExercises (:ExercisesResults:)
# default to urrently logged-in user
# sparklines for visuals
# also implies to record score per session with date
$RecipeInfo['Exercises']['Version'] = '2015-16-08';
@ -282,10 +277,19 @@ SDV($HandleActions['ExercisesCheck'], 'ExercisesCheck');
SDV($HandleAuth['ExercisesCheck'],'read');
function ExercisesCheck($pagename, $auth){
global $ScriptUrl, $FarmD, $Author;
$activityfile = $FarmD."/wiki.d/.exercisesscores";
$type = $_GET["type"];
$sourcepage = $_GET["source"];
$answer = $_GET["answer"];
$counter = (int) $_GET["counter"];
$counter = 0;
if ( isset($_GET["counter"]) )
$counter = (int) $_GET["counter"];
$score_lower_threshold = 3;
// this could also be a value relative to the top score if there is one
list($group,$page) = explode(".",$pagename);
if ($group == "AllPages"){
@ -373,6 +377,38 @@ function ExercisesCheck($pagename, $auth){
$result .= "\n\n%center%[-Generated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]].-]%%";
$renderedresult = MarkupToHTML($pagename, $result);
print $renderedresult;
if ( ( isset($Author) ) && ( $counter > $score_lower_threshold ) ) {
$score = "$counter,$Author,$type,".time()."\n";
$write_result = file_put_contents($activityfile,$score, FILE_APPEND | LOCK_EX);
if ($write_result < 1)
print "There seems to be an error updating the score file, please check that $activityfile has write permission for httpd.";
}
}
Markup("exercisesresults", "directives", "/\(:exercisesresults:\)/", ExercisesResults());
# markup to display results
# default to all participant, not just the currently logged in user
# hall of fame could be useful in collaborative learning wikis
# consider first sparklines for visuals
function ExercisesResults(){
global $ScriptUrl, $FarmD, $Author;
$activityfile = $FarmD."/wiki.d/.exercisesscores";
if (file_exists($activityfile)) {
$raw_scores = file_get_contents($activityfile);
$allscores = explode("\n",$raw_scores);
foreach ($allscores as $score ) {
list($counter,$author,$type,$time) = explode(",",$score);
if ($Author == $author) $author = "<b>$author</b>";
// $Author somehow never gets initialized
if ($counter != "")
$past_scores .= "<li> $counter done by $author doing $type at $time</li>\n";
}
} else {
$past_scores = "Currently no scores have been recorded. Consider starting an exercise first";
// print "Go above the minimum threshold of good answers while being logged in.";
// removed for now since the threshold is at 1
}
return $past_scores;
}
?>

Loading…
Cancel
Save