Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 class ilSQL2XML
00032 {
00039 var $domxml;
00040
00047 var $obj_id;
00048
00055 var $mapping;
00056
00063 var $hash;
00064
00071 var $ilias;
00072
00079 function ilSQL2XML ($a_lm_id, $a_lo_id = "")
00080 {
00081 global $ilias;
00082
00083 $this->ilias =& $ilias;
00084 $this->lm_tree = new ilTree ($a_lm_id,$a_lm_id);
00085
00086 if (!$a_lm_id)
00087 {
00088 $this->ilias->raiseError("No LearningModule ID given",$this->ilias->error_obj->FATAL);
00089 }
00090
00091 $this->lm_id = $a_lm_id;
00092
00093 if (!$a_lo_id)
00094 {
00095
00096
00097 $node_data = $this->lm_tree->getChilds($this->lm_id);
00098
00099 if (!$node_data[0]["obj_id"])
00100 {
00101 $this->ilias->raiseError("No LearningObjects found",$this->ilias->error_obj->FATAL);
00102 }
00103
00104 $this->lo_id = $node_data[0]["obj_id"];
00105
00106 }
00107 else
00108 {
00109 $this->lo_id = $a_lo_id;
00110 }
00111
00112
00113 $this->lo_parent = $this->lm_tree->getParentId($this->lo_id);
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 $this->level = $this->getAttributeValue($this->lo_id,"General","AggregationLevel");
00128 }
00129
00139 function getLearningObject ()
00140 {
00141 global $start;
00142
00143 $this->lo_struct = $this->getStructure($this->lo_id);
00144
00145
00146 if (strstr(php_uname(), "Windows"))
00147 {
00148 $path = "file://";
00149 }
00150
00151 $path .= getcwd();
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 $xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".
00163 "<!DOCTYPE LearningObject SYSTEM \"".$path."/xml/ilias_lo.dtd\">".
00164 "<root />";
00165
00166
00167 $this->doc = domxml_open_mem($xmlHeader);
00168
00169
00170 $root = $this->doc->document_element();
00171 $root->unlink_node();
00172
00173
00174 reset($this->lo_struct);
00175 $start = next($this->lo_struct);
00176
00177
00178 $node = $this->doc->create_element($start["element"]);
00179
00180 $root = $this->doc->append_child($node);
00181
00182 $this->hash[$start["node_id"]] = $root;
00183
00184
00185 $this->buildXML();
00186
00188
00189 if (count($subnodes = $this->doc->get_elements_by_tagname("LO")) > 0)
00190 {
00191 foreach ($subnodes as $subnode)
00192 {
00193
00194 $attributes = $subnode->attributes();
00195 $lo_id = $attributes[0]->value;
00196
00197 $level = $this->getAttributeValue($lo_id,"General","AggregationLevel");
00198
00199
00200
00201
00202
00203 if ($level == "1")
00204 {
00205 $this->hash = array();
00206 $this->lo_struct = $this->getStructure($lo_id);
00207
00208
00209 reset($this->lo_struct);
00210 $start = next($this->lo_struct);
00211
00212
00213 $node = $this->doc->create_element($start["element"]);
00214
00215 $parent = $subnode->parent_node();
00216 $subnode->unlink_node();
00217
00218 $root = $parent->append_child($node);
00219
00220 $this->hash[$start["node_id"]] = $root;
00221
00222
00223 $this->buildXML();
00224
00225
00226 }
00227 else
00228 {
00229
00230 $loObj =& $this->ilias->obj_factory->getInstanceByObjId($lo_id);
00231 $subnode->set_attribute("title", $loObj->getTitle());
00232 $subnode->set_attribute("level", $level);
00233 unset($loObj);
00234 }
00235
00236
00237
00238 }
00239 }
00240
00241
00242 return $this->doc->dump_mem(true);
00243 }
00244
00245 function buildXML ()
00246 {
00247 global $start;
00248
00249
00250
00251 foreach ($this->lo_struct as $key => $node_data)
00252 {
00253
00254 if ($key > $start["node_id"])
00255 {
00256 $insert = false;
00257 switch ($node_data["node_type_id"])
00258 {
00259 case 1:
00260 $node = $this->doc->create_element($node_data["element"]);
00261
00262
00263 if (is_array($node_data["attr_list"]))
00264 {
00265 foreach ($node_data["attr_list"] as $attr => $value)
00266 {
00267 $node->set_attribute($attr, $value);
00268 }
00269 }
00270
00271 $insert = true;
00272 break;
00273
00274 case 3:
00275 $node = $this->doc->create_text_node($node_data["textnode"]);
00276
00277 $insert = true;
00278 break;
00279
00280 }
00281
00282 if ($insert)
00283 {
00284
00285 $parent = $this->hash[$node_data["parent_node_id"]];
00286
00287
00288 $node = $parent->append_child($node);
00289 $this->hash[$this->lo_struct[$key]["node_id"]] = $node;
00290 }
00291 }
00292 }
00293
00294
00295 }
00296
00297
00298 function getStructure($a_lo_id)
00299 {
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00314 $q = "SELECT lo.node_id, lo.node_type_id, lo.lo_id, lo.parent_node_id, lo.struct, tx.textnode, el.element, a_name.attribute, a_value.value ".
00315 "FROM lo_tree AS lo ".
00316 "LEFT OUTER JOIN lo_element_idx AS e_idx ON lo.node_id = e_idx.node_id ".
00317 "LEFT OUTER JOIN lo_element_name AS el ON e_idx.element_id = el.element_id ".
00318 "LEFT OUTER JOIN lo_text AS tx ON lo.node_id = tx.node_id ".
00319 "LEFT OUTER JOIN lo_attribute_idx AS a_idx ON lo.node_id = a_idx.node_id ".
00320 "LEFT JOIN lo_attribute_name AS a_name ON a_idx.attribute_id=a_name.attribute_id ".
00321 "LEFT JOIN lo_attribute_value AS a_value ON a_idx.value_id=a_value.value_id ".
00322 "WHERE lo_id='".$a_lo_id."' ".
00323 "ORDER BY lft ASC";
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 $res = $this->ilias->db->query($q);
00430
00431 while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00432 {
00433 $data[$row["node_id"]] = $row;
00434
00435 if ($row["struct"] & 1)
00436 {
00437 $tmp[$row["node_id"]][] = array ($row["attribute"] => $row["value"]);
00438 }
00439 }
00440
00441
00442 foreach ($tmp as $node_id => $node)
00443 {
00444 $attr_list = array();
00445
00446 foreach ($node as $attr)
00447 {
00448
00449 $attr_list[key($attr)] = $attr[key($attr)];
00450 }
00451
00452 $data[$node_id]["attr_list"] = $attr_list;
00453 }
00454
00455
00456
00457
00458
00459 return $data;
00460 }
00461
00471 function getTree ($a_lo_id)
00472 {
00473 return $tree;
00474 }
00475
00484 function getNode ($a_node_id)
00485 {
00486 return $node;
00487 }
00488
00496 function getElementName ($a_node_id)
00497 {
00498 $q = "SELECT leaf_text FROM lo_element_name_leaf ".
00499 "WHERE node_id='".$a_node_id."' LIMIT 1";
00500
00501 $res = $this->ilias->db->getRow($q, DB_FETCHMODE_ASSOC);
00502
00503 return $res["leaf_text"];
00504 }
00505
00506 function getElementText ($a_node_id)
00507 {
00508 $q = "SELECT leaf_text FROM lo_text_leaf ".
00509 "WHERE node_id='".$a_node_id."' LIMIT 1";
00510
00511 $res = $this->ilias->db->getRow($q, DB_FETCHMODE_ASSOC);
00512
00513 return $res["leaf_text"];
00514 }
00523 function getAttributes ($a_node_id)
00524 {
00525 $q = "SELECT a_name.attribute,a_value.value ".
00526 "FROM lo_attribute_idx AS a_idx ".
00527 "LEFT JOIN lo_attribute_name AS a_name ON a_idx.attribute_id=a_name.attribute_id ".
00528 "LEFT JOIN lo_attribute_value AS a_value ON a_idx.value_id=a_value.value_id ".
00529 "WHERE a_idx.node_id = '".$a_node_id."'";
00530
00531
00532
00533 $res = $this->ilias->db->query($q);
00534
00535 if ($res->numRows())
00536 {
00537 while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00538 {
00539 $data[$row["attribute"]] = $row["value"];
00540 }
00541
00542 return $data;
00543 }
00544
00545 return false;
00546 }
00547
00548
00557 function getAttributeValue ($a_lo_id,$a_element,$a_attribute)
00558 {
00559
00560
00561 $q = "SELECT a_value.value ".
00562 "FROM lo_tree AS lo ".
00563 "LEFT JOIN lo_element_idx AS e_idx ON lo.node_id = e_idx.node_id ".
00564 "LEFT JOIN lo_element_name AS el ON e_idx.element_id = el.element_id ".
00565 "LEFT JOIN lo_attribute_idx AS a_idx ON lo.node_id = a_idx.node_id ".
00566 "LEFT JOIN lo_attribute_name AS a_name ON a_idx.attribute_id=a_name.attribute_id ".
00567 "LEFT JOIN lo_attribute_value AS a_value ON a_idx.value_id=a_value.value_id ".
00568 "WHERE lo_id = '".$a_lo_id."' ".
00569 "AND lo.struct > 0 ".
00570 "AND el.element = '".$a_element."' ".
00571 "AND a_name.attribute = '".$a_attribute."'";
00572
00573
00574
00575 $res = $this->ilias->db->query($q);
00576 $row = $res->fetchRow();
00577
00578
00579 return $row[0];
00580 }
00581
00582 function setNavigation()
00583 {
00584
00585
00586
00587 if ($this->lo_parent != $this->lm_id)
00588 {
00589 $up["child"] = $this->lo_parent;
00590 $up["parent"] = "missing";
00591 }
00592
00593
00594 $node_data = $this->lm_tree->getChilds($this->lo_parent);
00595
00596 foreach ($node_data as $key => $node)
00597 {
00598 if ($this->lo_id == $node["child"])
00599 {
00600 if ($key > 0)
00601 {
00602 $prev["child"] = $node_data[$key-1]["child"];
00603 $prev["parent"] = $node_data[$key-1]["parent"];
00604 }
00605
00606 if (count($node_data) > $key + 1)
00607 {
00608 $next["child"] = $node_data[$key+1]["child"];
00609 $next["parent"] = $node_data[$key+1]["parent"];
00610 }
00611 else
00612 {
00613
00614 $subnode_data = $this->lm_tree->getChilds($this->lo_id);
00615
00616 if (count($subnode_data) > 0)
00617 {
00618
00619 $next["child"] = $subnode_data[0]["child"];
00620 $next["parent"] = $subnode_data[0]["parent"];
00621 }
00622 }
00623
00624 break;
00625 }
00626 }
00627
00628
00629 $navbar = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
00630
00631 if ($prev)
00632 {
00633 $navbar .= "<td>".$this->img_url($prev["child"],$prev["parent"],$this->img_link("arr_left.gif"))."</td>";
00634 }
00635
00636 if ($up)
00637 {
00638 $navbar .= "<td>".$this->img_url($up["child"],$up["parent"],$this->img_link("arr_up.gif"))."</td>";
00639 }
00640
00641 if ($next)
00642 {
00643 $navbar .= "<td>".$this->img_url($next["child"],$next["parent"],$this->img_link("arr_right.gif"))."</td>";
00644 }
00645
00646 $navbar .= "</tr></table>";
00647
00648 return $navbar;
00649 }
00650
00651 function img_link($a_img)
00652 {
00653 return "<img src=\"./images/navigation/".$a_img."\" border=\"0\"/>";
00654 }
00655
00656 function img_url($a_id, $a_parent, $a_img)
00657 {
00658 return "<a href=\"./lo_view.php?type=lo&obj_id=".$_GET["obj_id"]."&lm_id=".$_GET["lm_id"]."&lo_id=".$a_id."&lo_parent=".$a_parent."\">".$a_img."</a>";
00659 }
00660
00670 function getChildNodes ($a_node_id)
00671 {
00672 return $nodes;
00673
00674 return false;
00675 }
00676
00686 function getParentNode ($a_node_id)
00687 {
00688 return $node;
00689
00690 return false;
00691 }
00692
00693 function getFirstChild ($a_node_id)
00694 {
00695 return $node;
00696
00697 return false;
00698 }
00699
00700 function getprevSibling ($a_node_id)
00701 {
00702 return $node;
00703
00704 return false;
00705 }
00706
00707 function getNextSibling ($a_node_id)
00708 {
00709 return $node;
00710
00711 return false;
00712 }
00713 }
00714 ?>
00715