ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilNestedSetXML.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
37 {
38  // {{{ Vars
39 
43  public $db;
44 
48  public $LEFT = 0;
49  public $RIGHT = 0;
50 
55  public $DEPTH = 0;
56 
60  public $obj_id;
61 
65  public $obj_type;
66 
70  public $xml_parser;
71 
75  public $lastTag = "";
76 
82  public $ilias;
83 
89  public $dom;
90 
91  // }}}
92 
98  public function __construct()
99  {
100  global $ilias,$ilDB;
101 
102  $this->ilias =&$ilias;
103 
104  $this->db =&$ilDB;
105  $this->LEFT = 0;
106  $this->RIGHT = 0;
107  $this->DEPTH = 0;
108 
109  $this->param_modifier = "";
110  }
111 
112 
123  public function startElement($parser, $name, $attrs)
124  {
125  // {{{
126  global $ilDB;
127 
128  $this->lastTag = $name;
129  $this->LEFT += 1;
130  $this->RIGHT = $this->LEFT + 1;
131  $this->DEPTH++;
132 
136  $this->db->query("INSERT INTO xmltags ( tag_name,tag_depth ) VALUES (" . $ilDB->quote($name) . "," . $ilDB->quote($this->DEPTH) . ") ");
137  // $pk = mysql_insert_id();
138  $r = $this->db->query("SELECT LAST_INSERT_ID()");
139  $row = $r->fetchRow();
140 
141  $pk = $row[0];
142 
143  $Q = "UPDATE NestedSetTemp SET ns_r=ns_r+2 WHERE ns_r >= " . $ilDB->quote($this->LEFT) . " AND ns_book_fk = " . $ilDB->quote($this->obj_id) . " ";
144  $this->db->query($Q);
145 
146  $Q = "INSERT INTO NestedSetTemp (ns_book_fk,ns_type,ns_tag_fk,ns_l,ns_r) VALUES (" . $ilDB->quote($this->obj_id) . "," . $ilDB->quote($this->obj_type) . "," . $ilDB->quote($pk) . "," . $ilDB->quote($this->LEFT) . "," . $ilDB->quote($this->RIGHT) . ") ";
147  $this->db->query($Q);
148 
149  $this->clean($attrs);
150  if (is_array($attrs) && count($attrs)>0) {
151  reset($attrs);
152  while (list($key, $val) = each($attrs)) {
153  $this->db->query("INSERT INTO xmlparam ( tag_fk,param_name,param_value ) VALUES (" . $ilDB->quote($pk) . "," . $ilDB->quote($key) . "," . $ilDB->quote($val) . ") ");
154  }
155  }
156 
157  return($pk);
158  // }}}
159  }
160 
169  public function characterData($parser, $data)
170  {
171  // {{{
172  global $ilDB;
173 
179  static $value_pk;
180 
181  // we don't need this trim since expression like ' ABC < > ' will be parsed to ' ABC <>'
182  if (1 or trim($data)!="") {
183  if ($this->lastTag == "TAGVALUE") {
184  $Q = "UPDATE xmlvalue SET tag_value = concat(tag_value," . $ilDB->quote($data) . ") WHERE tag_value_pk = " . $ilDB->quote($value_pk) . " ";
185  $this->db->query($Q);
186  } else {
187  $tag_pk = $this->startElement($this->xml_parser, "TAGVALUE", array());
188  $this->endElement($this->xml_parser, "TAGVALUE");
189 
190  $Q = "INSERT INTO xmlvalue (tag_fk,tag_value) VALUES (" . $ilDB->quote($tag_pk) . "," . $ilDB->quote($data) . ") ";
191  $this->db->query($Q);
192 
193  $Q = "SELECT LAST_INSERT_ID()";
194  $r = $this->db->query($Q);
195  $row = $r->fetchRow();
196  $value_pk = $row[0];
197 
198  $this->lastTag = "TAGVALUE";
199  }
200  }
201  // }}}
202  }
203 
211  public function endElement($parser, $name)
212  {
213  // {{{
214  $this->DEPTH--;
215  $this->LEFT += 1;
216  $this->lastTag = "";
217  // }}}
218  }
219 
228  public function import($xmldata, $obj_id, $obj_type)
229  {
230  // {{{
234  $this->db->query("DROP TABLE IF EXISTS NestedSetTemp");
235 
239  $Q = "CREATE TEMPORARY TABLE NestedSetTemp (
240  ns_book_fk int(11) NOT NULL,
241  ns_type char(50) NOT NULL,
242  ns_tag_fk int(11) NOT NULL,
243  ns_l int(11) NOT NULL,
244  ns_r int(11) NOT NULL,
245  KEY ns_tag_fk (ns_tag_fk),
246  KEY ns_l (ns_l),
247  KEY ns_r (ns_r),
248  KEY ns_book_fk (ns_book_fk)
249  ) TYPE=MyISAM ";
250  $this->db->query($Q);
251 
252  $this->obj_id = $obj_id;
253  $this->obj_type = $obj_type;
254  $this->DEPTH = 0;
255  $this->LEFT = 0;
256  $this->RIGHT = 0;
257 
258  $this->db->query("DELETE FROM NestedSetTemp");
259 
264  $this->xml_parser = xml_parser_create("UTF-8");
265  xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false);
266  xml_set_object($this->xml_parser, $this);
267  xml_set_element_handler($this->xml_parser, "startElement", "endElement");
268  xml_set_character_data_handler($this->xml_parser, "characterData");
269 
270  if (!xml_parse($this->xml_parser, $xmldata)) {
271  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)));
272  }
273  xml_parser_free($this->xml_parser);
274 
278  $this->deleteAllDbData();
279 
280  $this->db->query("INSERT INTO xmlnestedset SELECT * FROM NestedSetTemp");
281  $this->db->query("DROP TABLE IF EXISTS NestedSetTemp");
282  // }}}
283  }
284 
290  public function setParameterModifier(&$a_object, $a_method)
291  {
292  $this->param_modifier =&$a_object;
293  $this->param_modifier_method = $a_method;
294  }
295 
307  public function export($obj_id, $type)
308  {
309  // {{{
310  global $ilDB;
311 
312  $query = "SELECT * FROM xmlnestedset,xmltags WHERE ns_tag_fk = tag_pk AND ns_book_fk = " . $ilDB->quote($obj_id) . " AND ns_type = " . $ilDB->quote($type) . " ORDER BY ns_l";
313  $result = $this->db->query($query);
314  if (DB::isError($result)) {
315  die($this->className . "::checkTable(): " . $result->getMessage() . ":<br>" . $query);
316  }
317 
318  $xml = "";
319  $lastDepth = -1;
320 
321  while (is_array($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC))) {
322 
323  // {{{ tags
324  $Anfang = "<" . $row[tag_name];
325  $query = "SELECT * FROM xmlparam WHERE tag_fk = " . $ilDB->quote($row[tag_pk]) . " ";
326  $result_param = $this->db->query($query);
327  while (is_array($row_param = $result_param->fetchRow(ilDBConstants::FETCHMODE_ASSOC))) {
328  $param_value = $row_param[param_value];
329  if (is_object($this->param_modifier)) {
330  $obj =&$this->param_modifier;
331  $method = $this->param_modifier_method;
332  $param_value = $obj->$method($row[tag_name], $row_param[param_name], $param_value);
333  }
334  $Anfang .= " " . $row_param[param_name] . "=\"" . $param_value . "\"";
335  }
336 
337  $Anfang .= ">";
338  $Ende = "</" . $row[tag_name] . ">";
339  // }}}
340 
341  // {{{ TagValue
342  if ($row[tag_name]=="TAGVALUE") {
343  $query = "SELECT * FROM xmlvalue WHERE tag_fk = " . $ilDB->quote($row[tag_pk]) . " ";
344  $result_value = $this->db->query($query);
345  $row_value = $result_value->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
346  $Anfang = $row_value["tag_value"];
347  $Ende = "";
348 
349  $Anfang = htmlspecialchars($Anfang);
350  // $Anfang = utf8_encode($Anfang);
351  }
352  // }}}
353 
354  $D = $row[tag_depth];
355 
356  if ($D==$lastDepth) {
357  $xml .= $xmlE[$D];
358  $xml .= $Anfang;
359  $xmlE[$D] = $Ende;
360  } elseif ($D>$lastDepth) {
361  $xml .= $Anfang;
362  $xmlE[$D] = $Ende;
363  } else {
364  for ($i=$lastDepth;$i>=$D;$i--) {
365  $xml .= $xmlE[$i];
366  }
367  $xml .= $Anfang;
368  $xmlE[$D] = $Ende;
369  }
370 
371  $lastDepth = $D;
372  }
373 
374  for ($i=$lastDepth;$i>0;$i--) {
375  $xml .= $xmlE[$i];
376  }
377 
378  return($xml);
379  // }}}
380  }
381 
389  public function init($obj_id, $obj_type)
390  {
391  global $ilDB;
392 
393  // {{{
394  $this->db->setLimit(1);
395  $query = "SELECT * FROM xmlnestedset,xmltags WHERE ns_book_fk = " . $ilDB->quote($obj_id) . " AND ns_type =" .
396  $ilDB->quote($obj_type) . " AND ns_tag_fk=tag_pk ORDER BY ns_l";
397  $result = $this->db->query($query);
399 
400  $this->LEFT = $row["ns_l"];
401  $this->RIGHT = $row["ns_r"];
402  $this->DEPTH = $row["tag_depth"];
403  $this->obj_id = $obj_id;
404  $this->obj_type = $obj_type;
405  // }}}
406  }
407 
415  public function getTagName()
416  {
417  global $ilDB;
418 
419  $this->db->setLimit(1);
420  $query = "SELECT * FROM xmlnestedset,xmltags WHERE ns_book_fk = " . $ilDB->quote($this->obj_id) . " AND ns_type = " . $ilDB->quote($this->obj_type) . " AND ns_l = " . $ilDB->quote($this->LEFT) . " AND ns_r = " . $ilDB->quote($this->RIGHT) . " AND ns_tag_fk = tag_pk";
421  $result = $this->db->query($query);
423 
424  return($row["tag_name"]);
425  }
426 
436  public function setTagName($tagName)
437  {
438  global $ilDB;
439 
440  $this->db->setLimit(1);
441  $query = "SELECT * FROM xmlnestedset WHERE ns_book_fk = " . $ilDB->quote($this->obj_id) . " AND ns_type = " . $ilDB->quote($this->obj_type) . " AND ns_l = " . $ilDB->quote($this->LEFT) . " AND ns_r = " . $ilDB->quote($this->RIGHT);
442  $result = $this->db->query($query);
444 
445  $query = "UPDATE xmltags SET tag_name= " . $ilDB->quote($tagName) . " WHERE tag_pk = " . $ilDB->quote($row["ns_tag_fk"]);
446  $this->db->query($query);
447 
448  return($row["tagName"]);
449  }
450 
451 
458  public function getTagValue()
459  {
460  global $ilDB;
461 
462  $V = array();
463 
464  $query = "SELECT * FROM xmlnestedset,xmltags WHERE ns_tag_fk = tag_pk AND ns_book_fk = " . $ilDB->quote($this->obj_id) . " AND ns_type = " . $ilDB->quote($this->obj_type) . " AND ns_l >= " . $ilDB->quote($this->LEFT) . " AND ns_r <= " . $ilDB->quote($this->RIGHT) . " AND tag_depth = " . $ilDB->quote(($this->DEPTH+1)) . " ORDER BY ns_l";
465  $result = $this->db->query($query);
466  while (is_array($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC))) {
467  if ($row[tag_name]=="TAGVALUE") {
468  $query = "SELECT * FROM xmlvalue WHERE tag_fk = " . $ilDB->quote($row[tag_pk]) . " ";
469  $result2 = $this->db->query($query);
470  $row2 = $result2->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
471  $V[] = $row2[tag_value];
472  } else {
473  $xml = new ilNestedSetXml();
474 
475  $xml->LEFT = $row["ns_l"];
476  $xml->RIGHT = $row["ns_r"];
477  $xml->DEPTH = $row["tag_depth"];
478  $xml->obj_id = $obj_id;
479  $xml->obj_type = $obj_type;
480 
481  $V[] = $xml;
482  }
483  }
484 
485  return($V);
486  }
487 
494  public function setTagValue($value)
495  {
496  global $ilDB;
497 
498  $V = array();
499 
500  $query = "SELECT * FROM xmlnestedset,xmltags
501  LEFT JOIN xmlvalue ON xmltags.tag_pk=xmlvalue.tag_fk
502  WHERE ns_tag_fk = tag_pk AND
503  ns_book_fk = " . $ilDB->quote($this->obj_id) . " AND
504  ns_type = " . $ilDB->quote($this->obj_type) . " AND
505  ns_l >= " . $ilDB->quote($this->LEFT) . " AND
506  ns_r <= " . $ilDB->quote($this->RIGHT) . " AND
507  tag_depth = " . $ilDB->quote(($this->DEPTH+1)) . " AND
508  tag_name = 'TAGVALUE'
509  ORDER BY ns_l";
510  $result = $this->db->query($query);
511 
512  if (is_array($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC))) {
513  $query = "UPDATE xmlvalue SET tag_value = " . $ilDB->quote($value) . " WHERE tag_value_pk = " . $ilDB->quote($row["tag_value_pk"]) . " ";
514  $this->db->query($query);
515  } else {
516 
520  }
521  }
522 
532  public function getXpathNodes(&$doc, $qry)
533  {
534  if (is_object($doc)) {
535  $xpath = $doc->xpath_init();
536  $ctx = $doc->xpath_new_context();
537  //echo "<br><b>ilNestedSetXML::getXpathNodes</b>";
538  $result = $ctx->xpath_eval($qry);
539  if (is_array($result->nodeset)) {
540  return($result->nodeset);
541  }
542  }
543  return null;
544  }
545 
552  public function initDom()
553  {
554  $xml = $this->export($this->obj_id, $this->obj_type);
555 
556  /*
557  for testing
558  $xml_test = '
559  <MetaData>
560  <General Structure="Atomic">
561  <Identifier Catalog="ILIAS" Entry="34">Identifier 34 in ILIAS</Identifier>
562  <Identifier Catalog="ILIAS" Entry="45">Identifier 45 in ILIAS</Identifier>
563  <Identifier Catalog="ILIAS" Entry="67">Identifier 67 in ILIAS</Identifier>
564  </General>
565  </MetaData>
566  ';
567 
568  $xml = $xml_test;
569  */
570 
571  if ($xml=="") {
572  return(false);
573  } else {
574  $this->dom = domxml_open_mem($xml);
575  return(true);
576  }
577  }
578 
589  public function addXMLNode($xPath, $xml, $index = 0)
590  {
591  include_once "./Services/Xml/classes/class.ilXML2DOM.php";
592 
593  $newDOM = new XML2DOM($xml);
594  //echo "<br>addXMLNode:-".htmlspecialchars($this->dom->dump_mem(0));
595  $nodes = $this->getXpathNodes($this->dom, $xPath);
596 
597  if (count($nodes) > 0) {
598  $newDOM->insertNode($this->dom, $nodes[$index]);
599  return true;
600  } else {
601  return false;
602  }
603  }
604 
613  public function getFirstDomContent($xPath)
614  {
615  //echo "<br>ilNestedSetXML::getFirstDomContent-start-$xPath-"; flush();
616  $content = "";
617  if (is_object($this->dom)) {
618  $node = $this->getXpathNodes($this->dom, $xPath);
619  if (is_array($node)) {
620  $c = $node[0]->children();
621  //$content = $c[0]->content; // ## changed
622  if (is_object($c[0])) {
623  $content = $c[0]->get_content(); // ## changed
624  }
625  }
626  }
627  //echo "<br>ilNestedSetXML::getFirstDomContent-stop-$content-"; flush();
628  return($content);
629  }
630 
641  public function deleteDomNode($xPath, $name, $index = 0)
642  {
643  if ($index == "") {
644  $index = 0;
645  }
646  if (strpos($index, ",")) {
647  $indices = explode(",", $index);
648  $nodes = $this->getXpathNodes($this->dom, $xPath);
649  if (count($nodes) > 0) {
650  $children = $nodes[$indices[0]]->child_nodes();
651  if (count($children) > 0) {
652  $j = 0;
653  for ($i = 0; $i < count($children); $i++) {
654  if ($children[$i]->node_name() == $name) {
655  if ($j == $indices[1]) {
656  $children[$i]->unlink_node();
657  return true;
658  }
659  $j++;
660  }
661  }
662  }
663  }
664  } else {
665  $nodes = $this->getXpathNodes($this->dom, $xPath . "/" . $name);
666  if (count($nodes) > 0) {
667  $nodes[$index]->unlink_node();
668  return true;
669  }
670  }
671  return false;
672  }
673 
686  public function addDomNode($xPath, $name, $value = "", $attributes = "", $index = 0)
687  {
688  $nodes = $this->getXpathNodes($this->dom, $xPath);
689  if (count($nodes) > 0) {
690  $node = $this->dom->create_element($name);
691  if ($value != "") {
692  $node->set_content(utf8_encode($value));
693  }
694  if (is_array($attributes)) {
695  for ($i = 0; $i < count($attributes); $i++) {
696  $node->set_attribute($attributes[$i]["name"], utf8_encode($attributes[$i]["value"]));
697  }
698  }
699  $nodes[$index]->append_child($node);
700  return true;
701  } else {
702  return false;
703  }
704  }
705 
706  public function clean(&$meta)
707  {
708  if (is_array($meta)) {
709  foreach ($meta as $key => $value) {
710  if (is_array($meta[$key])) {
711  $this->clean($meta[$key]);
712  } else {
713  $meta[$key] = preg_replace("/&(?!amp;|lt;|gt;|quot;)/", "&amp;", $meta[$key]);
714  $meta[$key] = preg_replace("/\"/", "&quot;", $meta[$key]);
715  $meta[$key] = preg_replace("/</", "&lt;", $meta[$key]);
716  $meta[$key] = preg_replace("/>/", "&gt;", $meta[$key]);
717  }
718  }
719  }
720  return true;
721  }
730  public function updateDomNode($xPath, $meta, $no = 0)
731  {
732  $this->clean($meta);
733  $update = false;
734  if ($xPath == "//Bibliography") {
735  $nodes = $this->getXpathNodes($this->dom, $xPath . "/BibItem[" . ($no+1) . "]");
736  } else {
737  $nodes = $this->getXpathNodes($this->dom, $xPath);
738  }
739  if (count($nodes) > 0) {
740 
741  /* BibItem */
742  if ($nodes[0]->node_name() == "BibItem") {
743  $xml = '<BibItem Type="' . ilUtil::stripSlashes($meta["Type"]) . '" Label="' . ilUtil::stripSlashes($meta["Label"]["Value"]) . '">';
744  $xml .= '<Identifier Catalog="' . ilUtil::stripSlashes($meta["Identifier"]["Catalog"]) . '" Entry="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Identifier"]["Entry"])) . '"/>';
745  for ($i = 0; $i < count($meta["Language"]); $i++) {
746  $xml .= '<Language Language="' . ilUtil::stripSlashes($meta["Language"][$i]["Language"]) . '"/>';
747  }
748  for ($i = 0; $i < count($meta["Author"]); $i++) {
749  $xml .= '<Author>';
750  # for ($j = 0; $j < count($meta["Author"][$i]["FirstName"]); $j++)
751  # {
752  $xml .= '<FirstName>' . ilUtil::stripSlashes($meta["Author"][$i]["FirstName"]) . '</FirstName>';
753  # }
754  # for ($j = 0; $j < count($meta["Author"][$i]["MiddleName"]); $j++)
755  # {
756  $xml .= '<MiddleName>' . ilUtil::stripSlashes($meta["Author"][$i]["MiddleName"]) . '</MiddleName>';
757  # }
758  # for ($j = 0; $j < count($meta["Author"][$i]["LastName"]); $j++)
759  # {
760  $xml .= '<LastName>' . ilUtil::stripSlashes($meta["Author"][$i]["LastName"]) . '</LastName>';
761  # }
762  $xml .= '</Author>';
763  }
764  $xml .= '<Booktitle Language="' . ilUtil::stripSlashes($meta["Booktitle"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Booktitle"]["Value"]) . '</Booktitle>';
765  for ($i = 0; $i < count($meta["CrossRef"]); $i++) {
766  $xml .= '<CrossRef>' . ilUtil::stripSlashes($meta["CrossRef"][$i]["Value"]) . '</CrossRef>';
767  }
768  $xml .= '<Edition>' . ilUtil::stripSlashes($meta["Edition"]["Value"]) . '</Edition>';
769  for ($i = 0; $i < count($meta["Editor"]); $i++) {
770  $xml .= '<Editor>' . ilUtil::stripSlashes($meta["Editor"][$i]["Value"]) . '</Editor>';
771  }
772  $xml .= '<HowPublished Type="' . ilUtil::stripSlashes($meta["HowPublished"]["Type"]) . '"/>';
773  for ($i = 0; $i < count($meta["WherePublished"]); $i++) {
774  $xml .= '<WherePublished>' . ilUtil::stripSlashes($meta["WherePublished"][$i]["Value"]) . '</WherePublished>';
775  }
776  for ($i = 0; $i < count($meta["Institution"]); $i++) {
777  $xml .= '<Institution>' . ilUtil::stripSlashes($meta["Institution"][$i]["Value"]) . '</Institution>';
778  }
779  if (is_array($meta["Journal"])) {
780  $xml .= '<Journal Note="' . ilUtil::stripSlashes($meta["Journal"]["Note"]) . '" Number="' . ilUtil::stripSlashes($meta["Journal"]["Number"]) . '" Organization="' . ilUtil::stripSlashes($meta["Journal"]["Organization"]) . '"/>';
781  }
782  for ($i = 0; $i < count($meta["Keyword"]); $i++) {
783  $xml .= '<Keyword Language="' . ilUtil::stripSlashes($meta["Keyword"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Keyword"][$i]["Value"]) . '</Keyword>';
784  }
785  if (is_array($meta["Month"])) {
786  $xml .= '<Month>' . ilUtil::stripSlashes($meta["Month"]["Value"]) . '</Month>';
787  }
788  if (is_array($meta["Pages"])) {
789  $xml .= '<Pages>' . ilUtil::stripSlashes($meta["Pages"]["Value"]) . '</Pages>';
790  }
791  $xml .= '<Publisher>' . ilUtil::stripSlashes($meta["Publisher"]["Value"]) . '</Publisher>';
792  for ($i = 0; $i < count($meta["School"]); $i++) {
793  $xml .= '<School>' . ilUtil::stripSlashes($meta["School"][$i]["Value"]) . '</School>';
794  }
795  if (is_array($meta["Series"])) {
796  $xml .= '<Series>';
797  $xml .= '<SeriesTitle>' . ilUtil::stripSlashes($meta["Series"]["SeriesTitle"]) . '</SeriesTitle>';
798  # for ($i = 0; $i < count($meta["Series"]["SeriesEditor"]); $i++)
799  if (isset($meta["Series"]["SeriesEditor"])) {
800  # $xml .= '<SeriesEditor>' . ilUtil::stripSlashes($meta["Series"]["SeriesEditor"][$i]) . '</SeriesEditor>';
801  $xml .= '<SeriesEditor>' . ilUtil::stripSlashes($meta["Series"]["SeriesEditor"]) . '</SeriesEditor>';
802  }
803  if (isset($meta["Series"]["SeriesVolume"])) {
804  $xml .= '<SeriesVolume>' . ilUtil::stripSlashes($meta["Series"]["SeriesVolume"]) . '</SeriesVolume>';
805  }
806  $xml .= '</Series>';
807  }
808  $xml .= '<Year>' . ilUtil::stripSlashes($meta["Year"]["Value"]) . '</Year>';
809  if ($meta["URL_ISBN_ISSN"]["Type"] == "URL") {
810  $xml .= '<URL>' . ilUtil::stripSlashes($meta["URL_ISBN_ISSN"]["Value"]) . '</URL>';
811  } elseif ($meta["URL_ISBN_ISSN"]["Type"] == "ISBN") {
812  $xml .= '<ISBN>' . ilUtil::stripSlashes($meta["URL_ISBN_ISSN"]["Value"]) . '</ISBN>';
813  } elseif ($meta["URL_ISBN_ISSN"]["Type"] == "ISSN") {
814  $xml .= '<ISSN>' . ilUtil::stripSlashes($meta["URL_ISBN_ISSN"]["Value"]) . '</ISSN>';
815  }
816  $xml .= '</BibItem>';
817  # echo htmlspecialchars($xml);
818 
819  $update = true;
820  }
821 
822  /* General */
823  elseif ($nodes[0]->node_name() == "General") {
824  $xml = '<General Structure="' . ilUtil::stripSlashes($meta["Structure"]) . '">';
825  for ($i = 0; $i < count($meta["Identifier"]); $i++) {
826  $xml .= '<Identifier Catalog="' . ilUtil::stripSlashes($meta["Identifier"][$i]["Catalog"]) . '" Entry="' .
827  str_replace("\"", "", ilUtil::stripSlashes($meta["Identifier"][$i]["Entry"])) . '"/>';
828  }
829 
830  $xml .= '<Title Language="' .
831  ilUtil::stripSlashes($meta["Title"]["Language"]) . '">' .
832  ilUtil::stripSlashes($meta["Title"]["Value"]) . '</Title>';
833  for ($i = 0; $i < count($meta["Language"]); $i++) {
834  $xml .= '<Language Language="' . ilUtil::stripSlashes($meta["Language"][$i]["Language"]) . '"/>';
835  }
836  for ($i = 0; $i < count($meta["Description"]); $i++) {
837  $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Description"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Description"][$i]["Value"]) . '</Description>';
838  }
839  for ($i = 0; $i < count($meta["Keyword"]); $i++) {
840  $xml .= '<Keyword Language="' . ilUtil::stripSlashes($meta["Keyword"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Keyword"][$i]["Value"]) . '</Keyword>';
841  }
842  if ($meta["Coverage"] != "") {
843  $xml .= '<Coverage Language="' . ilUtil::stripSlashes($meta["Coverage"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Coverage"]["Value"]) . '</Coverage>';
844  }
845  $xml .= '</General>';
846  //echo "<br><br>".htmlspecialchars($xml);
847 
848  $update = true;
849  }
850 
851  /* Lifecycle */
852  elseif ($nodes[0]->node_name() == "Lifecycle") {
853  $xml = '<Lifecycle Status="' . $meta["Status"] . '">';
854  $xml .= '<Version Language="' . ilUtil::stripSlashes($meta["Version"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Version"]["Value"]) . '</Version>';
855  for ($i = 0; $i < count($meta["Contribute"]); $i++) {
856  $xml .= '<Contribute Role="' . ilUtil::stripSlashes($meta["Contribute"][$i]["Role"]) . '">';
857  $xml .= '<Date>' . ilUtil::stripSlashes($meta["Contribute"][$i]["Date"]) . '</Date>';
858  for ($j = 0; $j < count($meta["Contribute"][$i]["Entity"]); $j++) {
859  $xml .= '<Entity>' . ilUtil::stripSlashes($meta["Contribute"][$i]["Entity"][$j]) . '</Entity>';
860  }
861  $xml .= '</Contribute>';
862  }
863  $xml .= '</Lifecycle>';
864  # echo htmlspecialchars($xml);
865 
866  $update = true;
867  }
868 
869  /* Meta-Metadata */
870  elseif ($nodes[0]->node_name() == "Meta-Metadata") {
871  $xml = '<Meta-Metadata MetadataScheme="LOM v 1.0" Language="' . ilUtil::stripSlashes($meta["Language"]) . '">';
872  for ($i = 0; $i < count($meta["Identifier"]); $i++) {
873  $xml .= '<Identifier Catalog="' . ilUtil::stripSlashes($meta["Identifier"][$i]["Catalog"]) . '" Entry="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Identifier"][$i]["Entry"])) . '"/>';
874  }
875  for ($i = 0; $i < count($meta["Contribute"]); $i++) {
876  $xml .= '<Contribute Role="' . ilUtil::stripSlashes($meta["Contribute"][$i]["Role"]) . '">';
877  $xml .= '<Date>' . ilUtil::stripSlashes($meta["Contribute"][$i]["Date"]) . '</Date>';
878  for ($j = 0; $j < count($meta["Contribute"][$i]["Entity"]); $j++) {
879  $xml .= '<Entity>' . ilUtil::stripSlashes($meta["Contribute"][$i]["Entity"][$j]) . '</Entity>';
880  }
881  $xml .= '</Contribute>';
882  }
883  $xml .= '</Meta-Metadata>';
884  # echo htmlspecialchars($xml);
885 
886  $update = true;
887  }
888 
889  /* Technical */
890  elseif ($nodes[0]->node_name() == "Technical") {
891  $xml = '<Technical>';
892  for ($i = 0; $i < count($meta["Format"]); $i++) {
893  $xml .= '<Format>' . ilUtil::stripSlashes($meta["Format"][$i]) . '</Format>';
894  }
895  if ($meta["Size"] != "") {
896  $xml .= '<Size>' . ilUtil::stripSlashes($meta["Size"]) . '</Size>';
897  }
898  for ($i = 0; $i < count($meta["Location"]); $i++) {
899  $xml .= '<Location Type="' . ilUtil::stripSlashes($meta["Location"][$i]["Type"]) . '">' . ilUtil::stripSlashes($meta["Location"][$i]["Value"]) . '</Location>';
900  }
901  if (is_array($meta["Requirement"])) {
902  for ($i = 0; $i < count($meta["Requirement"]); $i++) {
903  $xml .= '<Requirement>';
904  $xml .= '<Type>';
905  if (is_array($meta["Requirement"][$i]["Type"]["OperatingSystem"])) {
906  $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"])) . '"/>';
907  }
908  if (is_array($meta["Requirement"][$i]["Type"]["Browser"])) {
909  $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"])) . '"/>';
910  }
911  $xml .= '</Type>';
912  $xml .= '</Requirement>';
913  }
914  } elseif (is_array($meta["OrComposite"])) {
915  for ($j = 0; $j < count($meta["OrComposite"]); $j++) {
916  $xml .= '<OrComposite>';
917  for ($i = 0; $i < count($meta["OrComposite"][$j]["Requirement"]); $i++) {
918  $xml .= '<Requirement>';
919  $xml .= '<Type>';
920  if (is_array($meta["OrComposite"][$j]["Requirement"][$i]["Type"]["OperatingSystem"])) {
921  $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"])) . '"/>';
922  }
923  if (is_array($meta["OrComposite"][$j]["Requirement"][$i]["Type"]["Browser"])) {
924  $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"])) . '"/>';
925  }
926  $xml .= '</Type>';
927  $xml .= '</Requirement>';
928  }
929  $xml .= '</OrComposite>';
930  }
931  }
932  if (is_array($meta["InstallationRemarks"])) {
933  $xml .= '<InstallationRemarks Language="' . ilUtil::stripSlashes($meta["InstallationRemarks"]["Language"]) . '">' . ilUtil::stripSlashes($meta["InstallationRemarks"]["Value"]) . '</InstallationRemarks>';
934  }
935  if (is_array($meta["OtherPlattformRequirements"])) {
936  $xml .= '<OtherPlattformRequirements Language="' . ilUtil::stripSlashes($meta["OtherPlattformRequirements"]["Language"]) . '">' . ilUtil::stripSlashes($meta["OtherPlattformRequirements"]["Value"]) . '</OtherPlattformRequirements>';
937  }
938  if ($meta["Duration"] != "") {
939  $xml .= '<Duration>' . ilUtil::stripSlashes($meta["Duration"]) . '</Duration>';
940  }
941  $xml .= '</Technical>';
942  # echo htmlspecialchars($xml);
943 
944  $update = true;
945  }
946 
947  /* Educational */
948  elseif ($nodes[0]->node_name() == "Educational") {
949  $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"]) . '">';
950  $xml .= '<TypicalLearningTime>' . ilUtil::stripSlashes($meta["TypicalLearningTime"]) . '</TypicalLearningTime>';
951  for ($i = 0; $i < count($meta["TypicalAgeRange"]); $i++) {
952  $xml .= '<TypicalAgeRange Language="' . ilUtil::stripSlashes($meta["TypicalAgeRange"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["TypicalAgeRange"][$i]["Value"]) . '</TypicalAgeRange>';
953  }
954  for ($i = 0; $i < count($meta["Description"]); $i++) {
955  $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Description"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Description"][$i]["Value"]) . '</Description>';
956  }
957  for ($i = 0; $i < count($meta["Language"]); $i++) {
958  $xml .= '<Language Language="' . ilUtil::stripSlashes($meta["Language"][$i]["Language"]) . '"/>';
959  }
960  $xml .= '</Educational>';
961 
962  $update = true;
963  }
964 
965  /* Rights */
966  elseif ($nodes[0]->node_name() == "Rights") {
967  $xml = '<Rights Cost="' . ilUtil::stripSlashes($meta["Cost"]) . '" CopyrightAndOtherRestrictions="' . ilUtil::stripSlashes($meta["CopyrightAndOtherRestrictions"]) . '">';
968  for ($i = 0; $i < count($meta["Description"]); $i++) {
969  $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Description"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Description"][$i]["Value"]) . '</Description>';
970  }
971  $xml .= '</Rights>';
972 
973  $update = true;
974  }
975 
976  /* Relation */
977  elseif ($nodes[0]->node_name() == "Relation") {
978 
979 # for ($j = 0; $j < count($meta["Relation"]); $j++)
980  # {
981  $meta["Relation"][0] = $meta;
982  $j = 0;
983  $xml = '<Relation Kind="' . ilUtil::stripSlashes($meta["Relation"][$j]["Kind"]) . '">';
984  $xml .= '<Resource>';
985  for ($i = 0; $i < count($meta["Relation"][$j]["Resource"]["Identifier"]); $i++) {
986  $xml .= '<Identifier_ Catalog="' . ilUtil::stripSlashes($meta["Relation"][$j]["Resource"]["Identifier"][$i]["Catalog"]) . '" Entry="' . str_replace("\"", "", ilUtil::stripSlashes($meta["Relation"][$j]["Resource"]["Identifier"][$i]["Entry"])) . '"/>';
987  }
988  for ($i = 0; $i < count($meta["Relation"][$j]["Resource"]["Description"]); $i++) {
989  $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Relation"][$j]["Resource"]["Description"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Relation"][$j]["Resource"]["Description"][$i]["Value"]) . '</Description>';
990  }
991  $xml .= '</Resource>';
992  $xml .= '</Relation>';
993  # echo htmlspecialchars($xml);
994  # }
995 
996  $update = true;
997  }
998 
999  /* Annotation */
1000  elseif ($nodes[0]->node_name() == "Annotation") {
1001 
1002 # for ($i = 0; $i < count($meta["Annotation"]); $i++)
1003  # {
1004  $meta["Annotation"][0] = $meta;
1005  $i = 0;
1006  $xml = '<Annotation>';
1007  $xml .= '<Entity>' . ilUtil::stripSlashes($meta["Annotation"][$i]["Entity"]) . '</Entity>';
1008  $xml .= '<Date>' . ilUtil::stripSlashes($meta["Annotation"][$i]["Date"]) . '</Date>';
1009  $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Annotation"][$i]["Description"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Annotation"][$i]["Description"]["Value"]) . '</Description>';
1010  $xml .= '</Annotation>';
1011  # echo htmlspecialchars($xml);
1012  # }
1013 
1014  $update = true;
1015  }
1016 
1017  /* Classification */
1018  elseif ($nodes[0]->node_name() == "Classification") {
1019 
1020 # for ($j = 0; $j < count($meta["Classification"]); $j++)
1021  # {
1022  $meta["Classification"][0] = $meta;
1023  $j = 0;
1024  $xml = '<Classification Purpose="' . ilUtil::stripSlashes($meta["Classification"][$j]["Purpose"]) . '">';
1025  for ($k = 0; $k < count($meta["Classification"][$j]["TaxonPath"]); $k++) {
1026  $xml .= '<TaxonPath>';
1027  $xml .= '<Source Language="' . ilUtil::stripSlashes($meta["Classification"][$j]["TaxonPath"][$k]["Source"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Classification"][$j]["TaxonPath"][$k]["Source"]["Value"]) . '</Source>';
1028  for ($i = 0; $i < count($meta["Classification"][$j]["TaxonPath"][$k]["Taxon"]); $i++) {
1029  $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>';
1030  }
1031  $xml .= '</TaxonPath>';
1032  }
1033  $xml .= '<Description Language="' . ilUtil::stripSlashes($meta["Classification"][$j]["Description"]["Language"]) . '">' . ilUtil::stripSlashes($meta["Classification"][$j]["Description"]["Value"]) . '</Description>';
1034  for ($i = 0; $i < count($meta["Classification"][$j]["Keyword"]); $i++) {
1035  $xml .= '<Keyword Language="' . ilUtil::stripSlashes($meta["Classification"][$j]["Keyword"][$i]["Language"]) . '">' . ilUtil::stripSlashes($meta["Classification"][$j]["Keyword"][$i]["Value"]) . '</Keyword>';
1036  }
1037  $xml .= '</Classification>';
1038  # echo htmlspecialchars($xml);
1039  # }
1040 
1041  $update = true;
1042  }
1043 
1044  if ($update) {
1045  $nodes[0]->unlink_node();
1046 
1047  if ($xPath != "//Bibliography") {
1048  $xPath = "//MetaData";
1049  }
1050  //echo "<br><br>savedA:".htmlspecialchars($this->dom->dump_mem(0));
1051  $this->addXMLNode($xPath, $xml);
1052  //echo "<br><br>savedB:".htmlspecialchars($this->dom->dump_mem(0));
1053  }
1054  return true;
1055  } else {
1056  return false;
1057  }
1058  }
1059 
1070  public function getDomContent($xPath, $name = "", $index = 0)
1071  {
1072  if ($index == "") {
1073  $index = 0;
1074  }
1075  # echo "Index: " . $index . " | Path: " . $xPath . " | Name: " . $name . "<br>\n";
1076  $nodes = $this->getXpathNodes($this->dom, $xPath);
1077  if (count($nodes) > 0) {
1078  $children = $nodes[$index]->child_nodes();
1079  if (count($children) > 0) {
1080  $k = 0;
1081  for ($i = 0; $i < count($children); $i++) {
1082  //echo "<br>ilNestedSetXML::getDomContent-".$children[$i]->node_name()."-".$name;
1083  if ($name == "" ||
1084  $children[$i]->node_name() == $name) {
1085  $content[$k]["value"] = $children[$i]->get_content();
1086  $a = $children[$i]->attributes();
1087  for ($j = 0; $j < count($a); $j++) {
1088  $content[$k][$a[$j]->name()] = $a[$j]->value();
1089  }
1090  $k++;
1091  }
1092  }
1093  # vd($content);
1094  return($content);
1095  }
1096  }
1097  return false;
1098  }
1099 
1108  public function replaceDomContent($xPath, $name = "", $index = 0, $newNode)
1109  {
1110  # echo "Index: " . $index . " | Path: " . $xPath . " | Name: " . $name . "<br>\n";
1111  $nodes = $this->getXpathNodes($this->dom, $xPath);
1112  if (count($nodes) > 0) {
1113  $children = $nodes[$index]->child_nodes();
1114  if (count($children) > 0) {
1115  for ($i = 0; $i < count($children); $i++) {
1116  if ($children[$i]->node_name() == $name &&
1117  is_array($newNode)) {
1118  foreach ($newNode as $key => $val) {
1119  if ($key == "value") {
1120  $this->replace_content($children[$i], $val);
1121  } else {
1122  $children[$i]->set_attribute($key, $val);
1123  }
1124  }
1125  }
1126  }
1127  }
1128  }
1129  }
1130 
1141  public function replace_content(&$node, &$new_content)
1142  {
1143  $newnode =&$this->dom->create_element($node->tagname());
1144  $newnode->set_content($new_content);
1145  $atts =&$node->attributes();
1146  foreach ($atts as $att) {
1147  $newnode->set_attribute($att->name(), $att->value());
1148  }
1149  $kids =&$node->child_nodes();
1150  foreach ($kids as $kid) {
1151  if ($kid->node_type() != XML_TEXT_NODE) {
1152  $newnode->append_child($kid);
1153  }
1154  }
1155  $node->replace_node($newnode);
1156  }
1157 
1166  public function updateDomContent($xPath, $name = "", $index = 0, $newNode)
1167  {
1168  // echo "Index: " . $index . " | Path: " . $xPath . " | Name: " . $name . "<br>\n";
1169  $nodes = $this->getXpathNodes($this->dom, $xPath);
1170  if (count($nodes) > 0) {
1171  $children = $nodes[$index]->child_nodes();
1172  if (count($children) > 0) {
1173  for ($i = 0; $i < count($children); $i++) {
1174  if ($children[$i]->node_name() == $name &&
1175  is_array($newNode)) {
1176  foreach ($newNode as $key => $val) {
1177  if ($key == "value") {
1178  $children[$i]->set_content($val);
1179  } else {
1180  $children[$i]->set_attribute($key, $val);
1181  }
1182  }
1183  }
1184  }
1185  }
1186  }
1187  }
1188 
1196  public function getFirstDomNode($xPath)
1197  {
1198  $node = $this->getXpathNodes($this->dom, $xPath);
1199  return($node[0]);
1200  }
1201 
1206  public function updateFromDom()
1207  {
1208  $this->deleteAllDbData();
1209  $xml = $this->dom->dump_mem(0);
1210  $this->import($xml, $this->obj_id, $this->obj_type);
1211  }
1212 
1217  public function deleteAllDbData()
1218  {
1219  global $ilBench, $ilDB;
1220 
1221  #$ilBench->start('NestedSet','deleteAllDBData');
1222  $res = $this->db->query("SELECT * FROM xmlnestedset WHERE ns_book_fk = " . $ilDB->quote($this->obj_id) . " AND ns_type = " . $ilDB->quote($this->obj_type) . " ");
1223  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1224  $this->db->query("DELETE FROM xmlparam WHERE tag_fk = " . $ilDB->quote($row["ns_tag_fk"]) . " ");
1225  $this->db->query("DELETE FROM xmlvalue WHERE tag_fk = " . $ilDB->quote($row["ns_tag_fk"]) . " ");
1226  $this->db->query("DELETE FROM xmltags WHERE tag_pk = " . $ilDB->quote($row["ns_tag_fk"]) . " ");
1227  }
1228  $this->db->query("DELETE FROM xmlnestedset WHERE ns_book_fk = " . $ilDB->quote($this->obj_id) . " AND ns_type = " . $ilDB->quote($this->obj_type) . " ");
1229  #$ilBench->stop('NestedSet','deleteAllDBData');
1230  }
1231 
1239  public function _deleteAllChildMetaData($a_ids)
1240  {
1241  global $ilBench, $ilDB;
1242 
1243  #$ilBench->start('NestedSet','deleteAllChildMetaData');
1244 
1245  // STEP TWO: DELETE ENTRIES IN xmlnestedset GET ALL tag_fks
1246  $in = " IN (";
1247  $in .= implode(",", ilUtil::quoteArray($a_ids));
1248  $in .= ")";
1249 
1250  $query = "SELECT ns_tag_fk FROM xmlnestedset " .
1251  "WHERE ns_book_fk " . $in;
1252  $res = $ilDB->query($query);
1253  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1254  $tag_fks[$row->ns_tag_fk] = $row->ns_tag_fk;
1255  }
1256  $ilDB->query("DELETE FROM xmlnestedset WHERE ns_book_fk " . $in);
1257 
1258 
1259  // FINALLY DELETE
1260  $in = " IN (";
1261  $in .= implode(",", ilUtil::quoteArray($tag_fks));
1262  $in .= ")";
1263 
1264  $ilDB->query("DELETE FROM xmlparam WHERE tag_fk " . $in);
1265  $ilDB->query("DELETE FROM xmlvalue WHERE tag_fk " . $in);
1266  $ilDB->query("DELETE FROM xmltags WHERE tag_pk " . $in);
1267 
1268  #$ilBench->stop('NestedSet','deleteAllChildMetaData');
1269  return true;
1270  }
1271 
1278  public function _getAllChildIds($a_obj_id)
1279  {
1280  global $ilDB;
1281 
1282  $query = "SELECT obj_id FROM lm_data WHERE lm_id = " . $ilDB->quote($a_obj_id) . " ";
1283  $res = $ilDB->query($query);
1284  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1285  $ids[$row->obj_id] = $row->obj_id;
1286  }
1287  $ids[$a_obj_id] = $a_obj_id;
1288 
1289  return $ids ? $ids : array();
1290  }
1291 
1292 
1293  // }}}
1294 }
getTagValue()
get tag content
replace_content(&$node, &$new_content)
Replace node contents.
$xml_parser
SAX-Parser-Handle.
_deleteAllChildMetaData($a_ids)
Delete meta data of a content object (pages, chapters) public.
$result
$type
initDom()
inits dom-object from given xml-content
domxml_open_mem($str, $mode=0, &$error=null)
export($obj_id, $type)
Export-Function.
__construct()
Constructor initilize netsed-set variables public.
$lastTag
last Tag-Name found
$attributes
$index
Definition: metadata.php:60
$db
Datenbank-handle.
_getAllChildIds($a_obj_id)
Get all child ids of a content object public.
init($obj_id, $obj_type)
initilialize Nested-Set-Structur
getFirstDomContent($xPath)
returns first content of this node
$LEFT
Left and right edge tags.
$xml
Definition: metadata.php:240
if($format !==null) $name
Definition: metadata.php:146
setTagName($tagName)
set tag-name
deleteDomNode($xPath, $name, $index=0)
deletes node
$r
Definition: example_031.php:79
foreach($_POST as $key=> $value) $res
getDomContent($xPath, $name="", $index=0)
returns all contents of this node
$obj_type
The type of the data to those this entry belongs.
setTagValue($value)
set tag-content
redirection script todo: (a better solution should control the processing via a xml file) ...
getTagName()
find first tag-name
updateFromDom()
imports new xml-data from dom into nested set public
$query
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
getFirstDomNode($xPath)
first dom-node
Create styles array
The data for the language used.
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
$DEPTH
Nesting level of the tags.
getXpathNodes(&$doc, $qry)
get node in dom-structure
static quoteArray($a_array)
Quotes all members of an array for usage in DB query statement.
$parser
Definition: BPMN2Parser.php:23
addDomNode($xPath, $name, $value="", $attributes="", $index=0)
adds node to DOM-Structure
global $ilBench
Definition: ilias.php:18
global $ilDB
updateDomContent($xPath, $name="", $index=0, $newNode)
updates content of this node
addXMLNode($xPath, $xml, $index=0)
parse XML code and add it to a given DOM object as a new node
$i
Definition: disco.tpl.php:19
endElement($parser, $name)
method called at a closing tag private
setParameterModifier(&$a_object, $a_method)
$key
Definition: croninfo.php:18
startElement($parser, $name, $attrs)
Method is called, at an introductory TAG private.
updateDomNode($xPath, $meta, $no=0)
updates dom node
replaceDomContent($xPath, $name="", $index=0, $newNode)
updates content of this node
deleteAllDbData()
deletes current db-data of $this->obj_id and $this->obj_type private