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