ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilStyleMigration Class Reference

Style Migration Class (->3.11) More...

+ Collaboration diagram for ilStyleMigration:

Public Member Functions

 addMissingStyleCharacteristics ($a_id="")
 Add missing style characteristics to styles. More...
 
 addMissingStyleCharacteristics ()
 

Static Public Member Functions

static _getCoreStyles ()
 Get core styles. More...
 
static _determineTag ($a_type)
 
static _getBasicStyleDom ()
 Get basic style dom. More...
 
static _createImagesDirectory ($a_style_id)
 Create images directory <data_dir>/sty/sty_<id>/images. More...
 
static _getImagesDirectory ($a_style_id)
 Get images directory. More...
 
static _addMissingStyleClassesToAllStyles ()
 Add missing style classes to all styles. More...
 

Static Public Attributes

static $assigned_tags
 
static $core_styles
 

Static Protected Attributes

static $basic_style_file = "./Services/Migration/DBUpdate_1385/basic_style/style.xml"
 
static $basic_style_image_dir = "./Services/Migration/DBUpdate_1385/basic_style/images"
 
static $basic_style_dom
 

Detailed Description

Style Migration Class (->3.11)

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 12 of file class.ilStyleMigration.php.

Member Function Documentation

◆ _addMissingStyleClassesToAllStyles()

static ilStyleMigration::_addMissingStyleClassesToAllStyles ( )
static

Add missing style classes to all styles.

Definition at line 355 of file class.ilStyleMigration.php.

356 {
357 global $ilDB;
358
361
362 // get all core image files
363 $core_images = array();
365 if (is_dir($core_dir))
366 {
367 $dir = opendir($core_dir);
368 while($file = readdir($dir))
369 {
370 if (substr($file, 0, 1) != "." && is_file($core_dir."/".$file))
371 {
372 $core_images[] = $file;
373 }
374 }
375 }
376
377 // check, whether core style class exists
378 $sets = $ilDB->query("SELECT * FROM object_data WHERE type = 'sty'");
379
380 while ($recs = $ilDB->fetchAssoc($sets))
381 {
382 $id = $recs["obj_id"];
383
384 foreach($core_styles as $cs)
385 {
386 // check, whether core style class exists
387 $set = $ilDB->queryF("SELECT * FROM style_char WHERE style_id = %s ".
388 "AND type = %s AND characteristic = %s",
389 array("integer", "text", "text"),
390 array($id, $cs["type"], $cs["class"]));
391
392 // if not, add core style class
393 if (!($rec = $ilDB->fetchAssoc($set)))
394 {
395 $ilDB->manipulateF("INSERT INTO style_char (style_id, type, characteristic) ".
396 " VALUES (%s,%s,%s) ",
397 array("integer", "text", "text"),
398 array($id, $cs["type"], $cs["class"]));
399
400 $xpath = new DOMXPath($bdom);
401 $par_nodes = $xpath->query("/StyleSheet/Style[@Tag = '".$cs["tag"]."' and @Type='".
402 $cs["type"]."' and @Class='".$cs["class"]."']/StyleParameter");
403 foreach ($par_nodes as $par_node)
404 {
405 // check whether style parameter exists
406 $set = $ilDB->queryF("SELECT * FROM style_parameter WHERE style_id = %s ".
407 "AND type = %s AND class = %s AND tag = %s AND parameter = %s",
408 array("integer", "text", "text", "text", "text"),
409 array($id, $cs["type"], $cs["class"],
410 $cs["tag"], $par_node->getAttribute("Name")));
411
412 // if not, create style parameter
413 if (!($rec = $ilDB->fetchAssoc($set)))
414 {
415 $ilDB->manipulateF("INSERT INTO style_parameter (style_id, type, class, tag, parameter, value) ".
416 " VALUES (%s,%s,%s,%s,%s,%s)",
417 array("integer", "text", "text", "text", "text", "text"),
418 array($id, $cs["type"], $cs["class"], $cs["tag"],
419 $par_node->getAttribute("Name"), $par_node->getAttribute("Value")));
420 }
421 }
422 }
423 }
424
425 // now check, whether some core image files are missing
428 reset($core_images);
429 foreach($core_images as $cim)
430 {
431 if (!is_file($imdir."/".$cim))
432 {
433 copy($core_dir."/".$cim, $imdir."/".$cim);
434 }
435 }
436 }
437 }
print $file
static _getBasicStyleDom()
Get basic style dom.
static _createImagesDirectory($a_style_id)
Create images directory <data_dir>/sty/sty_<id>/images.
static _getCoreStyles()
Get core styles.
static _getImagesDirectory($a_style_id)
Get images directory.
global $ilDB

