ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.
 addMissingStyleCharacteristics ()

Static Public Member Functions

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

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

static ilStyleMigration::_addMissingStyleClassesToAllStyles ( )
static

Add missing style classes to all styles.

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

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

{
global $ilDB;
// get all core image files
$core_images = array();
if (is_dir($core_dir))
{
$dir = opendir($core_dir);
while($file = readdir($dir))
{
if (substr($file, 0, 1) != "." && is_file($core_dir."/".$file))
{
$core_images[] = $file;
}
}
}
// check, whether core style class exists
$sets = $ilDB->query("SELECT * FROM object_data WHERE type = 'sty'");
while ($recs = $ilDB->fetchAssoc($sets))
{
$id = $recs["obj_id"];
foreach($core_styles as $cs)
{
// check, whether core style class exists
$set = $ilDB->queryF("SELECT * FROM style_char WHERE style_id = %s ".
"AND type = %s AND characteristic = %s",
array("integer", "text", "text"),
array($id, $cs["type"], $cs["class"]));
// if not, add core style class
if (!($rec = $ilDB->fetchAssoc($set)))
{
$ilDB->manipulateF("INSERT INTO style_char (style_id, type, characteristic) ".
" VALUES (%s,%s,%s) ",
array("integer", "text", "text"),
array($id, $cs["type"], $cs["class"]));
$xpath = new DOMXPath($bdom);
$par_nodes = $xpath->query("/StyleSheet/Style[@Tag = '".$cs["tag"]."' and @Type='".
$cs["type"]."' and @Class='".$cs["class"]."']/StyleParameter");
foreach ($par_nodes as $par_node)
{
// check whether style parameter exists
$set = $ilDB->queryF("SELECT * FROM style_parameter WHERE style_id = %s ".
"AND type = %s AND class = %s AND tag = %s AND parameter = %s",
array("integer", "text", "text", "text", "text"),
array($id, $cs["type"], $cs["class"],
$cs["tag"], $par_node->getAttribute("Name")));
// if not, create style parameter
if (!($rec = $ilDB->fetchAssoc($set)))
{
$ilDB->manipulateF("INSERT INTO style_parameter (style_id, type, class, tag, parameter, value) ".
" VALUES (%s,%s,%s,%s,%s,%s)",
array("integer", "text", "text", "text", "text", "text"),
array($id, $cs["type"], $cs["class"], $cs["tag"],
$par_node->getAttribute("Name"), $par_node->getAttribute("Value")));
}
}
}
}
// now check, whether some core image files are missing
reset($core_images);
foreach($core_images as $cim)
{
if (!is_file($imdir."/".$cim))
{
copy($core_dir."/".$cim, $imdir."/".$cim);
}
}
}
}

+ Here is the call graph for this function:

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.

References $ilErr, and ilUtil\makeDir().

Referenced by _addMissingStyleClassesToAllStyles().

