[Aimmath-commit] moodle/mod/aim_quiz lib.php,1.7,1.8
Brought to you by:
gustav_delius,
npstrick
|
From: <gus...@us...> - 2003-09-06 08:24:31
|
Update of /cvsroot/aimmath/moodle/mod/aim_quiz
In directory sc8-pr-cvs1:/tmp/cvs-serv2228/mod/aim_quiz
Modified Files:
lib.php
Log Message:
some more work done on the creation of pdf from quiz page.
Index: lib.php
===================================================================
RCS file: /cvsroot/aimmath/moodle/mod/aim_quiz/lib.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** lib.php 2 Sep 2003 18:47:54 -0000 1.7
--- lib.php 6 Sep 2003 08:24:25 -0000 1.8
***************
*** 372,379 ****
// find the row which gives the totals
if (preg_match("/<td(?:\s[^<>]*?|)>Total<\/td>(?:.(?!<td\s|<td>))*.?<td(?:\s[^<>]*?|)>((?:.(?!<\/td>))*?.?)<\/td>(?:.(?!<td\s|<td>))*.?<td(?:\s[^<>]*?|)>((?:.(?!<\/td>))*?.?)<\/td>/si", $data, $matches)) {
! if (empty($CFG->aim_quiz_grade_multiplier))
! $CFG->aim_quiz_grade_multiplier = 1.0;
! $max_grade = (int) (((float) html_entity_decode($matches[1])) * ((float) $CFG->aim_quiz_grade_multiplier));
! $grade = (int) (((float) html_entity_decode($matches[2])) * ((float) $CFG->aim_quiz_grade_multiplier));
}
}
--- 372,379 ----
// find the row which gives the totals
if (preg_match("/<td(?:\s[^<>]*?|)>Total<\/td>(?:.(?!<td\s|<td>))*.?<td(?:\s[^<>]*?|)>((?:.(?!<\/td>))*?.?)<\/td>(?:.(?!<td\s|<td>))*.?<td(?:\s[^<>]*?|)>((?:.(?!<\/td>))*?.?)<\/td>/si", $data, $matches)) {
! if (empty($CFG->aim_quiz_grade_multiplier))
! $CFG->aim_quiz_grade_multiplier = 1.0;
! $max_grade = (int) (((float) html_entity_decode($matches[1])) * ((float) $CFG->aim_quiz_grade_multiplier));
! $grade = (int) (((float) html_entity_decode($matches[2])) * ((float) $CFG->aim_quiz_grade_multiplier));
}
}
***************
*** 432,440 ****
// remove styles (as we haven't loaded the AiM stylesheet)
! $out = preg_replace("/<div(?:\s[^<>]*?|)>/i", "", $out);
! $out = preg_replace("/<\/div>/i", "", $out);
! $out = preg_replace("/<span(?:\s[^<>]*?|)>/i", "", $out);
! $out = preg_replace("/<\/span>/i", "", $out);
! $out = preg_replace("/(?<=<)(\w*(?:\s[^<>]*?|))\sclass=(?(?=\")\"[^\"<>]*?\"(?=\W)|\S*?(?=>))/i", "\\1", $out);
////// HACK - sort out non-xml complient AIM output
--- 432,440 ----
// remove styles (as we haven't loaded the AiM stylesheet)
! // $out = preg_replace("/<div(?:\s[^<>]*?|)>/i", "", $out);
! // $out = preg_replace("/<\/div>/i", "", $out);
! // $out = preg_replace("/<span(?:\s[^<>]*?|)>/i", "", $out);
! // $out = preg_replace("/<\/span>/i", "", $out);
! // $out = preg_replace("/(?<=<)(\w*(?:\s[^<>]*?|))\sclass=(?(?=\")\"[^\"<>]*?\"(?=\W)|\S*?(?=>))/i", "\\1", $out);
////// HACK - sort out non-xml complient AIM output
***************
*** 518,545 ****
function aim_quiz_pdf($aim_quiz, $course, $data) {
/// Function which extracts the latex from the AiM quiz page and converts it to pdf
! /// This still has to be written, I am only experimenting at the moment.
$latex = "\\documentclass[12pt]{article}\n
\\begin{document}\n
\\begin{center}
! \\bf ".$course->fullname.": ".$aim_quiz->name."
! \\end{center}";
! $questions = explode("<div class=\"question\"",$data);
! array_shift($questions);
! foreach ($questions as $key => $question) {
! $latex .= "\n\n{\\bf Question:}\n";
! $chunks = explode("</latex>",$question);
! array_pop($chunks);
! foreach ($chunks as $chunk) {
! preg_match("/(?<=<latex>)[\s\S]*\$/","$chunk",$piece);
! $latex .= $piece[0];
! }
}
$latex .= "\n\n\\end{document}";
$fp=fopen("temp.tex","w");
fwrite($fp,$latex);
fclose($fp);
! $latexoutput = system("pdflatex -interaction=batchmode temp.tex");
return true;
}
--- 518,587 ----
function aim_quiz_pdf($aim_quiz, $course, $data) {
/// Function which extracts the latex from the AiM quiz page and converts it to pdf
! /// This is not yet complete
! /// The strategy is:
! /// 1) use regexps to convert anything on the quiz page that
! /// we want to keep into latex,
! /// 2) collect all the latex together
! /// 3) pass it through pdflatex
$latex = "\\documentclass[12pt]{article}\n
\\begin{document}\n
\\begin{center}
! {\\bf " . $course->fullname . ": " . $aim_quiz->name . "}
! \\end{center}";
! // remove everything before the first question
! $data = preg_replace("/^[\s\S]*?(?=id=\"question)/",
! "",$data);
!
! // remove all answers and solutions
! $data = preg_replace("/class=\"lastanswer\"[\s\S]*?((?=id=\"question)|$)/",
! "",$data);
!
! // remove questionheaders including descriptions
! $data = preg_replace("/class=\"questionheader\"[\s\S]*?class=\"questionbody/",
! "",$data);
!
! // Questions
! $data = preg_replace("/id=\"question(\d+)\"/i",
! "<latex>\n\n\vspace{5mm}\\noindent{\\bf Question \$1:}\n\n</latex>",$data);
!
! // Parts
! $data = preg_replace("/id=\"question(\d+).(\d+)\"/i",
! "<latex>\n\n\vspace{2mm}{\\bf Part \$2}\n\n</latex>",$data);
!
! // replace radio buttons by circles
! $data = preg_replace("/(type=\"radio\"[^\/]*value=\")[A-Z]\"/",
! "<latex>\n\n $\circ$ </latex>",$data);
!
! // replace checkboxes by diamonds
! $data = preg_replace("/(type=\"checkbox\"[^\/]*value=\")[A-Z]\"/",
! "<latex>\n\n $\diamond$ </latex>",$data);
! // replace input box by ....
! // preg_match_all("/<latex>([\s\S]*)?<\/latex>/", $data, $matches);
! // $latex .= implode(" ", $matches[0]);
!
! // extract anything inside <latex> ..</latex> and append it to $latex
! // this is not done elegantly, but who cares.
! $chunks = explode("</latex>",$data);
! array_pop($chunks);
! foreach ($chunks as $chunk) {
! preg_match("/(?<=<latex>)[\s\S]*$/","$chunk",$piece);
! $latex .= $piece[0];
}
+
$latex .= "\n\n\\end{document}";
$fp=fopen("temp.tex","w");
fwrite($fp,$latex);
fclose($fp);
!
! // The next step is to call pdflatex to convert the latex to pdf
! // Unfortunately I have the problem that PHP hangs after executing
! // any command using exec or similar.
! // Does anyone know a solution? Is it a problem with the particular
! // version of PHP or apache that I am using?
!
! // $latexoutput = system("pdflatex -interaction=batchmode temp.tex");
! // exec(cmd);
return true;
}
|