ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilObjDlBook.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("./Modules/LearningModule/classes/class.ilObjContentObject.php");
5
15{
17
22 function ilObjDlBook($a_id = 0,$a_call_by_reference = true)
23 {
24 $this->type = "dbk";
25 parent::ilObjContentObject($a_id, $a_call_by_reference);
26
27 if($a_id)
28 {
30 }
31 }
32
33
38 {
39 include_once("./Modules/LearningModule/classes/class.ilBibItem.php");
40
41 $this->bib_obj =& new ilBibItem($this);
42 $this->bib_obj->read();
43
44 return true;
45 }
46
57 function exportRekursiv($obj_id, $depth, $left, $right)
58 {
59 global $ilDB;
60
61 // Jetzt alle lm_data anhand der obj_id auslesen.
62 $query = "SELECT *
63 FROM lm_tree, lm_data
64 WHERE lm_tree.lm_id = ".$ilDB->quote($obj_id, "integer")."
65 AND lm_tree.child = lm_data.obj_id
66 AND ( lm_data.type = 'st' OR lm_data.type = 'pg' )
67 AND lm_tree.depth = ".$ilDB->quote($depth, "integer")."
68 AND lm_tree.lft > ".$ilDB->quote($left, "integer").
69 " and lm_tree.rgt < ".$ilDB->quote($right, "integer")."
70 ORDER BY lm_tree.lft";
71 $result = $ilDB->query($query);
72 while (is_array($row = $ilDB->fetchAssoc($result)) )
73 {
74 if ($row["type"] == "st")
75 {
76 $xml .= "<StructureObject>";
77
78 $nested = new ilNestedSetXML();
79 $xml .= $nested->export($row["obj_id"],"st");
80 $xml .= "\n";
81
82 $xml .= $this->exportRekursiv($obj_id, $depth+1, $row["lft"], $row["rgt"]);
83
84 $xml .= "</StructureObject>";
85 }
86
87 if ($row["type"] == "pg")
88 {
89
90 $query = "SELECT * FROM page_object WHERE page_id= ".$ilDB->quote($row["obj_id"], "integer");
91 $result2 = $this->ilias->db->query($query);
92
93 $row2 = $result2->fetchRow(DB_FETCHMODE_ASSOC);
94
95 $PO = $row2["content"]."\n";
96
97 if (stristr($PO,"MediaObject"))
98 {
99
100 $dom = domxml_open_mem($PO);
101 $xpc = xpath_new_context($dom);
102 $path = "//MediaObject/MediaAlias";
103 $res =& xpath_eval($xpc, $path);
104 for($i = 0; $i < count($res->nodeset); $i++)
105 {
106 $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
107 $mob_id = $id_arr[count($id_arr) - 1];
108 $this->mob_ids[$mob_id] = true;
109 }
110 }
111
112 $nested = new ilNestedSetXML();
113 $mdxml = $nested->export($row["obj_id"],"pg");
114
115 $PO = str_replace("<PageObject>","<PageObject>\n$mdxml\n",$PO);
116
117 $xml .= $PO;
118
119 }
120
121 }
122
123 return($xml);
124 }
125
129 function export($a_deliver = true)
130 {
131 global $ilDB;
132
133 include_once("./Services/Xml/classes/class.ilNestedSetXML.php");
134 // ------------------------------------------------------
135 // anhand der ref_id die obj_id ermitteln.
136 // ------------------------------------------------------
137 $objRow["obj_id"] = ilOject::_lookupObjId();
138 $objRow["title"] = ilOject::_lookupTitle($objRow["obj_id"]);
139 $obj_id = $objRow["obj_id"];
140
141 $this->mob_ids = array();
142
143 // ------------------------------------------------------
144 // start xml-String
145 // ------------------------------------------------------
146 $xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE ContentObject SYSTEM \"ilias_co.dtd\">\n<ContentObject Type=\"LibObject\">\n";
147
148 // ------------------------------------------------------
149 // get global meta-data
150 // ------------------------------------------------------
151 $nested = new ilNestedSetXML();
152 $xml .= $nested->export($obj_id,"dbk")."\n";
153
154 // ------------------------------------------------------
155 // get all book-xml-data recursiv
156 // ------------------------------------------------------
157
158 $query = "SELECT *
159 FROM lm_tree, lm_data
160 WHERE lm_tree.lm_id = ".$ilDB->quote($obj_id, "integer")."
161 AND lm_tree.child = lm_data.obj_id
162 AND ( lm_data.type = 'du' )
163 AND lm_tree.depth = 1
164 ORDER BY lm_tree.lft";
165 $result = $ilDB->query($query);
166 $treeData = $ilDB->fetchAssoc($result);
167
168 $xml .= $this->exportRekursiv($obj_id,2, $treeData["lft"], $treeData["rgt"]);
169
170 // ------------------------------------------------------
171 // get or create export-directory
172 // ------------------------------------------------------
173 $this->createExportDirectory();
174 $export_dir = $this->getExportDirectory();
175
176 // ------------------------------------------------------
177 // get mediaobject-xml-data
178 // ------------------------------------------------------
179 $mob_ids = $this->mob_ids;
180 if (is_array($mob_ids) && count($mob_ids)>0)
181 {
182 reset ($mob_ids);
183 while (list ($key, $val) = each ($mob_ids))
184 {
185
186 $xml .= "<MediaObject>";
187
188 $query = "SELECT * FROM media_item WHERE mob_id= ".
189 $ilDB->quote($key, "integer")." ";
190 //vd($query);
191 $first = true;
192 $result = $ilDB->query($query);
193 while (is_array($row = $ilDB->fetchRow($result)) )
194 {
195 if($first)
196 {
197 //vd($row[purpose]);
198 $nested = new ilNestedSetXML();
199 $metaxml = $nested->export($key,"mob");
200 $metaxml = preg_replace("/Entry=\"(.*?)\"/","Entry=\"il__mob_".$key."\"",$metaxml);
201
202 $metaxml2 = "<Technical>";
203 $metaxml2 .= "<Format>".$row["format"]."</Format>";
204 $metaxml2 .= "<Size>14559</Size>";
205 $metaxml2 .= "<Location Type=\"".$row["location_type"]."\">".$row["location"]."</Location>";
206 $metaxml2 .= "</Technical>";
207
208 $metaxml = str_replace("</MetaData>",$metaxml2."</MetaData>",$metaxml);
209
210 $xml .= $metaxml;
211
212 $first = false;
213 }
214
215 $xml .= "<MediaItem Purpose=\"".$row["purpose"]."\">";
216 $xml .= "<Location Type=\"".$row["location_type"]."\">".$row["location"]."</Location>";
217 $xml .= "<Format>".$row["format"]."</Format>";
218 $xml .= "<Layout Width=\"".$row["width"]."\" Height=\"".$row["height"]."\"/>";
219 $xml .= "</MediaItem>";
220
221 }
222 $xml .= "</MediaObject>";
223 }
224 }
225
226
227 // ------------------------------------------------------
228 // get bib-xml-data
229 // ------------------------------------------------------
230 $nested = new ilNestedSetXML();
231 $bib = $nested->export($obj_id,"bib");
232
233 $xml .= $bib."\n";
234
235 // ------------------------------------------------------
236 // xml-ending
237 // ------------------------------------------------------
238 $xml .= "</ContentObject>";
239
240 // ------------------------------------------------------
241 // filename and directory-creation
242 // ------------------------------------------------------
243 $fileName = $objRow["title"];
244 $fileName = str_replace(" ","_",$fileName);
245
246 if (!file_exists($export_dir."/".$fileName))
247 {
248 @mkdir($export_dir."/".$fileName);
249 @chmod($export_dir."/".$fileName,0755);
250 }
251
252 if (!file_exists($export_dir."/".$fileName."/objects"))
253 {
254 @mkdir($export_dir."/".$fileName."/objects");
255 @chmod($export_dir."/".$fileName."/objects",0755);
256 }
257
258 // ------------------------------------------------------
259 // copy mob-files
260 // ------------------------------------------------------
261 $mob_ids = $this->mob_ids;
262 if (is_array($mob_ids) && count($mob_ids)>0)
263 {
264 reset ($mob_ids);
265 while (list ($key, $val) = each ($mob_ids))
266 {
267
268 if (!file_exists($export_dir."/".$fileName."/objects/mm".$key))
269 {
270 @mkdir($export_dir."/".$fileName."/objects/mm".$key);
271 @chmod($export_dir."/".$fileName."/objects/mm".$key,0755);
272 }
273
274 $mobdir = "./data/mobs/mm_".$key;
275 ilUtil::rCopy($mobdir, $export_dir."/".$fileName."/objects/mm".$key);
276 }
277 }
278
279 // ------------------------------------------------------
280 // save xml-file
281 // ------------------------------------------------------
282 $fp = fopen($export_dir."/".$fileName."/".$fileName.".xml","wb");
283 fwrite($fp,$xml);
284 fclose($fp);
285
286 // ------------------------------------------------------
287 // zip all files
288 // ------------------------------------------------------
289 ilUtil::zip($export_dir."/".$fileName, $export_dir."/".$fileName.".zip");
290
291 // ------------------------------------------------------
292 // deliver files
293 // ------------------------------------------------------
294
295 if($a_deliver)
296 {
297 ilUtil::deliverFile($export_dir."/".$fileName.".zip",$fileName);
298 }
299 else
300 {
301 return $export_dir."/".$fileName.".zip";
302 }
303 /*
304 header("Expires: Mon, 1 Jan 1990 00:00:00 GMT");
305 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
306 header("Cache-Control: no-store, no-cache, must-revalidate");
307 header("Cache-Control: post-check=0, pre-check=0", false);
308 header("Pragma: no-cache");
309 header("Content-type: application/octet-stream");
310 if (stristr(" ".$GLOBALS["HTTP_SERVER_VARS"]["HTTP_USER_AGENT"],"MSIE") )
311 {
312 header ("Content-Disposition: attachment; filename=" . $fileName.".zip");
313 }
314 else
315 {
316 header ("Content-Disposition: inline; filename=".$fileName.".zip" );
317 }
318 header ("Content-length:".(string)( filesize($export_dir."/".$fileName.".zip")) );
319
320 readfile( $export_dir."/".$fileName.".zip" );
321 */
322
323 }
324
325
326 function addTranslation($a_ref_id)
327 {
328 global $ilDB;
329
330 $ilDB->manipulate("DELETE FROM dbk_translations ".
331 " WHERE id = ".$ilDB->quote($this->ref_id, "integer")." ".
332 " AND tr_id = ".$ilDB->quote($a_ref_id, "integer"));
333
334 $ilDB->manipulate("INSERT INTO dbk_translations (id, tr_id) VALUES ".
335 "(".$ilDB->quote($this->ref_id, "integer").", ".
336 "".$ilDB->quote($a_ref_id, "integer").")");
337
338 $ilDB->manipulate("DELETE FROM dbk_translations ".
339 " WHERE id = ".$ilDB->quote($a_ref_id, "integer")." ".
340 " AND tr_id = ".$ilDB->quote($this->ref_id, "integer"));
341
342 $ilDB->manipulate("INSERT INTO dbk_translations (id, tr_id) VALUES ".
343 "(".$ilDB->quote($a_ref_id, "integer").", ".
344 "".$ilDB->quote($this->ref_id, "integer").")");
345
346 // UPDATE MEMBER VARIABLE
348
349 return true;
350 }
351
352 function addTranslations($a_arr_ref_id)
353 {
354 if(!is_array($a_arr_ref_id))
355 {
356 return false;
357 }
358 foreach($a_arr_ref_id as $ref_id)
359 {
360 $this->addTranslation($ref_id);
361 }
362 return true;
363 }
364 function deleteTranslation($a_ref_id)
365 {
366 global $ilDB;
367
368 if(!$a_ref_id)
369 {
370 return false;
371 }
372
373 $ilDB->manipulate("DELETE FROM dbk_translations ".
374 "WHERE id = ".$ilDB->quote($this->ref_id, "integer")." ".
375 "AND tr_id = ".$ilDB->quote($a_ref_id, "integer"));
376
377 $ilDB->manipulate("DELETE FROM dbk_translations ".
378 "WHERE id = ".$ilDB->quote($a_ref_id, "integer")." ".
379 "AND tr_id = ".$ilDB->quote($this->ref_id, "integer"));
380
381 // UPDATE MEMBER VARIABLE
383
384 return true;
385 }
386
387 function deleteTranslations($a_arr_ref_id)
388 {
389 if(!is_array($a_arr_ref_id))
390 {
391 return false;
392 }
393 foreach($a_arr_ref_id as $ref_id)
394 {
395 $this->deleteTranslation($ref_id);
396 }
397 return true;
398 }
400 {
401 return $this->tr_ids;
402 }
403
404 function getXMLZip()
405 {
406 return $this->export(false);
407 }
408
409
410 // PRIVATE METHODS
412 {
413 global $ilDB;
414
415 $query = "SELECT tr_id FROM dbk_translations ".
416 "WHERE id = ".$ilDB->quote($this->ref_id, "integer");
417
418 $res = $ilDB->query($query);
419 while ($row = $ilDB->fetchObject($res))
420 {
421 $tmp_tr_ids[] = $row->tr_id;
422 }
423 return $this->tr_ids = $tmp_tr_ids ? $tmp_tr_ids : array();
424 }
425} // END class.ilObjDlBook
426
427?>
$result
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
Class ilBibItem.
Class NestedSetXML functions for storing XML-Data into nested-set-database-strcture.
Class ilObjContentObject.
getExportDirectory($a_type="xml")
get export directory of lm
createExportDirectory($a_type="xml")
creates data directory for export files (data_dir/lm_data/lm_<id>/export, depending on data directory...
Class ilObjDlBook.
deleteTranslations($a_arr_ref_id)
initBibItemObject()
init bib object (contains all bib item data)
ilObjDlBook($a_id=0, $a_call_by_reference=true)
Constructor @access public.
addTranslation($a_ref_id)
export($a_deliver=true)
exports the digi-lib-object into a xml structure
addTranslations($a_arr_ref_id)
exportRekursiv($obj_id, $depth, $left, $right)
export lm_data-table to xml-structure
deleteTranslation($a_ref_id)
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static zip($a_dir, $a_file, $compress_content=false)
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
domxml_open_mem($str, $mode=DOMXML_LOAD_PARSING, &$error=NULL)
xpath_eval($xpath_context, $eval_str, $contextnode=null)
xpath_new_context($dom_document)
redirection script todo: (a better solution should control the processing via a xml file)
$path
Definition: index.php:22
global $ilDB