ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjDlBook.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 require_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
25 
35 {
36  var $bib_obj;
37 
42  function ilObjDlBook($a_id = 0,$a_call_by_reference = true)
43  {
44  $this->type = "dbk";
45  parent::ilObjContentObject($a_id, $a_call_by_reference);
46 
47  if($a_id)
48  {
49  $this->readAssignedTranslations();
50  }
51  }
52 
53 
57  function initBibItemObject()
58  {
59  include_once("./Modules/LearningModule/classes/class.ilBibItem.php");
60 
61  $this->bib_obj =& new ilBibItem($this);
62  $this->bib_obj->read();
63 
64  return true;
65  }
66 
77  function exportRekursiv($obj_id, $depth, $left, $right)
78  {
79  global $ilDB;
80 
81  // Jetzt alle lm_data anhand der obj_id auslesen.
82  $query = "SELECT *
83  FROM lm_tree, lm_data
84  WHERE lm_tree.lm_id = ".$ilDB->quote($obj_id)."
85  AND lm_tree.child = lm_data.obj_id
86  AND ( lm_data.type = 'st' OR lm_data.type = 'pg' )
87  AND lm_tree.depth = ".$ilDB->quote($depth)."
88  AND lm_tree.lft > ".$ilDB->quote($left)." and lm_tree.rgt < ".$ilDB->quote($right)."
89  ORDER BY lm_tree.lft";
90  $result = $this->ilias->db->query($query);
91  while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) )
92  {
93  if ($row["type"] == "st")
94  {
95  $xml .= "<StructureObject>";
96 
97  $nested = new ilNestedSetXML();
98  $xml .= $nested->export($row["obj_id"],"st");
99  $xml .= "\n";
100 
101  $xml .= $this->exportRekursiv($obj_id, $depth+1, $row["lft"], $row["rgt"]);
102 
103  $xml .= "</StructureObject>";
104  }
105 
106  if ($row["type"] == "pg")
107  {
108 
109  $query = "SELECT * FROM page_object WHERE page_id= ".$ilDB->quote($row["obj_id"]);
110  $result2 = $this->ilias->db->query($query);
111 
112  $row2 = $result2->fetchRow(DB_FETCHMODE_ASSOC);
113 
114  $PO = $row2["content"]."\n";
115 
116  if (stristr($PO,"MediaObject"))
117  {
118 
119  $dom = domxml_open_mem($PO);
120  $xpc = xpath_new_context($dom);
121  $path = "//MediaObject/MediaAlias";
122  $res =& xpath_eval($xpc, $path);
123  for($i = 0; $i < count($res->nodeset); $i++)
124  {
125  $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
126  $mob_id = $id_arr[count($id_arr) - 1];
127  $this->mob_ids[$mob_id] = true;
128  }
129  }
130 
131  $nested = new ilNestedSetXML();
132  $mdxml = $nested->export($row["obj_id"],"pg");
133 
134  $PO = str_replace("<PageObject>","<PageObject>\n$mdxml\n",$PO);
135 
136  $xml .= $PO;
137 
138  }
139 
140  }
141 
142  return($xml);
143  }
144 
148  function export($a_deliver = true)
149  {
150  global $ilDB;
151 
152  include_once("./classes/class.ilNestedSetXML.php");
153  // ------------------------------------------------------
154  // anhand der ref_id die obj_id ermitteln.
155  // ------------------------------------------------------
156  $query = "SELECT * FROM object_reference,object_data WHERE object_reference.ref_id= ".
157  $ilDB->quote($this->getRefId())." AND object_reference.obj_id=object_data.obj_id ";
158  $result = $this->ilias->db->query($query);
159 
160  $objRow = $result->fetchRow(DB_FETCHMODE_ASSOC);
161 
162  $obj_id = $objRow["obj_id"];
163 
164  $this->mob_ids = array();
165 
166  // ------------------------------------------------------
167  // start xml-String
168  // ------------------------------------------------------
169  $xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE ContentObject SYSTEM \"ilias_co.dtd\">\n<ContentObject Type=\"LibObject\">\n";
170 
171  // ------------------------------------------------------
172  // get global meta-data
173  // ------------------------------------------------------
174  $nested = new ilNestedSetXML();
175  $xml .= $nested->export($obj_id,"dbk")."\n";
176 
177  // ------------------------------------------------------
178  // get all book-xml-data recursiv
179  // ------------------------------------------------------
180 
181  $query = "SELECT *
182  FROM lm_tree, lm_data
183  WHERE lm_tree.lm_id = ".$ilDB->quote($obj_id)."
184  AND lm_tree.child = lm_data.obj_id
185  AND ( lm_data.type = 'du' )
186  AND lm_tree.depth = 1
187  ORDER BY lm_tree.lft";
188  $result = $this->ilias->db->query($query);
189  $treeData = $result->fetchRow(DB_FETCHMODE_ASSOC);
190 
191  $xml .= $this->exportRekursiv($obj_id,2, $treeData["lft"], $treeData["rgt"]);
192 
193  // ------------------------------------------------------
194  // get or create export-directory
195  // ------------------------------------------------------
196  $this->createExportDirectory();
197  $export_dir = $this->getExportDirectory();
198 
199  // ------------------------------------------------------
200  // get mediaobject-xml-data
201  // ------------------------------------------------------
202  $mob_ids = $this->mob_ids;
203  if (is_array($mob_ids) && count($mob_ids)>0)
204  {
205  reset ($mob_ids);
206  while (list ($key, $val) = each ($mob_ids))
207  {
208 
209  $xml .= "<MediaObject>";
210 
211  $query = "SELECT * FROM media_item WHERE mob_id= ".$ilDB->quote($key)." ";
212  //vd($query);
213  $first = true;
214  $result = $this->ilias->db->query($query);
215  while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) )
216  {
217  if($first)
218  {
219  //vd($row[purpose]);
220  $nested = new ilNestedSetXML();
221  $metaxml = $nested->export($key,"mob");
222  $metaxml = preg_replace("/Entry=\"(.*?)\"/","Entry=\"il__mob_".$key."\"",$metaxml);
223 
224  $metaxml2 = "<Technical>";
225  $metaxml2 .= "<Format>".$row["format"]."</Format>";
226  $metaxml2 .= "<Size>14559</Size>";
227  $metaxml2 .= "<Location Type=\"".$row["location_type"]."\">".$row["location"]."</Location>";
228  $metaxml2 .= "</Technical>";
229 
230  $metaxml = str_replace("</MetaData>",$metaxml2."</MetaData>",$metaxml);
231 
232  $xml .= $metaxml;
233 
234  $first = false;
235  }
236 
237  $xml .= "<MediaItem Purpose=\"".$row["purpose"]."\">";
238  $xml .= "<Location Type=\"".$row["location_type"]."\">".$row["location"]."</Location>";
239  $xml .= "<Format>".$row["format"]."</Format>";
240  $xml .= "<Layout Width=\"".$row["width"]."\" Height=\"".$row["height"]."\"/>";
241  $xml .= "</MediaItem>";
242 
243  }
244  $xml .= "</MediaObject>";
245  }
246  }
247 
248 
249  // ------------------------------------------------------
250  // get bib-xml-data
251  // ------------------------------------------------------
252  $nested = new ilNestedSetXML();
253  $bib = $nested->export($obj_id,"bib");
254 
255  $xml .= $bib."\n";
256 
257  // ------------------------------------------------------
258  // xml-ending
259  // ------------------------------------------------------
260  $xml .= "</ContentObject>";
261 
262  // ------------------------------------------------------
263  // filename and directory-creation
264  // ------------------------------------------------------
265  $fileName = $objRow["title"];
266  $fileName = str_replace(" ","_",$fileName);
267 
268  if (!file_exists($export_dir."/".$fileName))
269  {
270  @mkdir($export_dir."/".$fileName);
271  @chmod($export_dir."/".$fileName,0755);
272  }
273 
274  if (!file_exists($export_dir."/".$fileName."/objects"))
275  {
276  @mkdir($export_dir."/".$fileName."/objects");
277  @chmod($export_dir."/".$fileName."/objects",0755);
278  }
279 
280  // ------------------------------------------------------
281  // copy mob-files
282  // ------------------------------------------------------
283  $mob_ids = $this->mob_ids;
284  if (is_array($mob_ids) && count($mob_ids)>0)
285  {
286  reset ($mob_ids);
287  while (list ($key, $val) = each ($mob_ids))
288  {
289 
290  if (!file_exists($export_dir."/".$fileName."/objects/mm".$key))
291  {
292  @mkdir($export_dir."/".$fileName."/objects/mm".$key);
293  @chmod($export_dir."/".$fileName."/objects/mm".$key,0755);
294  }
295 
296  $mobdir = "./data/mobs/mm_".$key;
297  ilUtil::rCopy($mobdir, $export_dir."/".$fileName."/objects/mm".$key);
298  }
299  }
300 
301  // ------------------------------------------------------
302  // save xml-file
303  // ------------------------------------------------------
304  $fp = fopen($export_dir."/".$fileName."/".$fileName.".xml","wb");
305  fwrite($fp,$xml);
306  fclose($fp);
307 
308  // ------------------------------------------------------
309  // zip all files
310  // ------------------------------------------------------
311  ilUtil::zip($export_dir."/".$fileName, $export_dir."/".$fileName.".zip");
312 
313  // ------------------------------------------------------
314  // deliver files
315  // ------------------------------------------------------
316 
317  if($a_deliver)
318  {
319  ilUtil::deliverFile($export_dir."/".$fileName.".zip",$fileName);
320  }
321  else
322  {
323  return $export_dir."/".$fileName.".zip";
324  }
325  /*
326  header("Expires: Mon, 1 Jan 1990 00:00:00 GMT");
327  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
328  header("Cache-Control: no-store, no-cache, must-revalidate");
329  header("Cache-Control: post-check=0, pre-check=0", false);
330  header("Pragma: no-cache");
331  header("Content-type: application/octet-stream");
332  if (stristr(" ".$GLOBALS["HTTP_SERVER_VARS"]["HTTP_USER_AGENT"],"MSIE") )
333  {
334  header ("Content-Disposition: attachment; filename=" . $fileName.".zip");
335  }
336  else
337  {
338  header ("Content-Disposition: inline; filename=".$fileName.".zip" );
339  }
340  header ("Content-length:".(string)( filesize($export_dir."/".$fileName.".zip")) );
341 
342  readfile( $export_dir."/".$fileName.".zip" );
343  */
344 
345  }
346 
347 
348  function addTranslation($a_ref_id)
349  {
350  global $ilDB;
351 
352  $query = "REPLACE INTO dbk_translations ".
353  "SET id = ".$ilDB->quote($this->ref_id).", ".
354  "tr_id = ".$ilDB->quote($a_ref_id)." ";
355  $res = $this->ilias->db->query($query);
356 
357  $query = "REPLACE INTO dbk_translations ".
358  "SET id = ".$ilDB->quote($a_ref_id).", ".
359  "tr_id = ".$ilDB->quote($this->ref_id)." ";
360  $res = $this->ilias->db->query($query);
361 
362  // UPDATE MEMBER VARIABLE
363  $this->readAssignedTranslations();
364 
365  return true;
366  }
367 
368  function addTranslations($a_arr_ref_id)
369  {
370  if(!is_array($a_arr_ref_id))
371  {
372  return false;
373  }
374  foreach($a_arr_ref_id as $ref_id)
375  {
376  $this->addTranslation($ref_id);
377  }
378  return true;
379  }
380  function deleteTranslation($a_ref_id)
381  {
382  global $ilDB;
383 
384  if(!$a_ref_id)
385  {
386  return false;
387  }
388 
389  $query = "DELETE FROM dbk_translations ".
390  "WHERE id = ".$ilDB->quote($this->ref_id)." ".
391  "AND tr_id = ".$ilDB->quote($a_ref_id)." ";
392 
393  $res = $this->ilias->db->query($query);
394 
395  $query = "DELETE FROM dbk_translations ".
396  "WHERE id = ".$ilDB->quote($a_ref_id)." ".
397  "AND tr_id = ".$ilDB->quote($this->ref_id)." ";
398 
399  $res = $this->ilias->db->query($query);
400 
401  // UPDATE MEMBER VARIABLE
402  $this->readAssignedTranslations();
403 
404  return true;
405  }
406 
407  function deleteTranslations($a_arr_ref_id)
408  {
409  if(!is_array($a_arr_ref_id))
410  {
411  return false;
412  }
413  foreach($a_arr_ref_id as $ref_id)
414  {
415  $this->deleteTranslation($ref_id);
416  }
417  return true;
418  }
419  function getTranslations()
420  {
421  return $this->tr_ids;
422  }
430  function _search(&$search_obj,$a_search_in)
431  {
432  global $ilBench;
433 
434  switch($a_search_in)
435  {
436  case 'meta':
437  // FILTER ALL DBK OBJECTS
438  $in = $search_obj->getInStatement("r.ref_id");
439  $where = $search_obj->getWhereCondition("fulltext",array("xv.tag_value"));
440 
441  /* very slow on mysql < 4.0.18
442  $query = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
443  "lm_data AS l,xmlnestedset AS xm,xmlvalue AS xv ".
444  $where.
445  $in.
446  "AND r.obj_id=o.obj_id AND ((o.obj_id=l.lm_id AND xm.ns_book_fk=l.obj_id) OR ".
447  "(o.obj_id=xm.ns_book_fk AND xm.ns_type IN ('dbk','bib'))) ".
448  "AND xm.ns_tag_fk=xv.tag_fk ".
449  "AND o.type= 'dbk'"; */
450 
451  $query1 = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
452  "xmlnestedset AS xm,xmlvalue AS xv ".
453  $where.
454  $in.
455  "AND r.obj_id=o.obj_id AND ( ".
456  "(o.obj_id=xm.ns_book_fk AND xm.ns_type IN ('dbk','bib'))) ".
457  "AND xm.ns_tag_fk=xv.tag_fk ".
458  "AND o.type= 'dbk'";
459 
460  // BEGINNING SELECT WITH SEARCH RESULTS IS MUCH FASTER
461  $query1 = "SELECT DISTINCT(r.ref_id) as ref_id FROM xmlvalue AS xv ".
462  "LEFT JOIN xmlnestedset AS xm ON xm.ns_tag_fk=xv.tag_fk ".
463  "LEFT JOIN object_data AS o ON o.obj_id = xm.ns_book_fk ".
464  "LEFT JOIN object_reference AS r ON o.obj_id = r.obj_id ".
465  $where.
466  $in.
467  " AND o.type = 'dbk' AND xm.ns_type IN ('dbk','bib')";
468 
469  $query2 = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
470  "lm_data AS l,xmlnestedset AS xm,xmlvalue AS xv ".
471  $where.
472  $in.
473  "AND r.obj_id=o.obj_id AND ((o.obj_id=l.lm_id AND xm.ns_book_fk=l.obj_id) ".
474  ") ".
475  "AND xm.ns_tag_fk=xv.tag_fk ".
476  "AND o.type= 'dbk'";
477 
478  $query2 = "SELECT DISTINCT(r.ref_id) as ref_id FROM xmlvalue AS xv ".
479  " LEFT JOIN xmlnestedset AS xm ON xm.ns_tag_fk = xv.tag_fk ".
480  " LEFT JOIN lm_data AS l ON l.obj_id = xm.ns_book_fk ".
481  " LEFT JOIN object_data AS o ON o.obj_id = l.lm_id ".
482  " LEFT JOIN object_reference AS r ON r.obj_id = o.obj_id ".
483  $where.
484  $in.
485  "AND o.type = 'dbk'";
486 
487 
488  /*
489  $query = "SELECT DISTINCT(r.ref_id) AS ref_id FROM object_reference AS r ".
490  "INNER JOIN object_data AS o ON r.obj_id=o.obj_id ".
491  "INNER JOIN lm_data AS l ON l.lm_id = o.obj_id ".
492  "INNER JOIN xmlnestedset AS xm ON (xm.ns_book_fk = l.obj_id OR xm.ns_type IN ('dbk','bib')) ".
493  "INNER JOIN xmlvalue AS xv ON xm.ns_tag_fk = xv.tag_fk ".
494  $where.
495  $in.
496  "AND o.type = 'dbk'";
497  */
498 
499  $ilBench->start("Search", "ilObjDlBook_search_meta");
500  $res1 = $search_obj->ilias->db->query($query1);
501  $res2 = $search_obj->ilias->db->query($query2);
502  $ilBench->stop("Search", "ilObjDlBook_search_meta");
503 
504  $counter = 0;
505  $ids = array();
506  while($row = $res1->fetchRow(DB_FETCHMODE_OBJECT))
507  {
508  $ids[] = $row->ref_id;
509  $result[$counter]["id"] = $row->ref_id;
510 
511  ++$counter;
512  }
513  while($row = $res2->fetchRow(DB_FETCHMODE_OBJECT))
514  {
515  if(in_array($row->ref_id,$ids))
516  {
517  continue;
518  }
519  $result[$counter]["id"] = $row->ref_id;
520 
521  ++$counter;
522  }
523  break;
524 
525  case 'content':
526  $in = $search_obj->getInStatement("ref_id");
527  $where = $search_obj->getWhereCondition("fulltext",array("pg.content"));
528 
529  $query = "SELECT DISTINCT(r.ref_id) AS ref_id ,pg.page_id AS page_id FROM page_object AS pg ".
530  "INNER JOIN object_reference AS r ON pg.parent_id = r.obj_id ".
531  $where.
532  $in.
533  "AND pg.parent_type = 'dbk' ";
534 
535  $ilBench->start("Search", "ilObjDlBook_search_content");
536  $res = $search_obj->ilias->db->query($query);
537  $ilBench->stop("Search", "ilObjDlBook_search_content");
538 
539  $counter = 0;
540  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
541  {
542  $result[$counter]["id"] = $row->ref_id;
543  $result[$counter]["page_id"] = $row->page_id;
544 
545  ++$counter;
546  }
547  break;
548  }
549  return $result ? $result : array();
550  }
551 
552  function getXMLZip()
553  {
554  return $this->export(false);
555  }
556 
557 
558  // PRIVATE METHODS
560  {
561  global $ilDB;
562 
563  $query = "SELECT tr_id FROM dbk_translations ".
564  "WHERE id = ".$ilDB->quote($this->ref_id)." ";
565 
566  $res = $this->ilias->db->query($query);
567  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
568  {
569  $tmp_tr_ids[] = $row->tr_id;
570  }
571  return $this->tr_ids = $tmp_tr_ids ? $tmp_tr_ids : array();
572  }
573 } // END class.ilObjDlBook
574 
575 ?>