References $basic_style_image_dir, $core_styles, $file, $ilDB, _createImagesDirectory(), _getBasicStyleDom(), _getCoreStyles(), and _getImagesDirectory().

+ Here is the call graph for this function:

◆ _createImagesDirectory()

static ilStyleMigration::_createImagesDirectory (   $a_style_id)
static

Create images directory <data_dir>/sty/sty_<id>/images.

Definition at line 304 of file class.ilStyleMigration.php.

305 {
306 global $ilErr;
307
308 $sty_data_dir = CLIENT_WEB_DIR."/sty";
309 ilUtil::makeDir($sty_data_dir);
310 if(!is_writable($sty_data_dir))
311 {
312 $ilErr->raiseError("Style data directory (".$sty_data_dir
313 .") not writeable.", $ilErr->FATAL);
314 }
315
316 $style_dir = $sty_data_dir."/sty_".$a_style_id;
317 ilUtil::makeDir($style_dir);
318 if(!@is_dir($style_dir))
319 {
320 $ilErr->raiseError("Creation of style directory failed (".
321 $style_dir.").",$ilErr->FATAL);
322 }
323
324 // create images subdirectory
325 $im_dir = $style_dir."/images";
326 ilUtil::makeDir($im_dir);
327 if(!@is_dir($im_dir))
328 {
329 $ilErr->raiseError("Creation of Import Directory failed (".
330 $im_dir.").", $ilErr->FATAL);
331 }
332
333 // create thumbnails directory
334 $thumb_dir = $style_dir."/images/thumbnails";
335 ilUtil::makeDir($thumb_dir);
336 if(!@is_dir($thumb_dir))
337 {
338 $ilErr->raiseError("Creation of Import Directory failed (".
339 $thumb_dir.").", $ilErr->FATAL);
340 }
341 }
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...

References $ilErr, and ilUtil\makeDir().

Referenced by _addMissingStyleClassesToAllStyles().

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

◆ _determineTag()

static ilStyleMigration::_determineTag (   $a_type)
static

Definition at line 279 of file class.ilStyleMigration.php.

280 {
281 return self::$assigned_tags[$a_type];
282 }

Referenced by _getCoreStyles().

+ Here is the caller graph for this function:

◆ _getBasicStyleDom()

static ilStyleMigration::_getBasicStyleDom ( )
static

Get basic style dom.

Definition at line 287 of file class.ilStyleMigration.php.

288 {
289 global $ilBench;
290
291 if (!is_object(self::$basic_style_dom))
292 {
293 self::$basic_style_dom = new DOMDocument();
294 self::$basic_style_dom->load(self::$basic_style_file);
295 }
296
298 }
global $ilBench
Definition: ilias.php:18

References $basic_style_dom, and $ilBench.

Referenced by _addMissingStyleClassesToAllStyles().

+ Here is the caller graph for this function:

◆ _getCoreStyles()

static ilStyleMigration::_getCoreStyles ( )
static

Get core styles.

Definition at line 266 of file class.ilStyleMigration.php.

