ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilNestedSetXML.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "./Services/Xml/classes/class.ilXML2DOM.php";
5
17{
18 // {{{ Vars
19
23 var $db;
24
28 var $LEFT = 0;
29 var $RIGHT = 0;
30
35 var $DEPTH = 0;
36
40 var $obj_id;
41
45 var $obj_type;
46
50 var $xml_parser;
51
55 var $lastTag = "";
56
62 var $ilias;
63
69 var $dom;
70
76 private $unique_import_id = '';
77
78 // }}}
79
85 function ilNestedSetXML()
86 {
87 global $ilias,$ilDB;
88
89 $this->ilias =& $ilias;
90
91 $this->db =& $ilDB;
92 $this->LEFT = 0;
93 $this->RIGHT = 0;
94 $this->DEPTH = 0;
95 $this->unique_import_id = '';
96
97 $this->param_modifier = "";
98 }
99
100
111 function startElement($parser, $name, $attrs)
112 {
113 // {{{
114
115 $this->lastTag = $name;
116 $this->LEFT += 1;
117 $this->RIGHT = $this->LEFT + 1;
118 $this->DEPTH++;
119
124 $nextId = $this->db->nextId('xmltags');
125 $this->db->manipulateF('INSERT INTO xmltags ( tag_pk,tag_name,tag_depth ) VALUES (%s,%s,%s)',
126 array('integer','text','integer'), array($nextId, $name, $this->DEPTH));
127
128 $pk = $nextId;
129 $this->db->manipulateF('
130 UPDATE xmlnestedsettmp SET ns_r = ns_r+2
131 WHERE ns_r >= %s AND ns_book_fk = %s AND ns_unique_id = %s',
132 array('integer','integer', 'text'), array($this->LEFT, $this->obj_id, $this->unique_import_id));
133
134 $id = $this->db->nextId('xmlnestedsettmp');
135
136 $this->db->manipulateF('
137 INSERT INTO xmlnestedsettmp (ns_id, ns_unique_id, ns_book_fk, ns_type, ns_tag_fk, ns_l, ns_r) VALUES (%s,%s,%s,%s,%s,%s,%s)',
138 array('integer','text','integer','text','integer','integer','integer'),
139 array($id, $this->unique_import_id, $this->obj_id, $this->obj_type, $pk, $this->LEFT, $this->RIGHT));
140
141 $this->clean($attrs);
142 if (is_array($attrs) && count($attrs)>0)
143 {
144 reset ($attrs);
145 while (list ($key, $val) = each ($attrs))
146 {
147 $this->db->manipulateF('INSERT INTO xmlparam ( tag_fk,param_name,param_value ) VALUES (%s,%s,%s)',
148 array('integer','text','text'),
149 array($pk,$key,addslashes($val)));
150 }
151 }
152
153 return($pk);
154 // }}}
155 }
156
165 function characterData($parser, $data)
166 {
167 // {{{
173 static $value_pk;
174
175 // we don't need this trim since expression like ' ABC < > ' will be parsed to ' ABC <>'
176 if(1 or trim($data)!="") {
177
178
179 if ($this->lastTag == "TAGVALUE")
180 {
181 $this->db->manipulateF('UPDATE xmlvalue SET tag_value = %s WHERE tag_value_pk = %s',
182 array('text','integer'), array(concat(tag_value,addslashes($data)),$value_pk));
183 }
184 else
185 {
186 $tag_pk = $this->startElement($this->xml_parser,"TAGVALUE",array());
187 $this->endElement($this->xml_parser,"TAGVALUE");
188
189 $nextId = $this->db->nextId('xmlvalue');
190
191
192 $this->db->manipulateF('INSERT INTO xmlvalue (tag_value_pk, tag_fk, tag_value) VALUES (%s,%s,%s)',
193 array('integer','integer','text'), array($nextId,$tag_pk,addslashes($data)));
194
195 $value_pk = $nextId;
196
197 $this->lastTag = "TAGVALUE";
198 }
199
200 }
201 // }}}
202 }
203
211 function endElement($parser, $name)
212 {
213 // {{{
214 $this->DEPTH--;
215 $this->LEFT += 1;
216 $this->lastTag = "";
217 // }}}
218 }
219
228 function import($xmldata, $obj_id, $obj_type)
229 {
230 global $ilUser;
231
232 // {{{
237 $this->obj_id = $obj_id;
238 $this->obj_type = $obj_type;
239 $this->DEPTH = 0;
240 $this->LEFT = 0;
241 $this->RIGHT = 0;
242 $this->unique_import_id = $ilUser->getId();
243
244 $this->db->manipulateF(
245 "DELETE FROM xmlnestedsettmp WHERE ns_unique_id = %s",
246 array('text'),
247 array($this->unique_import_id)
248 );
249
254 $this->xml_parser = xml_parser_create("UTF-8");
255 xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false);
256 xml_set_object($this->xml_parser,$this);
257 xml_set_element_handler($this->xml_parser, "startElement", "endElement");
258 xml_set_character_data_handler($this->xml_parser, "characterData");
259
260 if (!xml_parse($this->xml_parser, $xmldata)) {
261 die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->xml_parser)),xml_get_current_line_number($this->xml_parser)));
262 }
263 xml_parser_free($this->xml_parser);
264
268 $this->deleteAllDbData();
269
270 $res = $this->db->query("
271 SELECT ns_book_fk, ns_type, ns_tag_fk, ns_l, ns_r
272 FROM xmlnestedsettmp
273 WHERE ns_unique_id =
274 " . $this->db->quote($this->unique_import_id, "text"));
275
276 while($row = $this->db->fetchAssoc($res))
277 {
278 $id = $this->db->nextId('xmlnestedset');
279
280 $this->db->manipulate("INSERT INTO xmlnestedset (ns_id, ns_book_fk, ns_type, ns_tag_fk, ns_l, ns_r)".
281 " VALUES (".
282 $this->db->quote($id, "integer").
283 ",".$this->db->quote($row['ns_book_fk'], "integer").
284 ",".$this->db->quote($row['ns_type'], "text").
285 ",".$this->db->quote($row['ns_tag_fk'], "integer").
286 ",".$this->db->quote($row['ns_l'], "integer").
287 ",".$this->db->quote($row['ns_r'], "integer").
288 ")"
289 );
290 }/*
291 $this->db->manipulateF(
292 "INSERT INTO xmlnestedset (SELECT ns_book_fk, ns_type, ns_tag_fk, ns_l, ns_r FROM xmlnestedsettmp WHERE ns_unique_id = %s)",
293 array('text'),
294 array($this->unique_import_id)
295 );*/
296
297 $this->db->manipulateF(
298 "DELETE FROM xmlnestedsettmp WHERE ns_unique_id = %s",
299 array('text'),
300 array($this->unique_import_id)
301 );
302 // }}}
303 }
304
310 function setParameterModifier(&$a_object, $a_method)
311 {
312 $this->param_modifier =& $a_object;
313 $this->param_modifier_method = $a_method;
314 }
315
327 function export($obj_id, $type)
328 {
329 // {{{
330
331 $result = $this->db->queryF('
332 SELECT * FROM xmlnestedset,xmltags
333 WHERE ns_tag_fk = tag_pk
334 AND ns_book_fk = %s
335 AND ns_type = %s
336 ORDER BY ns_l',
337 array('integer','text'),
338 array($obj_id,$type));
339
341 {
342 die($this->className."::checkTable(): ".$result->getMessage().":<br>".$q);
343 }
344
345 $xml = "";
346 $lastDepth = -1;
347
348 while (is_array($row = $this->db->fetchAssoc($result)))
349 {
350
351 // {{{ tags
352 $Anfang = "<".$row[tag_name];
353
354 $result_param = $this->db->queryF('SELECT * FROM xmlparam WHERE tag_fk = %s',array('integer'),array($row[tag_pk]));
355 while (is_array($row_param = $this->db->fetchAssoc($result_param)))
356 {
357 $param_value = $row_param[param_value];
358 if (is_object($this->param_modifier))
359 {
360 $obj =& $this->param_modifier;
361 $method = $this->param_modifier_method;
362 $param_value = $obj->$method($row[tag_name], $row_param[param_name], $param_value);
363 }
364 $Anfang .= " ".$row_param[param_name]."=\"".$param_value."\"";
365 }
366
367 $Anfang .= ">";
368 $Ende = "</".$row[tag_name].">";
369 // }}}
370
371 // {{{ TagValue
372 if ($row[tag_name]=="TAGVALUE")
373 {
374 $result_value = $this->db->queryF('SELECT * FROM xmlvalue WHERE tag_fk = %s', array('integer'),array($row[tag_pk]));
375 $row_value = $this->db->fetchAssoc($result_value);
376
377 $Anfang = $row_value["tag_value"];
378 $Ende = "";
379
380 $Anfang = htmlspecialchars($Anfang);
381 // $Anfang = utf8_encode($Anfang);
382 }
383 // }}}
384
385 $D = $row[tag_depth];
386
387 if ($D==$lastDepth)
388 {
389 $xml .= $xmlE[$D];
390 $xml .= $Anfang;
391 $xmlE[$D] = $Ende;
392 }
393 else if ($D>$lastDepth)
394 {
395 $xml .= $Anfang;
396 $xmlE[$D] = $Ende;
397 }
398 else
399 {
400 for ($i=$lastDepth;$i>=$D;$i--)
401 {
402 $xml .= $xmlE[$i];
403 }
404 $xml .= $Anfang;
405 $xmlE[$D] = $Ende;
406 }
407
408 $lastDepth = $D;
409
410 }
411
412 for ($i=$lastDepth;$i>0;$i--)
413 {
414 $xml .= $xmlE[$i];
415 }
416
417 return($xml);
418 // }}}
419 }
420
429 {
430 // {{{
431 $this->db->setLimit(1);
432
433 $result = $this->db->queryF('
434 SELECT * FROM xmlnestedset,xmltags
435 WHERE ns_book_fk = %s
436 AND ns_type = %s
437 AND ns_tag_fk = tag_pk
438 ORDER BY ns_l',
439 array('integer','text'),
440 array($obj_id, $obj_type));
441
442 $row = $this->db->fetchAssoc($result);
443
444 $this->LEFT = $row["ns_l"];
445 $this->RIGHT = $row["ns_r"];
446 $this->DEPTH = $row["tag_depth"];
447 $this->obj_id = $obj_id;
448 $this->obj_type = $obj_type;
449 // }}}
450 }
451
459 function getTagName()
460 {
461
462 $this->db->setLimit(1);
463
464 $result = $this->db->queryF('
465 SELECT * FROM xmlnestedset,xmltags
466 WHERE ns_book_fk = %s
467 AND ns_type = %s
468 AND ns_l = %s
469 AND ns_r = %s
470 AND ns_tag_fk = tag_pk',
471 array('integer','text','integer','integer'),
472 array($this->obj_id,$this->obj_type,$this->LEFT,$this->RIGHT));
473
474 $row = $this->db->fetchAssoc($result);
475
476 return($row["tag_name"]);
477
478 }
479
489 function setTagName($tagName)
490 {
491
492 $this->db->setLimit(1);
493
494 $result = $this->db->queryF('
495 SELECT * FROM xmlnestedset
496 WHERE ns_book_fk = %s
497 AND ns_type = %s
498 AND ns_l = %s
499 AND ns_r = %s',
500 array('integer','text','integer','integer'),
501 array($this->obj_id,$this->obj_type,$this->LEFT,$this->RIGHT));
502
503 $row = $this->db->fetchAssoc($result);
504
505 $this->db->manipulateF('UPDATE xmltags SET tag_name = %s WHERE tag_pk = %s',
506 array('text','integer'), array($tagName,$row["ns_tag_fk"]));
507
508
509 return($row["tagName"]);
510
511 }
512
513
520 function getTagValue()
521 {
522
523 $V = array();
524
525 $result = $this->db->queryF('
526 SELECT * FROM xmlnestedset,xmltags
527 WHERE ns_tag_fk = tag_pk
528 AND ns_book_fk = %s
529 AND ns_type = %s
530 AND ns_l >= %s
531 AND ns_r <= %s
532 AND tag_depth = %s
533 ORDER BY ns_l',
534 array('integer','text','integer','integer','integer'),
535 array($this->obj_id,$this->obj_type,$this->LEFT,$this->RIGHT,$this->DEPTH+1));
536
537 while (is_array($row = $this->db->fetchAssoc($result) ) )
538 {
539 if ($row[tag_name]=="TAGVALUE")
540 {
541 $result2 = $this->db->queryF('SELECT * FROM xmlvalue WHERE tag_fk = %s', array('integer'),array($row[tag_pk]));
542 $row2 = $this->db->fetchAssoc($result2);
543 $V[] = $row2[tag_value];
544 }
545 else
546 {
547 $xml = new ilNestedSetXml();
548
549 $xml->LEFT = $row["ns_l"];
550 $xml->RIGHT = $row["ns_r"];
551 $xml->DEPTH = $row["tag_depth"];
552 $xml->obj_id = $obj_id;
553 $xml->obj_type = $obj_type;
554
555 $V[] = $xml;
556
557 }
558 }
559
560 return($V);
561 }
562
569 function setTagValue($value)
570 {
571 $V = array();
572
573
574 $result = $this->db->queryF('
575 SELECT * FROM xmlnestedset,xmltags
576 LEFT JOIN xmlvalue ON xmltags.tag_pk = xmlvalue.tag_fk
577 WHERE ns_tag_fk = tag_pk
578 AND ns_book_fk = %s
579 AND ns_type = %s
580 AND ns_l >= %s
581 AND ns_r <= %s
582 AND tag_depth = %s
583 AND tag_name = %s
584 AND ORDER BY ns_l',
585 array('integer','text','integer','integer','integer','text'),
586 array($this->obj_id, $this->obj_type, $this->LEFT, $this->RIGHT, $this->DEPTH+1,'TAGVALUE')
587 );
588
589 if (is_array($row = $this->db->fetchAssoc($result) ) )
590 {
591 $this->db->manipulateF('UPDATE xmlvalue SET tag_value = %s WHERE tag_value_pk = %s',
592 array('text','integer'), array($value, $row["tag_value_pk"]));
593
594 }
595 else
596 {
597
602 }
603 }
604
614 function getXpathNodes(&$doc, $qry)
615 {
616 if (is_object($doc))
617 {
618 $xpath = $doc->xpath_init();
619 $ctx = $doc->xpath_new_context();
620//echo "<br><b>ilNestedSetXML::getXpathNodes</b>";
621 $result = $ctx->xpath_eval($qry);
622 if (is_array($result->nodeset))
623 {
624 return($result->nodeset);
625 }
626 }
627 return Null;
628 }
629
636 function initDom()
637 {
638 $xml = $this->export($this->obj_id, $this->obj_type);
639
640/*
641 for testing
642 $xml_test = '
643 <MetaData>
644 <General Structure="Atomic">
645 <Identifier Catalog="ILIAS" Entry="34">Identifier 34 in ILIAS</Identifier>
646 <Identifier Catalog="ILIAS" Entry="45">Identifier 45 in ILIAS</Identifier>
647 <Identifier Catalog="ILIAS" Entry="67">Identifier 67 in ILIAS</Identifier>
648 </General>
649 </MetaData>
650 ';
651
652 $xml = $xml_test;
653*/
654
655 if ($xml=="")
656 {
657 return(false);
658 }
659 else
660 {
661 $this->dom = domxml_open_mem($xml);
662 return(true);
663 }
664 }
665
676 function addXMLNode($xPath, $xml, $index = 0)
677 {
678 $newDOM = new XML2DOM($xml);
679//echo "<br>addXMLNode:-".htmlspecialchars($this->dom->dump_mem(0));
680 $nodes = $this->getXpathNodes($this->dom, $xPath);
681
682 if (count($nodes) > 0)
683 {
684 $newDOM->insertNode($this->dom, $nodes[$index]);
685 return true;
686 }
687 else
688 {
689 return false;
690 }
691 }
692
701 function getFirstDomContent($xPath)
702 {
703//echo "<br>ilNestedSetXML::getFirstDomContent-start-$xPath-"; flush();
704 $content = "";
705 if (is_object($this->dom))
706 {
707 $node = $this->getXpathNodes($this->dom,$xPath);
708 if (is_array($node))
709 {
710 if (is_object($node[0]))
711 {
712 $c = $node[0]->children();
713 //$content = $c[0]->content; // ## changed
714 if (is_object($c[0]))
715 {
716 $content = $c[0]->get_content(); // ## changed
717 }
718 }
719 }
720 }
721//echo "<br>ilNestedSetXML::getFirstDomContent-stop-$content-"; flush();
722 return($content);
723 }
724
735 function deleteDomNode($xPath, $name, $index = 0)
736 {
737 if ($index == "")
738 {
739 $index = 0;
740 }
741 if (strpos($index, ","))
742 {
743 $indices = explode(",", $index);
744 $nodes = $this->getXpathNodes($this->dom, $xPath);
745 if (count($nodes) > 0)
746 {
747 $children = $nodes[$indices[0]]->child_nodes();
748 if (count($children) > 0)
749 {
750 $j = 0;
751 for ($i = 0; $i < count($children); $i++)
752 {
753 if ($children[$i]->node_name() == $name)
754 {
755 if ($j == $indices[1])
756 {
757 $children[$i]->unlink_node();
758 return true;
759 }
760 $j++;
761 }
762 }
763 }
764 }
765 }
766 else
767 {
768 $nodes = $this->getXpathNodes($this->dom, $xPath . "/" . $name);
769 if (count($nodes) > 0)
770 {
771 $nodes[$index]->unlink_node();
772 return true;
773 }
774 }
775 return false;
776 }
777
790 function addDomNode($xPath, $name, $value = "", $attributes = "", $index = 0)
791 {
792 $nodes = $this->getXpathNodes($this->dom, $xPath);
793 if (count($nodes) > 0)
794 {
795 $node = $this->dom->create_element($name);
796 if ($value != "")
797 {
798 $node->set_content(utf8_encode($value));
799 }
800 if (is_array($attributes))
801 {
802 for ($i = 0; $i < count($attributes); $i++)
803 {
804 $node->set_attribute($attributes[$i]["name"], utf8_encode($attributes[$i]["value"]));
805 }
806 }
807 $nodes[$index]->append_child($node);
808 return true;
809 }
810 else
811 {
812 return false;
813 }
814 }
815
816 function clean(&$meta)
817 {
818 if(is_array($meta))
819 {
820 foreach($meta as $key => $value)
821 {
822 if(is_array($meta[$key]))
823 {
824 $this->clean($meta[$key]);
825 }
826 else
827 {
828 $meta[$key] = ilUtil::stripSlashes($meta[$key]);
829 $meta[$key] = preg_replace("/&(?!amp;|lt;|gt;|quot;)/","&amp;",$meta[$key]);
830 $meta[$key] = preg_replace("/\"/","&quot;",$meta[$key]);
831 $meta[$key] = preg_replace("/</","&lt;",$meta[$key]);
832 $meta[$key] = preg_replace("/>/","&gt;",$meta[$key]);
833 }
834 }
835 }
836 return true;
837 }
846 function updateDomNode($xPath, $meta, $no = 0)
847 {
848 $this->clean($meta);
849 $update = false;
850 if ($xPath == "//Bibliography")
851 {
852 $nodes = $this->getXpathNodes($this->dom, $xPath . "/BibItem[" . ($no+1) . "]");
853 }
854 else
855 {
856 $nodes = $this->getXpathNodes($this->dom, $xPath);
857 }
858 if (count($nodes) > 0)
859 {
860
861 /* BibItem */
862 if ($nodes[0]->node_name() == "BibItem")
863 {
864 $xml = '<BibItem Type="' . ilUtil::stripSlashes($meta["Type"]) . '" Label="' . ilUtil::stripSlashes($meta["Label"]["Value"]) . '">';
865 $xml .= '<Identifier Catalog="' . ilUtil::stripSlashes($meta["Identifier"]["Catalog"]) . '" Entry="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Identifier"]["Entry"])) . '"/>';
866 for ($i = 0; $i < count($meta["Language"]); $i++)
867 {
868 $xml .= '<Language Language="' . ilUtil::stripSlashes($meta["Language"][$i]["Language"]) . '"/>';
869 }
870 for ($i = 0; $i < count($meta["Author"]); $i++)
871 {
872 $xml .= '<Author>';
873# for ($j = 0; $j < count($meta["Author"][$i]["FirstName"]); $j++)
874# {
875 $xml .= '<FirstName>' . ilUtil::stripSlashes($meta["Author"][$i]["FirstName"]) . '</FirstName>';
876# }
877# for ($j = 0; $j < count($meta["Author"][$i]["MiddleName"]); $j++)
878# {
879 $xml .= '<MiddleName>' . ilUtil::stripSlashes($meta["Author"][$i]["MiddleName"]) . '</MiddleName>';
880# }
881# for ($j = 0; $j < count($meta["Author"][$i]["LastName"]); $j++)
882# {
883 $xml .= '<LastName>' . ilUtil::stripSlashes($meta["Author"][$i]["LastName"]) . '</LastName>';
884# }
885 $xml .= '</Author>';
886 }
887 $xml .= '<Booktitle Language="' . ilUtil::stripSlashes($meta["Booktitle"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Booktitle"]["Value"]) . '</Booktitle>';
888 for ($i = 0; $i < count($meta["CrossRef"]); $i++)
889 {
890 $xml .= '<CrossRef>' . ilUtil::stripSlashes($meta["CrossRef"][$i]["Value"]) . '</CrossRef>';
891 }
892 $xml .= '<Edition>' . ilUtil::stripSlashes($meta["Edition"]["Value"]) . '</Edition>';
893 for ($i = 0; $i < count($meta["Editor"]); $i++)
894 {
895 $xml .= '<Editor>' . ilUtil::stripSlashes($meta["Editor"][$i]["Value"]) . '</Editor>';
896 }
897 $xml .= '<HowPublished Type="' . ilUtil::stripSlashes($meta["HowPublished"]["Type"]) . '"/>';
898 for ($i = 0; $i < count($meta["WherePublished"]); $i++)
899 {
900 $xml .= '<WherePublished>' . ilUtil::stripSlashes($meta["WherePublished"][$i]["Value"]) . '</WherePublished>';
901 }
902 for ($i = 0; $i < count($meta["Institution"]); $i++)
903 {
904 $xml .= '<Institution>' . ilUtil::stripSlashes($meta["Institution"][$i]["Value"]) . '</Institution>';
905 }
906 if (is_array($meta["Journal"]))
907 {
908 $xml .= '<Journal Note="' . ilUtil::stripSlashes($meta["Journal"]["Note"]) . '" Number="' . ilUtil::stripSlashes($meta["Journal"]["Number"]) . '" Organization="' . ilUtil::stripSlashes($meta["Journal"]["Organization"]) . '"/>';
909 }
910 for ($i = 0; $i < count($meta["Keyword"]); $i++)
911 {
912 $xml .= '<Keyword Language="' . ilUtil::stripSlashes($meta["Keyword"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Keyword"][$i]["Value"]) . '</Keyword>';
913 }
914 if (is_array($meta["Month"]))
915 {
916 $xml .= '<Month>' . ilUtil::stripSlashes($meta["Month"]["Value"]) . '</Month>';
917 }
918 if (is_array($meta["Pages"]))
919 {
920 $xml .= '<Pages>' . ilUtil::stripSlashes($meta["Pages"]["Value"]) . '</Pages>';
921 }
922 $xml .= '<Publisher>' . ilUtil::stripSlashes($meta["Publisher"]["Value"]) . '</Publisher>';
923 for ($i = 0; $i < count($meta["School"]); $i++)
924 {
925 $xml .= '<School>' . ilUtil::stripSlashes($meta["School"][$i]["Value"]) . '</School>';
926 }
927 if (is_array($meta["Series"]))
928 {
929 $xml .= '<Series>';
930 $xml .= '<SeriesTitle>' . ilUtil::stripSlashes($meta["Series"]["SeriesTitle"]) . '</SeriesTitle>';
931# for ($i = 0; $i < count($meta["Series"]["SeriesEditor"]); $i++)
932 if (isset($meta["Series"]["SeriesEditor"]))
933 {
934# $xml .= '<SeriesEditor>' . ilUtil::stripSlashes($meta["Series"]["SeriesEditor"][$i]) . '</SeriesEditor>';
935 $xml .= '<SeriesEditor>' . ilUtil::stripSlashes($meta["Series"]["SeriesEditor"]) . '</SeriesEditor>';
936 }
937 if (isset($meta["Series"]["SeriesVolume"]))
938 {
939 $xml .= '<SeriesVolume>' . ilUtil::stripSlashes($meta["Series"]["SeriesVolume"]) . '</SeriesVolume>';
940 }
941 $xml .= '</Series>';
942 }
943 $xml .= '<Year>' . ilUtil::stripSlashes($meta["Year"]["Value"]) . '</Year>';
944 if ($meta["URL_ISBN_ISSN"]["Type"] == "URL")
945 {
946 $xml .= '<URL>' . ilUtil::stripSlashes($meta["URL_ISBN_ISSN"]["Value"]) . '</URL>';
947 }
948 else if ($meta["URL_ISBN_ISSN"]["Type"] == "ISBN")
949 {
950 $xml .= '<ISBN>' . ilUtil::stripSlashes($meta["URL_ISBN_ISSN"]["Value"]) . '</ISBN>';
951 }
952 else if ($meta["URL_ISBN_ISSN"]["Type"] == "ISSN")
953 {
954 $xml .= '<ISSN>' . ilUtil::stripSlashes($meta["URL_ISBN_ISSN"]["Value"]) . '</ISSN>';
955 }
956 $xml .= '</BibItem>';
957# echo htmlspecialchars($xml);
958
959 $update = true;
960 }
961
962 /* General */
963 else if ($nodes[0]->node_name() == "General")
964 {
965
966 $xml = '<General Structure="' . ilUtil::stripSlashes($meta["Structure"]) . '">';
967 for ($i = 0; $i < count($meta["Identifier"]); $i++)
968 {
969 $xml .= '<Identifier Catalog="' . ilUtil::stripSlashes($meta["Identifier"][$i]["Catalog"]) . '" Entry="' .
970 str_replace("\"", "", ilUtil::stripSlashes($meta["Identifier"][$i]["Entry"])) . '"/>';
971 }
972
973 $xml .= '<Title Language="' .
974 ilUtil::stripSlashes($meta["Title"]["Language"]) . '">' .
975 ilUtil::stripSlashes($meta["Title"]["Value"]) . '</Title>';
976 for ($i = 0; $i < count($meta["Language"]); $i++)
977 {
978 $xml .= '<Language Language="' . ilUtil::stripSlashes($meta["Language"][$i]["Language"]) . '"/>';
979 }
980 for ($i = 0; $i < count($meta["Description"]); $i++)
981 {
982 $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Description"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Description"][$i]["Value"]) . '</Description>';
983 }
984 for ($i = 0; $i < count($meta["Keyword"]); $i++)
985 {
986 $xml .= '<Keyword Language="' . ilUtil::stripSlashes($meta["Keyword"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Keyword"][$i]["Value"]) . '</Keyword>';
987 }
988 if ($meta["Coverage"] != "")
989 {
990 $xml .= '<Coverage Language="' . ilUtil::stripSlashes($meta["Coverage"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Coverage"]["Value"]) . '</Coverage>';
991 }
992 $xml .= '</General>';
993//echo "<br><br>".htmlspecialchars($xml);
994
995 $update = true;
996 }
997
998 /* Lifecycle */
999 else if ($nodes[0]->node_name() == "Lifecycle")
1000 {
1001 $xml = '<Lifecycle Status="' . $meta["Status"] . '">';
1002 $xml .= '<Version Language="' . ilUtil::stripSlashes($meta["Version"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Version"]["Value"]) . '</Version>';
1003 for ($i = 0; $i < count($meta["Contribute"]); $i++)
1004 {
1005 $xml .= '<Contribute Role="' . ilUtil::stripSlashes($meta["Contribute"][$i]["Role"]) . '">';
1006 $xml .= '<Date>' . ilUtil::stripSlashes($meta["Contribute"][$i]["Date"]) . '</Date>';
1007 for ($j = 0; $j < count($meta["Contribute"][$i]["Entity"]); $j++)
1008 {
1009 $xml .= '<Entity>' . ilUtil::stripSlashes($meta["Contribute"][$i]["Entity"][$j]) . '</Entity>';
1010 }
1011 $xml .= '</Contribute>';
1012 }
1013 $xml .= '</Lifecycle>';
1014# echo htmlspecialchars($xml);
1015
1016 $update = true;
1017 }
1018
1019 /* Meta-Metadata */
1020 else if ($nodes[0]->node_name() == "Meta-Metadata")
1021 {
1022
1023 $xml = '<Meta-Metadata MetadataScheme="LOM v 1.0" Language="' . ilUtil::stripSlashes($meta["Language"]) . '">';
1024 for ($i = 0; $i < count($meta["Identifier"]); $i++)
1025 {
1026 $xml .= '<Identifier Catalog="' . ilUtil::stripSlashes($meta["Identifier"][$i]["Catalog"]) . '" Entry="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Identifier"][$i]["Entry"])) . '"/>';
1027 }
1028 for ($i = 0; $i < count($meta["Contribute"]); $i++)
1029 {
1030 $xml .= '<Contribute Role="' . ilUtil::stripSlashes($meta["Contribute"][$i]["Role"]) . '">';
1031 $xml .= '<Date>' . ilUtil::stripSlashes($meta["Contribute"][$i]["Date"]) . '</Date>';
1032 for ($j = 0; $j < count($meta["Contribute"][$i]["Entity"]); $j++)
1033 {
1034 $xml .= '<Entity>' . ilUtil::stripSlashes($meta["Contribute"][$i]["Entity"][$j]) . '</Entity>';
1035 }
1036 $xml .= '</Contribute>';
1037 }
1038 $xml .= '</Meta-Metadata>';
1039# echo htmlspecialchars($xml);
1040
1041 $update = true;
1042 }
1043
1044 /* Technical */
1045 else if ($nodes[0]->node_name() == "Technical")
1046 {
1047
1048 $xml = '<Technical>';
1049 for ($i = 0; $i < count($meta["Format"]); $i++)
1050 {
1051 $xml .= '<Format>' . ilUtil::stripSlashes($meta["Format"][$i]) . '</Format>';
1052 }
1053 if ($meta["Size"] != "")
1054 {
1055 $xml .= '<Size>' . ilUtil::stripSlashes($meta["Size"]) . '</Size>';
1056 }
1057 for ($i = 0; $i < count($meta["Location"]); $i++)
1058 {
1059 $xml .= '<Location Type="' . ilUtil::stripSlashes($meta["Location"][$i]["Type"]) . '">' . ilUtil::stripSlashes($meta["Location"][$i]["Value"]) . '</Location>';
1060 }
1061 if (is_array($meta["Requirement"]))
1062 {
1063 for ($i = 0; $i < count($meta["Requirement"]); $i++)
1064 {
1065 $xml .= '<Requirement>';
1066 $xml .= '<Type>';
1067 if (is_array($meta["Requirement"][$i]["Type"]["OperatingSystem"]))
1068 {
1069 $xml .= '<OperatingSystem Name="' . ilUtil::stripSlashes($meta["Requirement"][$i]["Type"]["OperatingSystem"]["Name"]) . '" MinimumVersion="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Requirement"][$i]["Type"]["OperatingSystem"]["MinimumVersion"])) . '" MaximumVersion="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Requirement"][$i]["Type"]["OperatingSystem"]["MaximumVersion"])) . '"/>';
1070 }
1071 if (is_array($meta["Requirement"][$i]["Type"]["Browser"]))
1072 {
1073 $xml .= '<Browser Name="' . ilUtil::stripSlashes($meta["Requirement"][$i]["Type"]["Browser"]["Name"]) . '" MinimumVersion="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Requirement"][$i]["Type"]["Browser"]["MinimumVersion"])) . '" MaximumVersion="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Requirement"][$i]["Type"]["Browser"]["MaximumVersion"])) . '"/>';
1074 }
1075 $xml .= '</Type>';
1076 $xml .= '</Requirement>';
1077 }
1078 }
1079 else if (is_array($meta["OrComposite"]))
1080 {
1081 for ($j = 0; $j < count($meta["OrComposite"]); $j++)
1082 {
1083 $xml .= '<OrComposite>';
1084 for ($i = 0; $i < count($meta["OrComposite"][$j]["Requirement"]); $i++)
1085 {
1086 $xml .= '<Requirement>';
1087 $xml .= '<Type>';
1088 if (is_array($meta["OrComposite"][$j]["Requirement"][$i]["Type"]["OperatingSystem"]))
1089 {
1090 $xml .= '<OperatingSystem Name="' . ilUtil::stripSlashes($meta["OrComposite"][$j]["Requirement"][$i]["Type"]["OperatingSystem"]["Name"]) . '" MinimumVersion="' . str_replace("\"", "", ilUtil::stripSlashes($meta["OrComposite"][$j]["Requirement"][$i]["Type"]["OperatingSystem"]["MinimumVersion"])) . '" MaximumVersion="' . str_replace("\"", "", ilUtil::stripSlashes($meta["OrComposite"][$j]["Requirement"][$i]["Type"]["OperatingSystem"]["MaximumVersion"])) . '"/>';
1091 }
1092 if (is_array($meta["OrComposite"][$j]["Requirement"][$i]["Type"]["Browser"]))
1093 {
1094 $xml .= '<Browser Name="' . ilUtil::stripSlashes($meta["OrComposite"][$j]["Requirement"][$i]["Type"]["Browser"]["Name"]) . '" MinimumVersion="' . str_replace("\"", "", ilUtil::stripSlashes($meta["OrComposite"][$j]["Requirement"][$i]["Type"]["Browser"]["MinimumVersion"])) . '" MaximumVersion="' . str_replace("\"", "", ilUtil::stripSlashes($meta["OrComposite"][$j]["Requirement"][$i]["Type"]["Browser"]["MaximumVersion"])) . '"/>';
1095 }
1096 $xml .= '</Type>';
1097 $xml .= '</Requirement>';
1098 }
1099 $xml .= '</OrComposite>';
1100 }
1101 }
1102 if (is_array($meta["InstallationRemarks"]))
1103 {
1104 $xml .= '<InstallationRemarks Language="' . ilUtil::stripSlashes($meta["InstallationRemarks"]["Language"]) . '">' . ilUtil::stripSlashes($meta["InstallationRemarks"]["Value"]) . '</InstallationRemarks>';
1105 }
1106 if (is_array($meta["OtherPlattformRequirements"]))
1107 {
1108 $xml .= '<OtherPlattformRequirements Language="' . ilUtil::stripSlashes($meta["OtherPlattformRequirements"]["Language"]) . '">' . ilUtil::stripSlashes($meta["OtherPlattformRequirements"]["Value"]) . '</OtherPlattformRequirements>';
1109 }
1110 if ($meta["Duration"] != "")
1111 {
1112 $xml .= '<Duration>' . ilUtil::stripSlashes($meta["Duration"]) . '</Duration>';
1113 }
1114 $xml .= '</Technical>';
1115# echo htmlspecialchars($xml);
1116
1117 $update = true;
1118 }
1119
1120 /* Educational */
1121 else if ($nodes[0]->node_name() == "Educational")
1122 {
1123
1124 $xml = '<Educational InteractivityType="' . ilUtil::stripSlashes($meta["InteractivityType"]) . '" LearningResourceType="' . ilUtil::stripSlashes($meta["LearningResourceType"]) . '" InteractivityLevel="' . ilUtil::stripSlashes($meta["InteractivityLevel"]) . '" SemanticDensity="' . ilUtil::stripSlashes($meta["SemanticDensity"]) . '" IntendedEndUserRole="' . ilUtil::stripSlashes($meta["IntendedEndUserRole"]) . '" Context="' . ilUtil::stripSlashes($meta["Context"]) . '" Difficulty="' . ilUtil::stripSlashes($meta["Difficulty"]) . '">';
1125 $xml .= '<TypicalLearningTime>' . ilUtil::stripSlashes($meta["TypicalLearningTime"]) . '</TypicalLearningTime>';
1126 for ($i = 0; $i < count($meta["TypicalAgeRange"]); $i++)
1127 {
1128 $xml .= '<TypicalAgeRange Language="' . ilUtil::stripSlashes($meta["TypicalAgeRange"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["TypicalAgeRange"][$i]["Value"]) . '</TypicalAgeRange>';
1129 }
1130 for ($i = 0; $i < count($meta["Description"]); $i++)
1131 {
1132 $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Description"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Description"][$i]["Value"]) . '</Description>';
1133 }
1134 for ($i = 0; $i < count($meta["Language"]); $i++)
1135 {
1136 $xml .= '<Language Language="' . ilUtil::stripSlashes($meta["Language"][$i]["Language"]) . '"/>';
1137 }
1138 $xml .= '</Educational>';
1139
1140 $update = true;
1141 }
1142
1143 /* Rights */
1144 else if ($nodes[0]->node_name() == "Rights")
1145 {
1146
1147 $xml = '<Rights Cost="' . ilUtil::stripSlashes($meta["Cost"]) . '" CopyrightAndOtherRestrictions="' . ilUtil::stripSlashes($meta["CopyrightAndOtherRestrictions"]) . '">';
1148 for ($i = 0; $i < count($meta["Description"]); $i++)
1149 {
1150 $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Description"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Description"][$i]["Value"]) . '</Description>';
1151 }
1152 $xml .= '</Rights>';
1153
1154 $update = true;
1155 }
1156
1157 /* Relation */
1158 else if ($nodes[0]->node_name() == "Relation")
1159 {
1160
1161# for ($j = 0; $j < count($meta["Relation"]); $j++)
1162# {
1163 $meta["Relation"][0] = $meta;
1164 $j = 0;
1165 $xml = '<Relation Kind="' . ilUtil::stripSlashes($meta["Relation"][$j]["Kind"]) . '">';
1166 $xml .= '<Resource>';
1167 for ($i = 0; $i < count($meta["Relation"][$j]["Resource"]["Identifier"]); $i++)
1168 {
1169 $xml .= '<Identifier_ Catalog="' . ilUtil::stripSlashes($meta["Relation"][$j]["Resource"]["Identifier"][$i]["Catalog"]) . '" Entry="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Relation"][$j]["Resource"]["Identifier"][$i]["Entry"])) . '"/>';
1170 }
1171 for ($i = 0; $i < count($meta["Relation"][$j]["Resource"]["Description"]); $i++)
1172 {
1173 $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Relation"][$j]["Resource"]["Description"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Relation"][$j]["Resource"]["Description"][$i]["Value"]) . '</Description>';
1174 }
1175 $xml .= '</Resource>';
1176 $xml .= '</Relation>';
1177# echo htmlspecialchars($xml);
1178# }
1179
1180 $update = true;
1181 }
1182
1183 /* Annotation */
1184 else if ($nodes[0]->node_name() == "Annotation")
1185 {
1186
1187# for ($i = 0; $i < count($meta["Annotation"]); $i++)
1188# {
1189 $meta["Annotation"][0] = $meta;
1190 $i = 0;
1191 $xml = '<Annotation>';
1192 $xml .= '<Entity>' . ilUtil::stripSlashes($meta["Annotation"][$i]["Entity"]) . '</Entity>';
1193 $xml .= '<Date>' . ilUtil::stripSlashes($meta["Annotation"][$i]["Date"]) . '</Date>';
1194 $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Annotation"][$i]["Description"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Annotation"][$i]["Description"]["Value"]) . '</Description>';
1195 $xml .= '</Annotation>';
1196# echo htmlspecialchars($xml);
1197# }
1198
1199 $update = true;
1200 }
1201
1202 /* Classification */
1203 else if ($nodes[0]->node_name() == "Classification")
1204 {
1205
1206# for ($j = 0; $j < count($meta["Classification"]); $j++)
1207# {
1208 $meta["Classification"][0] = $meta;
1209 $j = 0;
1210 $xml = '<Classification Purpose="' . ilUtil::stripSlashes($meta["Classification"][$j]["Purpose"]) . '">';
1211 for ($k = 0; $k < count($meta["Classification"][$j]["TaxonPath"]); $k++)
1212 {
1213 $xml .= '<TaxonPath>';
1214 $xml .= '<Source Language="' . ilUtil::stripSlashes($meta["Classification"][$j]["TaxonPath"][$k]["Source"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Classification"][$j]["TaxonPath"][$k]["Source"]["Value"]) . '</Source>';
1215 for ($i = 0; $i < count($meta["Classification"][$j]["TaxonPath"][$k]["Taxon"]); $i++)
1216 {
1217 $xml .= '<Taxon Language="' . ilUtil::stripSlashes($meta["Classification"][$j]["TaxonPath"][$k]["Taxon"][$i]["Language"]) . '" Id="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Classification"][$j]["TaxonPath"][$k]["Taxon"][$i]["Id"])) . '">' . ilUtil::stripSlashes($meta["Classification"][$j]["TaxonPath"][$k]["Taxon"][$i]["Value"]) . '</Taxon>';
1218 }
1219 $xml .= '</TaxonPath>';
1220 }
1221 $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Classification"][$j]["Description"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Classification"][$j]["Description"]["Value"]) . '</Description>';
1222 for ($i = 0; $i < count($meta["Classification"][$j]["Keyword"]); $i++)
1223 {
1224 $xml .= '<Keyword Language="' . ilUtil::stripSlashes($meta["Classification"][$j]["Keyword"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Classification"][$j]["Keyword"][$i]["Value"]) . '</Keyword>';
1225 }
1226 $xml .= '</Classification>';
1227# echo htmlspecialchars($xml);
1228# }
1229
1230 $update = true;
1231 }
1232
1233 if ($update)
1234 {
1235 $nodes[0]->unlink_node();
1236
1237 if ($xPath != "//Bibliography")
1238 {
1239 $xPath = "//MetaData";
1240 }
1241//echo "<br><br>savedA:".htmlspecialchars($this->dom->dump_mem(0));
1242 $this->addXMLNode($xPath, $xml);
1243//echo "<br><br>savedB:".htmlspecialchars($this->dom->dump_mem(0));
1244 }
1245 return true;
1246 }
1247 else
1248 {
1249 return false;
1250 }
1251 }
1252
1263 function getDomContent($xPath, $name = "", $index = 0)
1264 {
1265 if ($index == "")
1266 {
1267 $index = 0;
1268 }
1269# echo "Index: " . $index . " | Path: " . $xPath . " | Name: " . $name . "<br>\n";
1270 $nodes = $this->getXpathNodes($this->dom, $xPath);
1271 if (count($nodes) > 0)
1272 {
1273 $children = $nodes[$index]->child_nodes();
1274 if (count($children) > 0)
1275 {
1276 $k = 0;
1277 for ($i = 0; $i < count($children); $i++)
1278 {
1279//echo "<br>ilNestedSetXML::getDomContent-".$children[$i]->node_name()."-".$name;
1280 if ($name == "" ||
1281 $children[$i]->node_name() == $name)
1282 {
1283 $content[$k]["value"] = $children[$i]->get_content();
1284 $a = $children[$i]->attributes();
1285 for ($j = 0; $j < count($a); $j++)
1286 {
1287 $content[$k][$a[$j]->name()] = $a[$j]->value();
1288 }
1289 $k++;
1290 }
1291 }
1292# vd($content);
1293 return($content);
1294 }
1295 }
1296 return false;
1297 }
1298
1307 function replaceDomContent($xPath, $name = "", $index = 0, $newNode)
1308 {
1309# echo "Index: " . $index . " | Path: " . $xPath . " | Name: " . $name . "<br>\n";
1310 $nodes = $this->getXpathNodes($this->dom, $xPath);
1311 if (count($nodes) > 0)
1312 {
1313 $children = $nodes[$index]->child_nodes();
1314 if (count($children) > 0)
1315 {
1316 for ($i = 0; $i < count($children); $i++)
1317 {
1318 if ($children[$i]->node_name() == $name &&
1319 is_array($newNode))
1320 {
1321 foreach ($newNode as $key => $val)
1322 {
1323 if ($key == "value")
1324 {
1325 $this->replace_content($children[$i], $val);
1326 }
1327 else
1328 {
1329 $children[$i]->set_attribute($key, $val);
1330 }
1331 }
1332 }
1333 }
1334 }
1335 }
1336 }
1337
1348 function replace_content( &$node, &$new_content )
1349 {
1350 $newnode =& $this->dom->create_element( $node->tagname() );
1351 $newnode->set_content( $new_content );
1352 $atts =& $node->attributes();
1353 foreach ( $atts as $att )
1354 {
1355 $newnode->set_attribute( $att->name(), $att->value() );
1356 }
1357 $kids =& $node->child_nodes();
1358 foreach ( $kids as $kid )
1359 {
1360 if ( $kid->node_type() != XML_TEXT_NODE )
1361 {
1362 $newnode->append_child( $kid );
1363 }
1364 }
1365 $node->replace_node( $newnode );
1366 }
1367
1376 function updateDomContent($xPath, $name = "", $index = 0, $newNode)
1377 {
1378// echo "Index: " . $index . " | Path: " . $xPath . " | Name: " . $name . "<br>\n";
1379 $nodes = $this->getXpathNodes($this->dom, $xPath);
1380 if (count($nodes) > 0)
1381 {
1382 $children = $nodes[$index]->child_nodes();
1383 if (count($children) > 0)
1384 {
1385 for ($i = 0; $i < count($children); $i++)
1386 {
1387 if ($children[$i]->node_name() == $name &&
1388 is_array($newNode))
1389 {
1390 foreach ($newNode as $key => $val)
1391 {
1392 if ($key == "value")
1393 {
1394 $children[$i]->set_content($val);
1395 }
1396 else
1397 {
1398 $children[$i]->set_attribute($key, $val);
1399 }
1400 }
1401 }
1402 }
1403 }
1404 }
1405 }
1406
1414 function getFirstDomNode($xPath)
1415 {
1416 $node = $this->getXpathNodes($this->dom,$xPath);
1417 return($node[0]);
1418 }
1419
1424 function updateFromDom()
1425 {
1426 $this->deleteAllDbData();
1427 $xml = $this->dom->dump_mem(0);
1428 $this->import($xml,$this->obj_id,$this->obj_type);
1429
1430 }
1431
1437 {
1438 global $ilBench;
1439
1440 #$ilBench->start('NestedSet','deleteAllDBData');
1441 $res = $this->db->queryF('
1442 SELECT * FROM xmlnestedset WHERE ns_book_fk = %s AND ns_type = %s ',
1443 array('integer','text'), array($this->obj_id,$this->obj_type));
1444
1445 while ($row = $this->db->fetchAssoc($res))
1446 {
1447 $this->db->manipulateF('DELETE FROM xmlparam WHERE tag_fk = %s',array('integer'), array($row["ns_tag_fk"]));
1448 $this->db->manipulateF('DELETE FROM xmlvalue WHERE tag_fk = %s',array('integer'), array($row["ns_tag_fk"]));
1449 $this->db->manipulateF('DELETE FROM xmltags WHERE tag_pk = %s',array('integer'), array($row["ns_tag_fk"]));
1450 }
1451 $this->db->manipulateF('DELETE FROM xmlnestedset WHERE ns_book_fk = %s AND ns_type = %s',
1452 array('integer','text'), array($this->obj_id,$this->obj_type));
1453 #$ilBench->stop('NestedSet','deleteAllDBData');
1454
1455 }
1456
1465 {
1466 global $ilBench,$ilDB;
1467
1468 #$ilBench->start('NestedSet','deleteAllChildMetaData');
1469
1470 // STEP TWO: DELETE ENTRIES IN xmlnestedset GET ALL tag_fks
1471 $in = " IN ('";
1472 $in .= implode("','", $a_ids);
1473 $in .= "')";
1474
1475 $query = "SELECT ns_tag_fk FROM xmlnestedset ".
1476 "WHERE ns_book_fk ".$in;
1477 $res = $ilDB->query($query);
1478 while($row = $ilDB->fetchObject($res))
1479 {
1480 $tag_fks[$row->ns_tag_fk] = $row->ns_tag_fk;
1481 }
1482 $ilDB->manipulate("DELETE FROM xmlnestedset WHERE ns_book_fk ".$in);
1483
1484
1485 // FINALLY DELETE
1486 // BEGIN WebDAV: Object deletion failed if no tag_fks was present.
1487 if ($tag_fks != null)
1488 {
1489 $in = " IN ('";
1490 $in .= implode("','", $tag_fks);
1491 $in .= "')";
1492
1493 $ilDB->manipulate("DELETE FROM xmlparam WHERE tag_fk ".$in);
1494 $ilDB->manipulate("DELETE FROM xmlvalue WHERE tag_fk ".$in);
1495 $ilDB->manipulate("DELETE FROM xmltags WHERE tag_pk ".$in);
1496 }
1497 // END WebDAV Object deletion failed if no tag_fks was present.
1498
1499 #$ilBench->stop('NestedSet','deleteAllChildMetaData');
1500 return true;
1501 }
1502
1509 function _getAllChildIds($a_obj_id)
1510 {
1511 global $ilDB;
1512
1513 $res = $ilDB->queryF('SELECT obj_id FROM lm_data WHERE lm_id = %s',array('integer'),array($a_obj_id));
1514 while($row = $ilDB->fetchObject($res))
1515 {
1516 $ids[$row->obj_id] = $row->obj_id;
1517 }
1518 $ids[$a_obj_id] = $a_obj_id;
1519
1520 return $ids ? $ids : array();
1521 }
1522
1523 // }}}
1524
1525}
1526
1527?>
$result
static isDbError($a_res)
Check error.
Definition: class.ilDB.php:515
Class NestedSetXML functions for storing XML-Data into nested-set-database-strcture.
addDomNode($xPath, $name, $value="", $attributes="", $index=0)
updateDomContent($xPath, $name="", $index=0, $newNode)
replace_content(&$node, &$new_content)
Replace node contents.
replaceDomContent($xPath, $name="", $index=0, $newNode)
$obj_type
The type of the data to those this entry belongs.
updateDomNode($xPath, $meta, $no=0)
getTagValue()
get tag content
$xml_parser
SAX-Parser-Handle.
startElement($parser, $name, $attrs)
Method is called, at an introductory TAG @access private.
$LEFT
Left and right edge tags.
getFirstDomNode($xPath)
first dom-node
endElement($parser, $name)
method called at a closing tag @access private
deleteDomNode($xPath, $name, $index=0)
$db
Datenbank-handle.
getXpathNodes(&$doc, $qry)
get node in dom-structure
$lastTag
last Tag-Name found
addXMLNode($xPath, $xml, $index=0)
ilNestedSetXML()
Constructor initilize netsed-set variables @access public.
getTagName()
find first tag-name
setTagValue($value)
set tag-content
init($obj_id, $obj_type)
initilialize Nested-Set-Structur
setTagName($tagName)
set tag-name
export($obj_id, $type)
Export-Function.
$DEPTH
Nesting level of the tags.
setParameterModifier(&$a_object, $a_method)
getDomContent($xPath, $name="", $index=0)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$data
global $ilBench
Definition: ilias.php:18
domxml_open_mem($str, $mode=DOMXML_LOAD_PARSING, &$error=NULL)
redirection script todo: (a better solution should control the processing via a xml file)
global $ilDB
global $ilUser
Definition: imgupload.php:15