ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilPDFGeneratorUtils Class Reference
+ Collaboration diagram for ilPDFGeneratorUtils:

Static Public Member Functions

static prepareGenerationRequest (string $service, string $purpose)
 Prepare the content processing for a PDF generation request This function should be called as in a request before any content is generated It sets the generation mode for Latex processing according the needs of the PDF renderer. More...
 
static getTestPdfDir ()
 
static removePrintMediaDefinitionsFromStyleFile (string $path)
 
static removeWrongPathFromStyleFiles (string $path)
 
static getPurposeMap ()
 
static getSelectionMap ()
 
static getRenderers ()
 
static updateRendererSelection (string $service, string $purpose, string $renderer)
 
static getRendererConfig (string $service, string $purpose, string $renderer)
 
static getRendererDefaultConfig (string $service, string $purpose, string $renderer)
 
static removeRendererConfig (string $service, string $purpose, string $renderer)
 
static getRendererInstance (string $renderer)
 
static saveRendererPurposeConfig (string $service, string $purpose, string $renderer, array $config)
 
static getRendererMapForPurpose (string $service, string $purpose)
 

Static Protected Member Functions

static isRendererPlugin (string $path)
 

Detailed Description

Deprecated:

Definition at line 24 of file class.ilPDFGeneratorUtils.php.

Member Function Documentation

◆ getPurposeMap()

static ilPDFGeneratorUtils::getPurposeMap ( )
static
Returns
array<string, string[]>

Definition at line 73 of file class.ilPDFGeneratorUtils.php.

References $DIC, and $ilDB.

Referenced by ilObjPDFGenerationGUI\configForm(), and ilObjPDFGenerationGUI\saveSettings().