267 {
268 $c_styles = array();
269 foreach (self::$core_styles as $cstyle)
270 {
271 $c_styles[$cstyle["type"].".".ilStyleMigration::_determineTag($cstyle["type"]).".".$cstyle["class"]]
272 = array("type" => $cstyle["type"],
273 "tag" => ilStyleMigration::_determineTag($cstyle["type"]),
274 "class" => $cstyle["class"]);
275 }
276 return $c_styles;
277 }
static _determineTag($a_type)

References _determineTag().

Referenced by _addMissingStyleClassesToAllStyles().

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

◆ _getImagesDirectory()

static ilStyleMigration::_getImagesDirectory (   $a_style_id)
static

Get images directory.

Definition at line 346 of file class.ilStyleMigration.php.

347 {
348 return CLIENT_WEB_DIR."/sty/sty_".$a_style_id.
349 "/images";
350 }

Referenced by _addMissingStyleClassesToAllStyles().

+ Here is the caller graph for this function:

◆ addMissingStyleCharacteristics() [1/2]

ilStyleMigration::addMissingStyleCharacteristics (   $a_id = "")

Add missing style characteristics to styles.

Definition at line 121 of file class.ilStyleMigration.php.

122 {
123 global $ilDB;
124
125 $add_str = "";
126 if ($a_id != "")
127 {
128 $add_str = " AND style_id = ".$ilDB->quote($a_id, "integer");
129 }
130
131 $set = $ilDB->query($q = "SELECT DISTINCT style_id, tag, class FROM style_parameter WHERE ".
132 $ilDB->equals("type", "", "text", true)." ".$add_str);
133
134 while ($rec = $ilDB->fetchAssoc($set))
135 {
136 // derive types from tag
137 $types = array();
138 switch ($rec["tag"])
139 {
140 case "div":
141 case "p":
142 if (in_array($rec["class"], array("Headline3", "Headline1",
143 "Headline2", "TableContent", "List", "Standard", "Remark",
144 "Additional", "Mnemonic", "Citation", "Example")))
145 {
146 $types[] = "text_block";
147 }
148 if (in_array($rec["class"], array("Block", "Remark",
149 "Additional", "Mnemonic", "Example", "Excursus", "Special")))
150 {
151 $types[] = "section";
152 }
153 if (in_array($rec["class"], array("Page", "Footnote", "PageTitle", "LMNavigation")))
154 {
155 $types[] = "page";
156 }
157 break;
158
159 case "td":
160 $types[] = "table_cell";
161 break;
162
163 case "a":
164 if (in_array($rec["class"], array("ExtLink", "IntLink", "FootnoteLink")))
165 {
166 $types[] = "link";
167 }
168 break;
169
170 case "span":
171 $types[] = "text_inline";
172 break;
173
174 case "table":
175 $types[] = "table";
176 break;
177
178 default:
179 $types[] = array();
180 break;
181 }
182
183 // check if style_char set exists
184 foreach ($types as $t)
185 {
186 // check if second type already exists
187 $set4 = $ilDB->queryF("SELECT * FROM style_char ".
188 " WHERE style_id = %s AND type = %s AND characteristic = %s",
189 array("integer", "text", "text"),
190 array($rec["style_id"], $t, $rec["class"]));
191 if ($rec4 = $ilDB->fetchAssoc($set4))
192 {
193 // ok
194 }
195 else
196 {
197//echo "<br>1-".$rec["style_id"]."-".$t."-".$rec["class"]."-";
198 $ilDB->manipulateF("INSERT INTO style_char ".
199 " (style_id, type, characteristic) VALUES ".
200 " (%s,%s,%s) ",
201 array("integer", "text", "text"),
202 array($rec["style_id"], $t, $rec["class"]));
203 }
204 }
205
206 // update types
207 if ($rec["type"] == "")
208 {
209 if (count($types) > 0)
210 {
211 $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
212 " WHERE style_id = %s AND class = %s AND ".$ilDB->equals("type", "", "text", true),
213 array("text", "integer", "text"),
214 array($types[0], $rec["style_id"], $rec["class"]));
215
216 // links extra handling
217 if ($types[0] == "link")
218 {
219 $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
220 " WHERE style_id = %s AND (class = %s OR class = %s) AND ".$ilDB->equals("type", "", "text", true),
221 array("text", "integer", "text", "text"),
222 array($types[0], $rec["style_id"], $rec["class"].":visited",
223 $rec["class"].":hover"));
224//echo "<br>4-".$types[0]."-".$rec["style_id"]."-".$rec["class"].":visited"."-".
225// $rec["class"].":hover";
226 }
227 }
228
229 if (count($types) == 2)
230 {
231 // select all records of first type and add second type
232 // records if necessary.
233 $set2 = $ilDB->queryF("SELECT * FROM style_parameter ".
234 " WHERE style_id = %s AND class = %s AND type = %s",
235 array("integer", "text", "text"),
236 array($rec["style_id"], $rec["class"], $types[0]));
237 while ($rec2 = $ilDB->fetchAssoc($set2))
238 {
239 // check if second type already exists
240 $set3 = $ilDB->queryF("SELECT * FROM style_parameter ".
241 " WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
242 array("integer", "text", "text", "text", "text"),
243 array($rec["style_id"], $rec["tag"], $rec["class"], $types[1], $rec["parameter"]));
244 if ($rec3 = $ilDB->fetchAssoc($set3))
245 {
246 // ok
247 }
248 else
249 {
250 $ilDB->manipulateF("INSERT INTO style_parameter ".
251 " (style_id, tag, class, parameter, value, type) VALUES ".
252 " (%s,%s,%s,%s,%s,%s) ",
253 array("integer", "text", "text", "text", "text", "text"),
254 array($rec2["style_id"], $rec2["tag"], $rec2["class"],
255 $rec2["parameter"], $rec2["value"], $types[1]));
256 }
257 }
258 }
259 }
260 }
261 }

