ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilCourseArchives.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
24include_once('Modules/Course/classes/class.ilFSStorageCourse.php');
25
26
37{
39 var $ilias;
40 var $ilErr;
41 var $ilDB;
42 var $tree;
43 var $lng;
44
50
53
54 private $fss_storage;
55
56
61 public function __construct($course_obj)
62 {
64
65 $this->ilias = $ilias;
66 $this->ilErr = $ilErr;
67 $this->ilDB = $ilDB;
68 $this->lng = $lng;
69 $this->tree = $tree;
70
71 $this->ARCHIVE_XML = 1;
72 $this->ARCHIVE_HTML = 2;
73 $this->ARCHIVE_PDF = 3;
74
75 $this->course_obj = $course_obj;
76
77 $this->__read();
78 }
79
80 // SET GET
81 function getArchives()
82 {
83 return $this->archives;
84 }
85
86 function getArchive($a_id)
87 {
88 return $this->archives[$a_id];
89 }
90
92 {
93 foreach($this->archives as $id => $archive)
94 {
95 if($archive['archive_type'] == $this->ARCHIVE_XML)
96 {
97 continue;
98 }
99 if($this->course_obj->getArchiveType() != $this->course_obj->ARCHIVE_DOWNLOAD and
100 $archive['archive_type'] == $this->ARCHIVE_PDF)
101 {
102 continue;
103 }
104 $public_archives[$id] = $archive;
105 }
106
107 return $public_archives ? $public_archives : array();
108 }
109
110 function setType($a_type)
111 {
112 $this->archive_type = $a_type;
113 }
114 function getType()
115 {
116 return $this->archive_type ? $this->archive_type : $this->ARCHIVE_XML;
117 }
118
119 function setDate($a_date)
120 {
121 $this->archive_date = $a_date;
122 }
123 function getDate()
124 {
125 return $this->archive_date ? $this->archive_date : time();
126 }
127
128 function setSize($a_size)
129 {
130 $this->archive_size = $a_size;
131 }
132 function getSize()
133 {
134 return $this->archive_size;
135 }
136 function setName($a_name)
137 {
138 $this->archive_name = $a_name;
139 }
140 function getName()
141 {
142 return $this->archive_name;
143 }
144 function setLanguage($a_lang_code)
145 {
146 $this->archive_lang = $a_lang_code;
147 }
148 function getLanguage()
149 {
150 return $this->archive_lang;
151 }
152
153
154 function getArchiveFile($a_id)
155 {
156 $archive = $this->getArchive($a_id);
157 $this->initCourseFilesObject();
158
159 if(PATH_TO_ZIP)
160 {
161 return $this->course_files_obj->getArchiveDirectory().'/'.$archive['archive_name'].'.zip';
162 }
163 else
164 {
165 return $this->course_files_obj->getArchiveDirectory().'/'.$archive['archive_name'];
166 }
167
168 }
169
175 function addXML($a_selection = "")
176 {
177 $this->setType($this->ARCHIVE_XML);
178 $this->setName(time().'__'.$this->ilias->getSetting('inst_id').'__crs_'.$this->course_obj->getId());
179 $this->setDate(time());
180
181 // Step one create folder
182 $this->initCourseFilesObject();
183 $this->course_files_obj->addArchiveSubDirectory($this->getName());
184
185 // Step two create course xml
186 $this->initCourseXMLWriter();
187
188 $this->course_xml_writer->start();
189 $this->course_files_obj->writeArchiveFile($this->course_xml_writer->getXML(),$this->getName().'/'.$this->getName().'.xml');
190
191
192 // Step three create child object xml
193 // add objects directory
194 $this->course_files_obj->addArchiveSubDirectory($this->getName().'/objects');
195
196 $this->copied_files = array();
197 $this->__addZipFiles($this->course_obj->getRefId(), $a_selection);
198
199 // Step four: Write index file
200 include_once("./Services/Export/classes/class.ilExport.php");
201 ilExport::_generateIndexFile($this->course_files_obj->getArchiveDirectory().'/'.
202 $this->getName().'/index.html', $this->course_obj->getId(),$this->copied_files);
203
204 // Step five zip
205 $this->setSize($this->course_files_obj->zipArchive($this->getName(),$this->getName().'.zip'));
206
207
208 // Finally add entry in crs_archives table
209 $this->add();
210
211 return true;
212 }
213
214 function addHTML()
215 {
216 $this->setType($this->ARCHIVE_HTML);
217 $this->setDate(time());
218 $this->setName($this->getDate().'__'.$this->ilias->getSetting('inst_id').'__crs_'.$this->course_obj->getId());
219
220 // Step one create folder
221 $this->initCourseFilesObject();
222 $this->course_files_obj->addArchiveSubDirectory($this->getName());
223
224 // Step two, create child html
225 $this->course_files_obj->addArchiveSubDirectory($this->getName().'/objects');
226 $this->__addHTMLFiles($this->course_obj->getRefId());
227
228 // Step three create course html
229 $this->__addCourseHTML();
230
231 // Step three create copy in web dir
232 $this->course_files_obj->createArchiveOnlineVersion($this->getName());
233
234 // Step four zip
235 $this->setSize($this->course_files_obj->zipArchive($this->getName(),$this->getName().'.zip'));
236
237 // Finally add entry in crs_archives table
238 $this->add();
239
240 return true;
241 }
242
243
244 function add()
245 {
246 global $ilDB;
247
248 $next_id = $ilDB->nextId('crs_archives');
249 $query = "INSERT INTO crs_archives (archive_id,course_id,archive_name,archive_type,archive_date,archive_size,archive_lang) ".
250 "VALUES (" .
251 $ilDB->quote($next_id,'integer').", ".
252 $ilDB->quote($this->course_obj->getId(),'integer').",".
253 $ilDB->quote($this->getName(),'text').",".
254 $ilDB->quote($this->getType(),'integer').", ".
255 $ilDB->quote($this->getDate(),'integer').",".
256 $ilDB->quote($this->getSize(),'integer').",".
257 $ilDB->quote($this->getLanguage(),'text').
258 ")";
259 $res = $ilDB->manipulate($query);
260
261 $this->__read();
262 return true;
263 }
264
265 function delete($a_id)
266 {
267 global $ilDB;
268
269 // Delete in file system
270 $this->initCourseFilesObject();
271
272 $this->course_files_obj->deleteArchive($this->archives[$a_id]["archive_name"]);
273
274 $query = "DELETE FROM crs_archives ".
275 "WHERE course_id = ".$ilDB->quote($this->course_obj->getId(),'integer')." ".
276 "AND archive_id = ".$ilDB->quote($a_id,'integer')." ";
277 $res = $ilDB->manipulate($query);
278
279 $this->__read();
280 return true;
281 }
282
283 function deleteAll()
284 {
285 foreach($this->getArchives() as $id => $archive)
286 {
287 $this->delete($id);
288 }
289 }
290
292 {
293 if(!is_object($this->course_files_obj))
294 {
295 include_once('Modules/Course/classes/class.ilFSStorageCourse.php');
296 $this->course_files_obj = new ilFSStorageCourse($this->course_obj->getId());
297 }
298 return true;
299 }
300
302 {
303 if(!is_object($this->course_xml_writer))
304 {
305 include_once "./Modules/Course/classes/class.ilCourseXMLWriter.php";
306 $this->course_xml_writer = new ilCourseXMLWriter($this->course_obj);
307 }
308 return true;
309 }
310
311 // PRIVATE
312
318 function __addZipFiles($a_parent_id, $a_selection = "")
319 {
320 $this->course_obj->initCourseItemObject();
321 $this->course_obj->items_obj->setParentId($a_parent_id);
322
323 foreach($this->course_obj->items_obj->getAllItems() as $item)
324 {
325 if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
326 {
327 continue;
328 }
329 $action = $a_selection[$item['child']];
330 if ($a_selection == "")
331 {
332 $action = "create";
333 }
334
335 if ($action == "omit")
336 {
337 continue;
338 }
339
340 if ($action == "create")
341 {
342 $abs_file_name = $tmp_obj->getXMLZip();
343 }
344 else
345 {
346 include_once("./Services/Export/classes/class.ilExport.php");
347 $info = ilExport::_getLastExportFileInformation($item['obj_id'], "xml", $item['type']);
348 $abs_file_name = ilExport::_getExportDirectory($item['obj_id'], "xml", $item['type'])."/".$info["file"];
349 if (!@is_file($abs_file_name))
350 {
351 $abs_file_name = "";
352 }
353 }
354
355 // must return absolute path to zip file
356 if ($abs_file_name != "")
357 {
358 //$new_name = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['obj_id'].'.zip';
359 $new_name = basename($abs_file_name);
360 $this->course_files_obj->copyFile($abs_file_name,$this->course_files_obj->getArchiveDirectory().'/'.
361 $this->getName().'/'.$new_name);
362 if (is_file($this->course_files_obj->getArchiveDirectory().'/'.
363 $this->getName().'/'.$new_name))
364 {
365 $this->copied_files[] = array("title" => $item['title'],
366 "file" => $new_name, "type" => $item['type']);
367 }
368 }
369 $this->__addZipFiles($item['child']);
370
371 unset($tmp_obj);
372 }
373 return true;
374 }
375
376 function __addHTMLFiles($a_parent_id)
377 {
378 $this->course_obj->initCourseItemObject();
379 $this->course_obj->items_obj->setParentId($a_parent_id);
380
381 foreach($this->course_obj->items_obj->getAllItems() as $item)
382 {
383 if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
384 {
385 continue;
386 }
387 if($abs_dir_name = $tmp_obj->getHTMLDirectory())
388 {
389 $new_name = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['obj_id'];
390
391 $this->course_files_obj->addDirectory($this->getName().'/objects/'.$new_name);
392 $this->course_files_obj->rCopy($abs_dir_name,$this->getName().'/objects/'.$new_name);
393
394 // Store filename in hashtable (used for create course html tree)
395 $this->html_files["$item[obj_id]"] = "objects/".$new_name."/index.html";
396 }
397 $this->__addHTMLFiles($item['child']);
398 unset($tmp_obj);
399 }
400 return true;
401 }
402
404 {
405 global $tpl,$ilias;
406
407 // Get Language
408 if($this->getLanguage())
409 {
410 $lng = new ilLanguage($this->getLanguage());
411 $lng->loadLanguageModule('crs');
412 }
413 else
414 {
415 $lng =& $this->lng;
416 }
417
418 $tmp_tpl = new ilTemplate("tpl.crs_export.html",true,true,'Modules/Course');
419
420 $this->course_files_obj->copyFile($tpl->tplPath.'/'.$ilias->account->prefs["style"].'.css',
421 $this->course_files_obj->getArchiveDirectory().'/'.$this->getName().'/default.css');
422
423 $tmp_tpl->setVariable('TITLE',$lng->txt('crs_export'));
424 $tmp_tpl->setVariable("CRS_STRUCTURE",$lng->txt('crs_structure'));
425
426
427 $tmp_tpl->setVariable("DETAILS_TITLE",$lng->txt("crs_details"));
428
429 // SET TXT VARIABLES
430 $tmp_tpl->setVariable("TXT_SYLLABUS",$lng->txt("crs_syllabus"));
431 $tmp_tpl->setVariable("TXT_CONTACT",$lng->txt("crs_contact"));
432 $tmp_tpl->setVariable("TXT_CONTACT_NAME",$lng->txt("crs_contact_name"));
433 $tmp_tpl->setVariable("TXT_CONTACT_RESPONSIBILITY",$lng->txt("crs_contact_responsibility"));
434 $tmp_tpl->setVariable("TXT_CONTACT_EMAIL",$lng->txt("crs_contact_email"));
435 $tmp_tpl->setVariable("TXT_CONTACT_PHONE",$lng->txt("crs_contact_phone"));
436 $tmp_tpl->setVariable("TXT_CONTACT_CONSULTATION",$lng->txt("crs_contact_consultation"));
437 $tmp_tpl->setVariable("TXT_DATES",$lng->txt("crs_dates"));
438 $tmp_tpl->setVariable("TXT_ACTIVATION",$lng->txt("crs_activation"));
439 $tmp_tpl->setVariable("TXT_SUBSCRIPTION",$lng->txt("crs_subscription"));
440 $tmp_tpl->setVariable("TXT_ARCHIVE",$lng->txt("crs_archive"));
441
442 // FILL
443 $tmp_tpl->setVariable("SYLLABUS",nl2br($this->course_obj->getSyllabus() ?
444 $this->course_obj->getSyllabus() :
445 $lng->txt("crs_not_available")));
446
447 $tmp_tpl->setVariable("CONTACT_NAME",$this->course_obj->getContactName() ?
448 $this->course_obj->getContactName() :
449 $lng->txt("crs_not_available"));
450 $tmp_tpl->setVariable("CONTACT_RESPONSIBILITY",$this->course_obj->getContactResponsibility() ?
451 $this->course_obj->getContactResponsibility() :
452 $lng->txt("crs_not_available"));
453 $tmp_tpl->setVariable("CONTACT_PHONE",$this->course_obj->getContactPhone() ?
454 $this->course_obj->getContactPhone() :
455 $lng->txt("crs_not_available"));
456 $tmp_tpl->setVariable("CONTACT_CONSULTATION",nl2br($this->course_obj->getContactConsultation() ?
457 $this->course_obj->getContactConsultation() :
458 $lng->txt("crs_not_available")));
459 if($this->course_obj->getContactEmail())
460 {
461 $tmp_tpl->setCurrentBlock("email_link");
462 #$tmp_tpl->setVariable("EMAIL_LINK","ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".$this->course_obj->getContactEmail());
463 $tmp_tpl->setVariable("CONTACT_EMAIL",$this->course_obj->getContactEmail());
464 $tmp_tpl->parseCurrentBlock();
465 }
466 else
467 {
468 $tmp_tpl->setCurrentBlock("no_mail");
469 $tmp_tpl->setVariable("NO_CONTACT_EMAIL",$this->course_obj->getContactEmail());
470 $tmp_tpl->parseCurrentBlock();
471 }
472 if($this->course_obj->getActivationUnlimitedStatus())
473 {
474 $tmp_tpl->setVariable("ACTIVATION",$lng->txt('crs_unlimited'));
475 }
476 else
477 {
478 $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getActivationStart())." ".
479 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getActivationEnd());
480 $tmp_tpl->setVariable("ACTIVATION",$str);
481 }
482 if($this->course_obj->getSubscriptionUnlimitedStatus())
483 {
484 $tmp_tpl->setVariable("SUBSCRIPTION",$lng->txt('crs_unlimited'));
485 }
486 else
487 {
488 $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getSubscriptionStart())." ".
489 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getSubscriptionEnd());
490 $tmp_tpl->setVariable("SUBSCRIPTION",$str);
491 }
492 if($this->course_obj->getArchiveType() == $this->course_obj->ARCHIVE_DISABLED)
493 {
494 $tmp_tpl->setVariable("ARCHIVE",$lng->txt('crs_archive_disabled'));
495 }
496 else
497 {
498 $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getArchiveStart())." ".
499 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getArchiveEnd());
500 $tmp_tpl->setVariable("ARCHIVE",$str);
501 }
502
503 $this->structure = '';
504 $this->__buildStructure($tmp_tpl,$this->course_obj->getRefId());
505 $tmp_tpl->setVariable("STRUCTURE",$this->structure);
506
507 $this->course_files_obj->writeArchiveFile($tmp_tpl->get(),$this->getName().'/index.html');
508
509 return true;
510 }
511
512 function __buildStructure(&$tmp_tpl,$a_parent_id)
513 {
514 $this->course_obj->initCourseItemObject();
515 $this->course_obj->items_obj->setParentId($a_parent_id);
516
517 $items = $this->course_obj->items_obj->getAllItems();
518
519 foreach($items as $key => $item)
520 {
521 if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
522 {
523 continue;
524 }
525
526
527 if($key == 0)
528 {
529 $this->structure .= "<ul>";
530 }
531
532 $this->structure .= "<li>";
533
534 if(isset($this->html_files["$item[obj_id]"]))
535 {
536 $link = "<a href=\"./".$this->html_files["$item[obj_id]"]."\">".$item["title"]."</a>";
537 }
538 else
539 {
540 $link = $item['title'];
541 }
542 $this->structure .= $link;
543 $this->structure .= "</li>";
544
545 $this->__buildStructure($tmp_tpl,$item['child']);
546
547 if($key == (count($items) - 1))
548 {
549 $this->structure .= "</ul>";
550 }
551
552
553 unset($tmp_obj);
554 }
555 return true;
556 }
557
565 public function cloneArchives()
566 {
567
568 }
569
570
571 function __read()
572 {
573 global $ilDB;
574
575 $this->archives = array();
576 $query = "SELECT * FROM crs_archives ".
577 "WHERE course_id = ".$ilDB->quote($this->course_obj->getId(),'integer')." ".
578 "ORDER BY archive_date DESC";
579
580 $res = $this->ilDB->query($query);
581 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
582 {
583 $this->archives[$row->archive_id]["archive_id"] = $row->archive_id;
584 $this->archives[$row->archive_id]["archive_type"] = $row->archive_type;
585 $this->archives[$row->archive_id]["archive_date"] = $row->archive_date;
586 $this->archives[$row->archive_id]["archive_size"] = $row->archive_size;
587 $this->archives[$row->archive_id]["archive_name"] = $row->archive_name;
588 $this->archives[$row->archive_id]["archive_lang"] = $row->archive_lang;
589 }
590 return true;
591 }
592}
593?>
global $tpl
Definition: ilias.php:8
An exception for terminatinating execution or to throw for unit testing.
class ilCourseArchives
__addZipFiles($a_parent_id, $a_selection="")
Add zip files to folder.
addXML($a_selection="")
Add XML archive.
__buildStructure(&$tmp_tpl, $a_parent_id)
__construct($course_obj)
Constructor.
cloneArchives()
Clone archives.
Database Wrapper.
Definition: class.ilDB.php:30
query($sql, $a_handle_error=true)
Query.
static _getLastExportFileInformation($a_obj_id, $a_type="", $a_obj_type="")
Get last export file information.
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
static _generateIndexFile($a_filename, $a_obj_id, $a_files, $a_type="")
Generates an index.html file including links to all xml files included (for container exports)
language handling
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
special template class to simplify handling of ITX/PEAR
$info
Definition: example_052.php:80
redirection script todo: (a better solution should control the processing via a xml file)
$a_type
Definition: workflow.php:93