ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTestPDFGenerator Class Reference

Class ilTestPDFGenerator. More...

+ Collaboration diagram for ilTestPDFGenerator:

Static Public Member Functions

static generatePDF ($pdf_output, $output_mode, $filename=null)
 
static preprocessHTML ($html)
 

Data Fields

const PDF_OUTPUT_DOWNLOAD = 'D'
 
const PDF_OUTPUT_INLINE = 'I'
 
const PDF_OUTPUT_FILE = 'F'
 

Static Protected Member Functions

static getTemplatePath ($a_filename)
 

Static Private Member Functions

static removeScriptElements ($html)
 

Detailed Description

Class ilTestPDFGenerator.

Class that handles PDF generation for test and assessment.

Author
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 13 of file class.ilTestPDFGenerator.php.

Member Function Documentation

◆ generatePDF()

static ilTestPDFGenerator::generatePDF (   $pdf_output,
  $output_mode,
  $filename = null 
)
static

Definition at line 59 of file class.ilTestPDFGenerator.php.

References $filename, and ilPDFGeneration\doJob().

Referenced by ilTestArchiveService\archiveActivesPass(), ilTestPlayerAbstractGUI\archiveParticipantSubmission(), ilObjTestGUI\createUserResults(), ilTestServiceGUI\getQuestionResultForTestUsers(), ilTestEvaluationGUI\outParticipantsPassDetails(), ilTestEvaluationGUI\outParticipantsResultsOverview(), ilTestEvaluationGUI\outUserPassDetails(), ilTestEvaluationGUI\outUserResultsOverview(), ilTestSubmissionReviewGUI\pdfDownload(), ilObjTestGUI\printobject(), ilTestScoring\recalculatePasses(), and ilTestArchiver\updateTestArchive().

60  {
61  $pdf_output = self::preprocessHTML($pdf_output);
62 
63  if (substr($filename, strlen($filename) - 4, 4) != '.pdf')
64  {
65  $filename .= '.pdf';
66  }
67 
68  require_once './Services/PDFGeneration/classes/class.ilPDFGeneration.php';
69 
70  $job = new ilPDFGenerationJob();
71  $job->setAutoPageBreak(true)
72  ->setCreator('ILIAS Test')
73  ->setFilename($filename)
74  ->setMarginLeft('20')
75  ->setMarginRight('20')
76  ->setMarginTop('20')
77  ->setMarginBottom('20')
78  ->setOutputMode($output_mode)
79  ->addPage($pdf_output);
80 
82  }
$filename
Definition: buildRTE.php:89
Class ilPDFGenerationJob.
static doJob(ilPDFGenerationJob $job)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTemplatePath()

static ilTestPDFGenerator::getTemplatePath (   $a_filename)
staticprotected

Definition at line 91 of file class.ilTestPDFGenerator.php.

92  {
93  $module_path = "Modules/Test/";
94 
95  // use ilStyleDefinition instead of account to get the current skin
96  include_once "Services/Style/classes/class.ilStyleDefinition.php";
97  if (ilStyleDefinition::getCurrentSkin() != "default")
98  {
99  $fname = "./Customizing/global/skin/".
100  ilStyleDefinition::getCurrentSkin()."/".$module_path.basename($a_filename);
101  }
102 
103  if($fname == "" || !file_exists($fname))
104  {
105  $fname = "./".$module_path."templates/default/".basename($a_filename);
106  }
107  return $fname;
108  }

◆ preprocessHTML()

static ilTestPDFGenerator::preprocessHTML (   $html)
static

Definition at line 84 of file class.ilTestPDFGenerator.php.

85  {
86  $html = self::removeScriptElements($html);
87  $pdf_css_path = self::getTemplatePath('test_pdf.css');
88  return '<style>' . file_get_contents($pdf_css_path) . '</style>' . $html;
89  }

◆ removeScriptElements()

static ilTestPDFGenerator::removeScriptElements (   $html)
staticprivate
Parameters
$html
Returns
string

Definition at line 23 of file class.ilTestPDFGenerator.php.

24  {
25  if(!is_string($html) || !strlen(trim($html)))
26  {
27  return $html;
28  }
29 
30  $dom = new DOMDocument("1.0", "utf-8");
31  if(!@$dom->loadHTML('<?xml encoding="UTF-8">' . $html))
32  {
33  return $html;
34  }
35 
36  $invalid_elements = array();
37 
38  $script_elements = $dom->getElementsByTagName('script');
39  foreach($script_elements as $elm)
40  {
41  $invalid_elements[] = $elm;
42  }
43 
44  foreach($invalid_elements as $elm)
45  {
46  $elm->parentNode->removeChild($elm);
47  }
48 
49  $dom->encoding = 'UTF-8';
50  $cleaned_html = $dom->saveHTML();
51  if(!$cleaned_html)
52  {
53  return $html;
54  }
55 
56  return $cleaned_html;
57  }

Field Documentation

◆ PDF_OUTPUT_DOWNLOAD

◆ PDF_OUTPUT_FILE

◆ PDF_OUTPUT_INLINE

const ilTestPDFGenerator::PDF_OUTPUT_INLINE = 'I'

Definition at line 16 of file class.ilTestPDFGenerator.php.


The documentation for this class was generated from the following file: