ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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='Modules/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.

Referenced by makeHtmlDocument().

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  }
+ Here is the caller graph for this function:

◆ generateHTML()

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

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

References preprocessHTML().

141  {
142  file_put_contents($filename, $this->preprocessHTML($content));
143  return true;
144  }
$filename
Definition: buildRTE.php:78
+ Here is the call graph for this function:

◆ getCssContent()

ilTestHTMLGenerator::getCssContent ( )
private

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

References getTemplatePath().

Referenced by preprocessHTML().

165  : string
166  {
167  $css_content = file_get_contents($this->getTemplatePath('delos.css', ''));
168  $css_content .= ' html, body { overflow: auto; } body { padding: 1rem; }';
169 
170  return $css_content;
171  }
getTemplatePath($a_filename, $module_path='Modules/Test/')
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTemplatePath()

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

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

References ilStyleDefinition\getCurrentSkin().

Referenced by getCssContent().

151  : string
152  {
153  $fname = '';
154  if (ilStyleDefinition::getCurrentSkin() != "default") {
155  $fname = "./Customizing/global/skin/" .
156  ilStyleDefinition::getCurrentSkin() . "/" . $module_path . basename($a_filename);
157  }
158 
159  if ($fname == "" || !file_exists($fname)) {
160  $fname = "./" . $module_path . "templates/default/" . basename($a_filename);
161  }
162  return $fname;
163  }
static getCurrentSkin()
get the current skin use always this function instead of getting the account&#39;s skin the current skin ...
+ 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.

References Vendor\Package\$e, buildHtmlDocument(), ilFileUtils\ilTempnam(), and ilWACSignedPath\signFile().

Referenced by preprocessHTML().

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)
+ 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 146 of file class.ilTestHTMLGenerator.php.

References getCssContent(), and makeHtmlDocument().

Referenced by generateHTML().

146  : string
147  {
148  return $this->makeHtmlDocument($html, '<style>' . $this->getCssContent() . '</style>');
149  }
makeHtmlDocument($content_html, $style_html)
+ 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: