ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPDFGeneratorUtils.php
Go to the documentation of this file.
1<?php
2
7{
8 public static function getTestPdfDir()
9 {
10 $iliasPDFTestPath = 'data/' . CLIENT_ID . '/pdf_service/';
11 if (!file_exists($iliasPDFTestPath)) {
12 mkdir($iliasPDFTestPath);
13 }
14 return $iliasPDFTestPath;
15 }
16
21 {
22 foreach (glob($path . '*.css') as $filename) {
23 $content = file_get_contents($filename);
24 $content = preg_replace('/@media[\s]* print/', '@media nothing', $content);
25 file_put_contents($filename, $content);
26 }
27 }
28
32 public static function removeWrongPathFromStyleFiles($path)
33 {
34 foreach (glob($path . '*.css') as $filename) {
35 $content = file_get_contents($filename);
36 $content = preg_replace('/src:\surl\‍([\',\"](..\/)*(\S)/', "src: url(./$2", $content);
37 file_put_contents($filename, $content);
38 }
39 }
40
44 public static function setCheckedIfTrue(\ilPropertyFormGUI $form)
45 {
46 foreach ($form->getItems() as $item) {
47 if ($item instanceof ilCheckboxInputGUI) {
48 if ($item->getChecked() != null && ($item->getValue() == true || $item->getValue() == '1')) {
49 $item->setChecked(true);
50 }
51 }
52 }
53 }
54
55 public static function getPurposeMap()
56 {
57 global $DIC;
58 $ilDB = $DIC['ilDB'];
59
60 $purposes = array();
61
62 $result = $ilDB->query('SELECT service, purpose FROM pdfgen_purposes ORDER BY service, purpose');
63
64 while ($row = $ilDB->fetchAssoc($result)) {
65 $purposes[$row['service']][] = $row['purpose'];
66 }
67
68 return $purposes;
69 }
70
71 public static function getSelectionMap()
72 {
73 global $DIC;
74 $ilDB = $DIC['ilDB'];
75
76 $mappings = array();
77 $result = $ilDB->query('SELECT service, purpose, preferred, selected FROM pdfgen_map');
78
79 while ($row = $ilDB->fetchAssoc($result)) {
80 $mappings[$row['service']][$row['purpose']]['selected'] = $row['selected'];
81 $mappings[$row['service']][$row['purpose']]['preferred'] = $row['preferred'];
82 }
83
84 return $mappings;
85 }
86
87 public static function getRenderers()
88 {
89 global $DIC;
90 $ilDB = $DIC['ilDB'];
91
92 $renderers = array();
93 $result = $ilDB->query('SELECT renderer, service, purpose FROM pdfgen_renderer_avail');
94
95 while ($row = $ilDB->fetchAssoc($result)) {
96 $renderers[$row['service']][$row['purpose']][] = $row['renderer'];
97 }
98
99 return $renderers;
100 }
101
107 public static function updateRendererSelection($service, $purpose, $renderer)
108 {
109 global $DIC;
110 $ilDB = $DIC['ilDB'];
111
112 $ilDB->update(
113 'pdfgen_map',
114 array( 'selected' => array('text', $renderer) ),
115 array(
116 'service' => array('text', $service),
117 'purpose' => array('text', $purpose)
118 )
119 );
120 }
121
128 public static function getRendererConfig($service, $purpose, $renderer)
129 {
130 global $DIC;
132 $ilDB = $DIC['ilDB'];
133
134 $query = 'SELECT config FROM pdfgen_conf WHERE renderer = ' . $ilDB->quote($renderer, 'text') .
135 ' AND service = ' . $ilDB->quote($service, 'text') . ' AND purpose = ' . $ilDB->quote($purpose, 'text');
136
137 $result = $ilDB->query($query);
138 if ($ilDB->numRows($result) == 0) {
139 return self::getRendererDefaultConfig($service, $purpose, $renderer);
140 } else {
141 $row = $ilDB->fetchAssoc($result);
142 return json_decode($row['config'], true);
143 }
144 }
145
152 public static function getRendererDefaultConfig($service, $purpose, $renderer)
153 {
155 $class_instance = self::getRendererInstance($renderer);
156
157 return $class_instance->getDefaultConfig($service, $purpose);
158 }
159
165 public static function removeRendererConfig($service, $purpose, $renderer)
166 {
167 global $DIC;
168 $ilDB = $DIC['ilDB'];
169
170 $query = 'DELETE FROM pdfgen_conf WHERE renderer = ' . $ilDB->quote($renderer, 'text') .
171 ' AND service = ' . $ilDB->quote($service, 'text') . ' AND purpose = ' . $ilDB->quote($purpose, 'text');
172
173 $ilDB->manipulate($query);
174 }
175
181 public static function getRendererInstance($renderer)
182 {
183 global $DIC;
185 $ilDB = $DIC['ilDB'];
186
187 $result = $ilDB->query('SELECT path FROM pdfgen_renderer WHERE renderer = ' . $ilDB->quote($renderer, 'text'));
188
189 if ($ilDB->numRows($result) == 0) {
190 throw new Exception('No such renderer - given: ' . $renderer);
191 }
192 $row = $ilDB->fetchAssoc($result);
193
194 include_once $row['path'];
195 if (self::isRendererPlugin($row['path'])) {
196 $classname = 'il' . $renderer . 'RendererPlugin';
197 } else {
198 $classname = 'il' . $renderer . 'Renderer';
199 }
200
201 if (false && !class_exists($classname)) {
202 throw new Exception(
203 'Class failed loading, including path ' . $row['path']
204 . ' did not lead to class definition ' . $classname . ' being available.'
205 );
206 }
207
208 $class_instance = new $classname;
209 return $class_instance;
210 }
211
216 protected static function isRendererPlugin($path)
217 {
218 $needle = 'Plugin.php';
219 $length = strlen($needle);
220 return (substr($path, -$length) === $needle);
221 }
222
229 public static function saveRendererPurposeConfig($service, $purpose, $renderer, $config)
230 {
231 global $DIC;
233 $ilDB = $DIC['ilDB'];
234
235 $query = 'DELETE FROM pdfgen_conf WHERE renderer = ' . $ilDB->quote($renderer, 'text') .
236 ' AND service = ' . $ilDB->quote($service, 'text') . ' AND purpose = ' . $ilDB->quote($purpose, 'text');
237
238 $ilDB->manipulate($query);
239
240 $ilDB->insert(
241 'pdfgen_conf',
242 array(
243 'conf_id' => array('integer', $ilDB->nextId('pdfgen_conf')),
244 'renderer' => array('text', $renderer),
245 'service' => array('text', $service),
246 'purpose' => array('text', $purpose),
247 'config' => array('clob', json_encode($config))
248 )
249 );
250 }
251
257 public static function getRendererMapForPurpose($service, $purpose)
258 {
259 global $DIC;
261 $ilDB = $DIC['ilDB'];
262
263 $result = $ilDB->query('SELECT preferred, selected FROM pdfgen_map WHERE
264 service = ' . $ilDB->quote($service, 'text') . ' AND purpose=' . $ilDB->quote($purpose, 'text'));
265
266 if ($ilDB->numRows($result) == 0) {
267 return array('selected' => 'TCPDF', 'preferred' => 'TCPDF');
268 }
269 $row = $ilDB->fetchAssoc($result);
270
271 return $row;
272 }
273}
$result
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
Class ilPDFGeneratorUtils.
static removeRendererConfig($service, $purpose, $renderer)
static removeWrongPathFromStyleFiles($path)
static updateRendererSelection($service, $purpose, $renderer)
static setCheckedIfTrue(\ilPropertyFormGUI $form)
static removePrintMediaDefinitionsFromStyleFile($path)
This class represents a property form user interface.
$service
Definition: login.php:15
$query
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
global $ilDB