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