73  : array
74  {
75  global $DIC;
76  $ilDB = $DIC->database();
77 
78  $purposes = [];
79 
80  $result = $ilDB->query('SELECT service, purpose FROM pdfgen_purposes ORDER BY service, purpose');
81 
82  while ($row = $ilDB->fetchAssoc($result)) {
83  $purposes[$row['service']][] = $row['purpose'];
84  }
85 
86  return $purposes;
87  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getRendererConfig()

static ilPDFGeneratorUtils::getRendererConfig ( string  $service,
string  $purpose,
string  $renderer 
)
static

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

References $DIC, $ilDB, and $query.

Referenced by ilObjPDFGenerationGUI\buildConfigForm(), and ilHtmlToPdfTransformerFactory\deliverPDFFromHTMLString().

142  {
143  global $DIC;
144  $ilDB = $DIC->database();
145 
146  $query = 'SELECT config FROM pdfgen_conf WHERE renderer = ' . $ilDB->quote($renderer, 'text') .
147  ' AND service = ' . $ilDB->quote($service, 'text') . ' AND purpose = ' . $ilDB->quote($purpose, 'text');
148 
149  $result = $ilDB->query($query);
150  if ($ilDB->numRows($result) === 0) {
151  return self::getRendererDefaultConfig($service, $purpose, $renderer);
152  }
153 
154  $row = $ilDB->fetchAssoc($result);
155  return json_decode($row['config'], true, 512, JSON_THROW_ON_ERROR);
156  }
global $DIC
Definition: feed.php:28
$query
$service
Definition: ltiservices.php:43
+ Here is the caller graph for this function:

◆ getRendererDefaultConfig()

static ilPDFGeneratorUtils::getRendererDefaultConfig ( string  $service,
string  $purpose,
string  $renderer 
)
static
Exceptions
Exception

Definition at line 161 of file class.ilPDFGeneratorUtils.php.

162  {
163  $class_instance = self::getRendererInstance($renderer);
164 
165  return $class_instance->getDefaultConfig($service, $purpose);
166  }
$service
Definition: ltiservices.php:43

◆ getRendererInstance()

static ilPDFGeneratorUtils::getRendererInstance ( string  $renderer)
static
Exceptions
Exception
Returns
ilRendererConfig&ilPDFRenderer

Definition at line 183 of file class.ilPDFGeneratorUtils.php.

References $DIC, and $ilDB.

Referenced by ilObjPDFGenerationGUI\buildConfigForm(), ilHtmlToPdfTransformerFactory\deliverPDFFromHTMLString(), and ilObjPDFGenerationGUI\saveConfig().

184  {
185  global $DIC;
186 
187  $ilDB = $DIC->database();
188 
189  $result = $ilDB->query('SELECT path FROM pdfgen_renderer WHERE renderer = ' . $ilDB->quote($renderer, 'text'));
190 
191  if ($ilDB->numRows($result) === 0) {
192  throw new Exception('No such renderer - given: ' . $renderer);
193  }
194  $row = $ilDB->fetchAssoc($result);
195 
196  $classname = 'il' . $renderer . 'Renderer';
197  if (self::isRendererPlugin($row['path'])) {
198  $classname = 'il' . $renderer . 'RendererPlugin';
199  }
200 
201  return new $classname();
202  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getRendererMapForPurpose()

static ilPDFGeneratorUtils::getRendererMapForPurpose ( string  $service,
string  $purpose 
)
static
Parameters
string$service
string$purpose
Returns
array{selected: string, preferred: string}

Definition at line 238 of file class.ilPDFGeneratorUtils.php.

References $DIC, and $ilDB.

Referenced by ilHtmlToPdfTransformerFactory\deliverPDFFromHTMLString().

238  : array
239  {
240  global $DIC;
241  $ilDB = $DIC->database();
242 
243  $result = $ilDB->query(
244  'SELECT preferred, selected FROM pdfgen_map WHERE service = ' . $ilDB->quote($service, 'text') . ' ' .
245  'AND purpose=' . $ilDB->quote($purpose, 'text')
246  );
247 
248  if ($ilDB->numRows($result) === 0) {
249  return ['selected' => 'TCPDF', 'preferred' => 'TCPDF'];
250  }
251 
252  return $ilDB->fetchAssoc($result);
253  }
global $DIC
Definition: feed.php:28
$service
Definition: ltiservices.php:43
+ Here is the caller graph for this function:

◆ getRenderers()

static ilPDFGeneratorUtils::getRenderers ( )
static
Returns
array<string, array<string, string[]>>

Definition at line 111 of file class.ilPDFGeneratorUtils.php.

References $DIC, and $ilDB.

Referenced by ilObjPDFGenerationGUI\buildConfigForm(), ilObjPDFGenerationGUI\configForm(), and ilObjPDFGenerationGUI\saveSettings().

111  : array
112  {
113  global $DIC;
114  $ilDB = $DIC->database();
115 
116  $renderers = [];
117  $result = $ilDB->query('SELECT renderer, service, purpose FROM pdfgen_renderer_avail');
118 
119  while ($row = $ilDB->fetchAssoc($result)) {
120  $renderers[$row['service']][$row['purpose']][] = $row['renderer'];
121  }
122 
123  return $renderers;
124  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getSelectionMap()

static ilPDFGeneratorUtils::getSelectionMap ( )
static
Returns
array<string, array<string, array{selected: string, preferred: string}>>

Definition at line 92 of file class.ilPDFGeneratorUtils.php.

References $DIC, and $ilDB.

Referenced by ilObjPDFGenerationGUI\configForm(), and ilObjPDFGenerationGUI\saveSettings().

92  : array
93  {
94  global $DIC;
95  $ilDB = $DIC->database();
96 
97  $mappings = [];
98  $result = $ilDB->query('SELECT service, purpose, preferred, selected FROM pdfgen_map');
99 
100  while ($row = $ilDB->fetchAssoc($result)) {
101  $mappings[$row['service']][$row['purpose']]['selected'] = $row['selected'];
102  $mappings[$row['service']][$row['purpose']]['preferred'] = $row['preferred'];
103  }
104 
105  return $mappings;
106  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getTestPdfDir()

static ilPDFGeneratorUtils::getTestPdfDir ( )
static

Definition at line 42 of file class.ilPDFGeneratorUtils.php.

References CLIENT_ID.

42  : string
43  {
44  $iliasPDFTestPath = 'data/' . CLIENT_ID . '/pdf_service/';
45  if (!is_dir($iliasPDFTestPath) && !mkdir($iliasPDFTestPath) && !is_dir($iliasPDFTestPath)) {
46  throw new RuntimeException(sprintf('Directory "%s" was not created', $iliasPDFTestPath));
47  }
48 
49  return $iliasPDFTestPath;
50  }
const CLIENT_ID
Definition: constants.php:41

◆ isRendererPlugin()

static ilPDFGeneratorUtils::isRendererPlugin ( string  $path)
staticprotected

Definition at line 204 of file class.ilPDFGeneratorUtils.php.

204  : bool
205  {
206  $needle = 'Plugin.php';
207  $length = strlen($needle);
208  return (substr($path, -$length) === $needle);
209  }
$path
Definition: ltiservices.php:32

◆ prepareGenerationRequest()

static ilPDFGeneratorUtils::prepareGenerationRequest ( string  $service,
string  $purpose 
)
static

Prepare the content processing for a PDF generation request This function should be called as in a request before any content is generated It sets the generation mode for Latex processing according the needs of the PDF renderer.

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

References Vendor\Package\$e.

Referenced by ilTestExportGUI\createTestArchiveExport(), ilParticipantsTestResultsGUI\createUserResults(), ilTestServiceGUI\getQuestionResultForTestUsers(), ilTestEvaluationGUI\outParticipantsPassDetails(), ilTestEvaluationGUI\outParticipantsResultsOverview(), ilTestEvaluationGUI\outUserPassDetails(), ilTestEvaluationGUI\outUserResultsOverview(), ilTestSubmissionReviewGUI\pdfDownload(), ilObjTestGUI\printobject(), ilObjTestGUI\reviewobject(), and ilTestEvalObjectiveOrientedGUI\showVirtualPassCmd().

31  : void
32  {
33  try {
34  $map = self::getRendererMapForPurpose($service, $purpose);
35  $renderer = self::getRendererInstance($map['selected']);
36  $renderer->prepareGenerationRequest($service, $purpose);
37  } catch (Exception $e) {
38  return;
39  }
40  }
$service
Definition: ltiservices.php:43
+ Here is the caller graph for this function:

◆ removePrintMediaDefinitionsFromStyleFile()

static ilPDFGeneratorUtils::removePrintMediaDefinitionsFromStyleFile ( string  $path)
static

Definition at line 52 of file class.ilPDFGeneratorUtils.php.

References $filename.

52  : void
53  {
54  foreach (glob($path . '*.css') as $filename) {
55  $content = file_get_contents($filename);
56  $content = preg_replace('/@media[\s]* print/', '@media nothing', $content);
57  file_put_contents($filename, $content);
58  }
59  }
$path
Definition: ltiservices.php:32
$filename
Definition: buildRTE.php:78

◆ removeRendererConfig()

static ilPDFGeneratorUtils::removeRendererConfig ( string  $service,
string  $purpose,
string  $renderer 
)
static

Definition at line 168 of file class.ilPDFGeneratorUtils.php.

References $DIC, $ilDB, and $query.

Referenced by ilObjPDFGenerationGUI\resetSettings().

168  : void
169  {
170  global $DIC;
171  $ilDB = $DIC->database();
172 
173  $query = 'DELETE FROM pdfgen_conf WHERE renderer = ' . $ilDB->quote($renderer, 'text') .
174  ' AND service = ' . $ilDB->quote($service, 'text') . ' AND purpose = ' . $ilDB->quote($purpose, 'text');
175 
176  $ilDB->manipulate($query);
177  }
global $DIC
Definition: feed.php:28
$query
$service
Definition: ltiservices.php:43
+ Here is the caller graph for this function:

◆ removeWrongPathFromStyleFiles()

static ilPDFGeneratorUtils::removeWrongPathFromStyleFiles ( string  $path)
static

Definition at line 61 of file class.ilPDFGeneratorUtils.php.

References $filename.

61  : void
62  {
63  foreach (glob($path . '*.css') as $filename) {
64  $content = file_get_contents($filename);
65  $content = preg_replace('/src:\surl\([\',\"](..\/)*(\S)/', "src: url(./$2", $content);
66  file_put_contents($filename, $content);
67  }
68  }
$path
Definition: ltiservices.php:32
$filename
Definition: buildRTE.php:78

◆ saveRendererPurposeConfig()

static ilPDFGeneratorUtils::saveRendererPurposeConfig ( string  $service,
string  $purpose,
string  $renderer,
array  $config 
)
static

Definition at line 211 of file class.ilPDFGeneratorUtils.php.

References $DIC, $ilDB, $query, and $service.

Referenced by ilObjPDFGenerationGUI\saveConfig().

211  : void
212  {
213  global $DIC;
214  $ilDB = $DIC->database();
215 
216  $query = 'DELETE FROM pdfgen_conf WHERE renderer = ' . $ilDB->quote($renderer, 'text') .
217  ' AND service = ' . $ilDB->quote($service, 'text') . ' AND purpose = ' . $ilDB->quote($purpose, 'text');
218 
219  $ilDB->manipulate($query);
220 
221  $ilDB->insert(
222  'pdfgen_conf',
223  [
224  'conf_id' => ['integer', $ilDB->nextId('pdfgen_conf')],
225  'renderer' => ['text', $renderer],
226  'service' => ['text', $service],
227  'purpose' => ['text', $purpose],
228  'config' => ['clob', json_encode($config, JSON_THROW_ON_ERROR)]
229  ]
230  );
231  }
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
global $DIC
Definition: feed.php:28
$query
$service
Definition: ltiservices.php:43
+ Here is the caller graph for this function:

◆ updateRendererSelection()

static ilPDFGeneratorUtils::updateRendererSelection ( string  $service,
string  $purpose,
string  $renderer 
)
static

Definition at line 126 of file class.ilPDFGeneratorUtils.php.

References $DIC, and $ilDB.

Referenced by ilObjPDFGenerationGUI\saveSettings().

126  : void
127  {
128  global $DIC;
129  $ilDB = $DIC->database();
130 
131  $ilDB->update(
132  'pdfgen_map',
133  ['selected' => ['text', $renderer]],
134  [
135  'service' => ['text', $service],
136  'purpose' => ['text', $purpose]
137  ]
138  );
139  }
global $DIC
Definition: feed.php:28
$service
Definition: ltiservices.php:43
+ Here is the caller graph for this function:

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