References $ilDB, and $t.

◆ addMissingStyleCharacteristics() [2/2]

ilStyleMigration::addMissingStyleCharacteristics ( )

Definition at line 36 of file class.ilStyleMigration.php.

37 {
38 global $ilDB;
39
40 $set = $ilDB->query("SELECT DISTINCT style_id, tag, class FROM style_parameter
41 WHERE ".$ilDB->equals("type", "", "text", true));
42 while ($rec = $ilDB->fetchAssoc($set))
43 {
44//echo "<br><b>".$rec["tag"]."-".$rec["class"]."-</b>";
45 // derive types from tag
46 $types = array();
47 switch ($rec["tag"])
48 {
49 case "div":
50 if (in_array($rec["class"], array("Headline3", "Headline1",
51 "Headline2", "TableContent", "List", "Standard", "Remark",
52 "Additional", "Mnemonic", "Citation", "Example")))
53 {
54 $types[] = "text_block";
55 }
56 if (in_array($rec["class"], array("Block", "Remark",
57 "Additional", "Mnemonic", "Example", "Excursus", "Special")))
58 {
59 $types[] = "section";
60 }
61 if (in_array($rec["class"], array("Page", "Footnote", "PageTitle", "LMNavigation")))
62 {
63 $types[] = "page";
64 }
65 break;
66
67 case "td":
68 $types[] = "table_cell";
69 break;
70
71 case "a":
72 if (in_array($rec["class"], array("ExtLink", "IntLink", "FootnoteLink")))
73 {
74 $types[] = "link";
75 }
76 break;
77
78 case "span":
79 $types[] = "text_inline";
80 break;
81
82 case "table":
83 $types[] = "table";
84 break;
85 }
86
87 // check if style_char set exists
88 foreach ($types as $t)
89 {
90 // check if second type already exists
91 $st = $ilDB->prepare("SELECT * FROM style_char ".
92 " WHERE style_id = ? AND type = ? AND characteristic = ?",
93 array("integer", "text", "text"));
94 $set4 = $ilDB->execute($st,
95 array($rec["style_id"], $t, $rec["class"]));
96 if ($rec4 = $ilDB->fetchAssoc($set4))
97 {
98 // ok
99 }
100 else
101 {
102//echo "<br>1-".$rec["style_id"]."-".$t."-".$rec["class"]."-";
103 $st = $ilDB->prepareManip("INSERT INTO style_char ".
104 " (style_id, type, characteristic) VALUES ".
105 " (?,?,?) ",
106 array("integer", "text", "text"));
107 $ilDB->execute($st,
108 array($rec["style_id"], $t, $rec["class"]));
109 }
110 }
111
112 // update types
113 if ($rec["type"] == "")
114 {
115 if (count($types) > 0)
116 {
117 $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
118 " WHERE style_id = %s AND class = %s AND type = %s",
119 array("text", "integer", "text", "text"),
120 array($types[0], $rec["style_id"], $rec["class"], ""));
121//echo "<br>2-".$types[0]."-".$rec["style_id"]."-".$rec["class"]."-";
122
123 // links extra handling
124 if ($types[0] == "link")
125 {
126 $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
127 " WHERE style_id = %s AND (class = %s OR class = %s) AND type = %s",
128 array("text", "integer", "text", "text", "text"),
129 array($types[0], $rec["style_id"], $rec["class"].":visited",
130 $rec["class"].":hover", ""));
131 }
132 }
133//echo "A";
134 if (count($types) == 2)
135 {
136//echo "B";
137 // select all records of first type and add second type
138 // records if necessary.
139 $set2 = $ilDB->queryF("SELECT * FROM style_parameter ".
140 " WHERE style_id = %s AND class = %s AND type = %s",
141 array("integer", "text", "text"),
142 array($rec["style_id"], $rec["class"], $types[0]));
143 while ($rec2 = $ilDB->fetchAssoc($set2))
144 {
145//echo "C";
146 // check if second type already exists
147 $set3 = $ilDB->queryF("SELECT * FROM style_parameter ".
148 " WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
149 array("integer", "text", "text", "text", "text", "text"),
150 array($rec["style_id"], $rec["tag"], $rec["class"], $types[1], $rec["parameter"]));
151 if ($rec3 = $ilDB->fetchAssoc($set3))
152 {
153 // ok
154 }
155 else
156 {
157//echo "D";
158 $id = $ilDB->nextId("style_parameter");
159 $st = $ilDB->prepareManip("INSERT INTO style_parameter ".
160 " (id,style_id, tag, class, parameter, value, type) VALUES ".
161 " (%s,%s,%s,%s,%s,%s,%s) ",
162 array("integer","integer", "text", "text", "text", "text", "text"),
163 array($id, $rec2["style_id"], $rec2["tag"], $rec2["class"],
164 $rec2["parameter"], $rec2["value"], $types[1]));
165 }
166 }
167 }
168 }
169 }
170 }

References $ilDB, and $t.

Field Documentation

◆ $assigned_tags

ilStyleMigration::$assigned_tags
static

Definition at line 15 of file class.ilStyleMigration.php.

◆ $basic_style_dom

ilStyleMigration::$basic_style_dom
staticprotected

Definition at line 116 of file class.ilStyleMigration.php.

Referenced by _getBasicStyleDom().

◆ $basic_style_file

ilStyleMigration::$basic_style_file = "./Services/Migration/DBUpdate_1385/basic_style/style.xml"
staticprotected

Definition at line 114 of file class.ilStyleMigration.php.

◆ $basic_style_image_dir

ilStyleMigration::$basic_style_image_dir = "./Services/Migration/DBUpdate_1385/basic_style/images"
staticprotected

Definition at line 115 of file class.ilStyleMigration.php.

Referenced by _addMissingStyleClassesToAllStyles().

◆ $core_styles

ilStyleMigration::$core_styles
static

Definition at line 57 of file class.ilStyleMigration.php.

Referenced by _addMissingStyleClassesToAllStyles().


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