ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilStyleMigration.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("Services/Table/classes/class.ilTable2GUI.php");
25 
34 class ilStyleMigration
35 {
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  }
171 }
172 ?>