{
global $ilErr;
$sty_data_dir = CLIENT_WEB_DIR."/sty";
ilUtil::makeDir($sty_data_dir);
if(!is_writable($sty_data_dir))
{
$ilErr->raiseError("Style data directory (".$sty_data_dir
.") not writeable.", $ilErr->FATAL);
}
$style_dir = $sty_data_dir."/sty_".$a_style_id;
ilUtil::makeDir($style_dir);
if(!@is_dir($style_dir))
{
$ilErr->raiseError("Creation of style directory failed (".
$style_dir.").",$ilErr->FATAL);
}
// create images subdirectory
$im_dir = $style_dir."/images";
ilUtil::makeDir($im_dir);
if(!@is_dir($im_dir))
{
$ilErr->raiseError("Creation of Import Directory failed (".
$im_dir.").", $ilErr->FATAL);
}
// create thumbnails directory
$thumb_dir = $style_dir."/images/thumbnails";
ilUtil::makeDir($thumb_dir);
if(!@is_dir($thumb_dir))
{
$ilErr->raiseError("Creation of Import Directory failed (".
$thumb_dir.").", $ilErr->FATAL);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilStyleMigration::_determineTag (   $a_type)
static

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

Referenced by _getCoreStyles().

{
return self::$assigned_tags[$a_type];
}

+ Here is the caller graph for this function:

static ilStyleMigration::_getBasicStyleDom ( )
static

Get basic style dom.

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

References $basic_style_dom, and $ilBench.

Referenced by _addMissingStyleClassesToAllStyles().

{
global $ilBench;
if (!is_object(self::$basic_style_dom))
{
self::$basic_style_dom = new DOMDocument();
self::$basic_style_dom->load(self::$basic_style_file);
}
}

+ Here is the caller graph for this function:

static ilStyleMigration::_getCoreStyles ( )
static

Get core styles.

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

References _determineTag().

Referenced by _addMissingStyleClassesToAllStyles().

{
$c_styles = array();
foreach (self::$core_styles as $cstyle)
{
$c_styles[$cstyle["type"].".".ilStyleMigration::_determineTag($cstyle["type"]).".".$cstyle["class"]]
= array("type" => $cstyle["type"],
"tag" => ilStyleMigration::_determineTag($cstyle["type"]),
"class" => $cstyle["class"]);
}
return $c_styles;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilStyleMigration::_getImagesDirectory (   $a_style_id)
static

Get images directory.

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

Referenced by _addMissingStyleClassesToAllStyles().

{
return CLIENT_WEB_DIR."/sty/sty_".$a_style_id.
"/images";
}

+ Here is the caller graph for this function:

ilStyleMigration::addMissingStyleCharacteristics ( )

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

References $ilDB, and $t.

{
global $ilDB;
$set = $ilDB->query("SELECT DISTINCT style_id, tag, class FROM style_parameter
WHERE ".$ilDB->equals("type", "", "text", true));
while ($rec = $ilDB->fetchAssoc($set))
{
//echo "<br><b>".$rec["tag"]."-".$rec["class"]."-</b>";
// derive types from tag
$types = array();
switch ($rec["tag"])
{
case "div":
if (in_array($rec["class"], array("Headline3", "Headline1",
"Headline2", "TableContent", "List", "Standard", "Remark",
"Additional", "Mnemonic", "Citation", "Example")))
{
$types[] = "text_block";
}
if (in_array($rec["class"], array("Block", "Remark",
"Additional", "Mnemonic", "Example", "Excursus", "Special")))
{
$types[] = "section";
}
if (in_array($rec["class"], array("Page", "Footnote", "PageTitle", "LMNavigation")))
{
$types[] = "page";
}
break;
case "td":
$types[] = "table_cell";
break;
case "a":
if (in_array($rec["class"], array("ExtLink", "IntLink", "FootnoteLink")))
{
$types[] = "link";
}
break;
case "span":
$types[] = "text_inline";
break;
case "table":
$types[] = "table";
break;
}
// check if style_char set exists
foreach ($types as $t)
{
// check if second type already exists
$st = $ilDB->prepare("SELECT * FROM style_char ".
" WHERE style_id = ? AND type = ? AND characteristic = ?",
array("integer", "text", "text"));
$set4 = $ilDB->execute($st,
array($rec["style_id"], $t, $rec["class"]));
if ($rec4 = $ilDB->fetchAssoc($set4))
{
// ok
}
else
{
//echo "<br>1-".$rec["style_id"]."-".$t."-".$rec["class"]."-";
$st = $ilDB->prepareManip("INSERT INTO style_char ".
" (style_id, type, characteristic) VALUES ".
" (?,?,?) ",
array("integer", "text", "text"));
$ilDB->execute($st,
array($rec["style_id"], $t, $rec["class"]));
}
}
// update types
if ($rec["type"] == "")
{
if (count($types) > 0)
{
$ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
" WHERE style_id = %s AND class = %s AND type = %s",
array("text", "integer", "text", "text"),
array($types[0], $rec["style_id"], $rec["class"], ""));
//echo "<br>2-".$types[0]."-".$rec["style_id"]."-".$rec["class"]."-";
// links extra handling
if ($types[0] == "link")
{
$ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
" WHERE style_id = %s AND (class = %s OR class = %s) AND type = %s",
array("text", "integer", "text", "text", "text"),
array($types[0], $rec["style_id"], $rec["class"].":visited",
$rec["class"].":hover", ""));
}
}
//echo "A";
if (count($types) == 2)
{
//echo "B";
// select all records of first type and add second type
// records if necessary.
$set2 = $ilDB->queryF("SELECT * FROM style_parameter ".
" WHERE style_id = %s AND class = %s AND type = %s",
array("integer", "text", "text"),
array($rec["style_id"], $rec["class"], $types[0]));
while ($rec2 = $ilDB->fetchAssoc($set2))
{
//echo "C";
// check if second type already exists
$set3 = $ilDB->queryF("SELECT * FROM style_parameter ".
" WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
array("integer", "text", "text", "text", "text", "text"),
array($rec["style_id"], $rec["tag"], $rec["class"], $types[1], $rec["parameter"]));
if ($rec3 = $ilDB->fetchAssoc($set3))
{
// ok
}
else
{
//echo "D";
$id = $ilDB->nextId("style_parameter");
$st = $ilDB->prepareManip("INSERT INTO style_parameter ".
" (id,style_id, tag, class, parameter, value, type) VALUES ".
" (%s,%s,%s,%s,%s,%s,%s) ",
array("integer","integer", "text", "text", "text", "text", "text"),
array($id, $rec2["style_id"], $rec2["tag"], $rec2["class"],
$rec2["parameter"], $rec2["value"], $types[1]));
}
}
}
}
}
}
ilStyleMigration::addMissingStyleCharacteristics (   $a_id = "")

Add missing style characteristics to styles.

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

References $ilDB, $q, and $t.

{
global $ilDB;
$add_str = "";
if ($a_id != "")
{
$add_str = " AND style_id = ".$ilDB->quote($a_id, "integer");
}
$set = $ilDB->query($q = "SELECT DISTINCT style_id, tag, class FROM style_parameter WHERE ".
$ilDB->equals("type", "", "text", true)." ".$add_str);
while ($rec = $ilDB->fetchAssoc($set))
{
// derive types from tag
$types = array();
switch ($rec["tag"])
{
case "div":
case "p":
if (in_array($rec["class"], array("Headline3", "Headline1",
"Headline2", "TableContent", "List", "Standard", "Remark",
"Additional", "Mnemonic", "Citation", "Example")))
{
$types[] = "text_block";
}
if (in_array($rec["class"], array("Block", "Remark",
"Additional", "Mnemonic", "Example", "Excursus", "Special")))
{
$types[] = "section";
}
if (in_array($rec["class"], array("Page", "Footnote", "PageTitle", "LMNavigation")))
{
$types[] = "page";
}
break;
case "td":
$types[] = "table_cell";
break;
case "a":
if (in_array($rec["class"], array("ExtLink", "IntLink", "FootnoteLink")))
{
$types[] = "link";
}
break;
case "span":
$types[] = "text_inline";
break;
case "table":
$types[] = "table";
break;
default:
$types[] = array();
break;
}
// check if style_char set exists
foreach ($types as $t)
{
// check if second type already exists
$set4 = $ilDB->queryF("SELECT * FROM style_char ".
" WHERE style_id = %s AND type = %s AND characteristic = %s",
array("integer", "text", "text"),
array($rec["style_id"], $t, $rec["class"]));
if ($rec4 = $ilDB->fetchAssoc($set4))
{
// ok
}
else
{
//echo "<br>1-".$rec["style_id"]."-".$t."-".$rec["class"]."-";
$ilDB->manipulateF("INSERT INTO style_char ".
" (style_id, type, characteristic) VALUES ".
" (%s,%s,%s) ",
array("integer", "text", "text"),
array($rec["style_id"], $t, $rec["class"]));
}
}
// update types
if ($rec["type"] == "")
{
if (count($types) > 0)
{
$ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
" WHERE style_id = %s AND class = %s AND ".$ilDB->equals("type", "", "text", true),
array("text", "integer", "text"),
array($types[0], $rec["style_id"], $rec["class"]));
// links extra handling
if ($types[0] == "link")
{
$ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
" WHERE style_id = %s AND (class = %s OR class = %s) AND ".$ilDB->equals("type", "", "text", true),
array("text", "integer", "text", "text"),
array($types[0], $rec["style_id"], $rec["class"].":visited",
$rec["class"].":hover"));
//echo "<br>4-".$types[0]."-".$rec["style_id"]."-".$rec["class"].":visited"."-".
// $rec["class"].":hover";
}
}
if (count($types) == 2)
{
// select all records of first type and add second type
// records if necessary.
$set2 = $ilDB->queryF("SELECT * FROM style_parameter ".
" WHERE style_id = %s AND class = %s AND type = %s",
array("integer", "text", "text"),
array($rec["style_id"], $rec["class"], $types[0]));
while ($rec2 = $ilDB->fetchAssoc($set2))
{
// check if second type already exists
$set3 = $ilDB->queryF("SELECT * FROM style_parameter ".
" WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
array("integer", "text", "text", "text", "text"),
array($rec["style_id"], $rec["tag"], $rec["class"], $types[1], $rec["parameter"]));
if ($rec3 = $ilDB->fetchAssoc($set3))
{
// ok
}
else
{
$ilDB->manipulateF("INSERT INTO style_parameter ".
" (style_id, tag, class, parameter, value, type) VALUES ".
" (%s,%s,%s,%s,%s,%s) ",
array("integer", "text", "text", "text", "text", "text"),
array($rec2["style_id"], $rec2["tag"], $rec2["class"],
$rec2["parameter"], $rec2["value"], $types[1]));
}
}
}
}
}
}

Field Documentation

ilStyleMigration::$assigned_tags
static

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

ilStyleMigration::$basic_style_dom
staticprotected

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

Referenced by _getBasicStyleDom().

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

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

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().

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: