ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilTestHTMLGenerator Class Reference

Class that handles PDF generation for test and assessment. More...

+ Collaboration diagram for ilTestHTMLGenerator:

Public Member Functions

 generateHTML (string $content, string $filename)
 

Private Member Functions

 buildHtmlDocument ($content_html, $style_html)
 
 makeHtmlDocument ($content_html, $style_html)
 
 preprocessHTML (string $html)
 
 getTemplatePath ($a_filename, $module_path='components/ILIAS/Test/')
 
 getCssContent ()
 

Detailed Description

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 29 of file class.ilTestHTMLGenerator.php.

Member Function Documentation

◆ buildHtmlDocument()

ilTestHTMLGenerator::buildHtmlDocument (   $content_html,
  $style_html 
)
private

Definition at line 31 of file class.ilTestHTMLGenerator.php.

31 : string
32 {
33 return "
34 <html>
35 <head>
36 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
37 $style_html
38 </head>
39 <body>$content_html</body>
40 </html>
41 ";
42 }

Referenced by makeHtmlDocument().

+ Here is the caller graph for this function:

◆ generateHTML()

ilTestHTMLGenerator::generateHTML ( string  $content,
string  $filename 
)

Definition at line 141 of file class.ilTestHTMLGenerator.php.

142 {
143 file_put_contents($filename, $this->preprocessHTML($content));
144 return true;
145 }
$filename
Definition: buildRTE.php:78

References $filename, and preprocessHTML().

+ Here is the call graph for this function:

◆ getCssContent()

ilTestHTMLGenerator::getCssContent ( )
private

Definition at line 166 of file class.ilTestHTMLGenerator.php.

166 : string
167 {
168 $css_content = file_get_contents($this->getTemplatePath('delos.css', ''));
169 $css_content .= ' html, body { overflow: auto; } body { padding: 1rem; }';
170
171 return $css_content;
172 }
getTemplatePath($a_filename, $module_path='components/ILIAS/Test/')

References getTemplatePath().

Referenced by preprocessHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTemplatePath()

ilTestHTMLGenerator::getTemplatePath (   $a_filename,
  $module_path = 'components/ILIAS/Test/' 
)
private

Definition at line 152 of file class.ilTestHTMLGenerator.php.

152 : string
153 {
154 $fname = '';
155 if (ilStyleDefinition::getCurrentSkin() !== 'default') {
156 $fname = './Customizing/skin/' .
157 ilStyleDefinition::getCurrentSkin() . '/' . $module_path . basename($a_filename);
158 }
159
160 if ($fname == '' || !file_exists($fname)) {
161 $fname = './' . $module_path . 'assets/css/' . basename($a_filename);
162 }
163 return $fname;
164 }
static getCurrentSkin()
get the current skin use always this function instead of getting the account's skin the current skin ...

References ilStyleDefinition\getCurrentSkin().

Referenced by getCssContent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeHtmlDocument()

ilTestHTMLGenerator::makeHtmlDocument (   $content_html,
  $style_html 
)
private
Parameters
$content_html
$style_html
Returns
string

Definition at line 49 of file class.ilTestHTMLGenerator.php.

49 : string
50 {
51 if (!is_string($content_html) || !strlen(trim($content_html))) {
52 return $content_html;
53 }
54
55 $html = $this->buildHtmlDocument($content_html, $style_html);
56
57 $dom = new DOMDocument("1.0", "utf-8");
58 if (!@$dom->loadHTML($html)) {
59 return $html;
60 }
61
62 $invalid_elements = [];
63
64 $script_elements = $dom->getElementsByTagName('script');
65 foreach ($script_elements as $elm) {
66 $invalid_elements[] = $elm;
67 }
68
69 foreach ($invalid_elements as $elm) {
70 $elm->parentNode->removeChild($elm);
71 }
72
73 // remove noprint elems as tcpdf will make empty pdf when hidden by css rules
74 $domX = new DomXPath($dom);
75 foreach ($domX->query("//*[contains(@class, 'noprint')]") as $node) {
76 $node->parentNode->removeChild($node);
77 }
78
79 $dom->encoding = 'UTF-8';
80
81 $content_to_replace = $this->generateImageDataSrces($dom);
82
83 $cleaned_html = $dom->saveHTML();
84
85 if (!$cleaned_html) {
86 return $html;
87 }
88
89 if ($content_to_replace === null) {
90 return $cleaned_html;
91 }
92
93 return str_replace(array_keys($content_to_replace), array_values($content_to_replace), $cleaned_html);
94 }
buildHtmlDocument($content_html, $style_html)

References buildHtmlDocument().

Referenced by preprocessHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ preprocessHTML()

ilTestHTMLGenerator::preprocessHTML ( string  $html)
private

Definition at line 147 of file class.ilTestHTMLGenerator.php.

147 : string
148 {
149 return $this->makeHtmlDocument($html, '<style>' . $this->getCssContent() . '</style>');
150 }
makeHtmlDocument($content_html, $style_html)

References getCssContent(), and makeHtmlDocument().

Referenced by generateHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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