• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

course/classes/class.ilCourseArchives.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00035 class ilCourseArchives
00036 {
00037         var $course_obj;
00038         var $ilias;
00039         var $ilErr;
00040         var $ilDB;
00041         var $tree;
00042         var $lng;
00043 
00044         var $archive_type;
00045         var $archive_date;
00046         var $archive_size;
00047         var $archive_name;
00048         var $archive_lang;
00049 
00050         var $course_files_obj;
00051         var $course_xml_writer;
00052 
00053 
00054         function ilCourseArchives(&$course_obj)
00055         {
00056                 global $ilErr,$ilDB,$lng,$tree,$ilias;
00057 
00058                 $this->ilias =& $ilias;
00059                 $this->ilErr =& $ilErr;
00060                 $this->ilDB  =& $ilDB;
00061                 $this->lng   =& $lng;
00062                 $this->tree  =& $tree;
00063 
00064                 $this->ARCHIVE_XML = 1;
00065                 $this->ARCHIVE_HTML = 2;
00066                 $this->ARCHIVE_PDF = 3;
00067 
00068                 $this->course_obj =& $course_obj;
00069 
00070                 $this->__read();
00071         }
00072 
00073         // SET GET
00074         function getArchives()
00075         {
00076                 return $this->archives;
00077         }
00078         
00079         function getArchive($a_id)
00080         {
00081                 return $this->archives[$a_id];
00082         }
00083 
00084         function getPublicArchives()
00085         {
00086                 foreach($this->archives as $id => $archive)
00087                 {
00088                         if($archive['archive_type'] == $this->ARCHIVE_XML)
00089                         {
00090                                 continue;
00091                         }
00092                         if($this->course_obj->getArchiveType() != $this->course_obj->ARCHIVE_DOWNLOAD and
00093                                 $archive['archive_type'] == $this->ARCHIVE_PDF)
00094                         {
00095                                 continue;
00096                         }
00097                         $public_archives[$id] = $archive;
00098                 }
00099                 
00100                 return $public_archives ? $public_archives : array();
00101         }
00102 
00103         function setType($a_type)
00104         {
00105                 $this->archive_type = $a_type;
00106         }
00107         function getType()
00108         {
00109                 return $this->archive_type ? $this->archive_type : $this->ARCHIVE_XML;
00110         }
00111 
00112         function setDate($a_date)
00113         {
00114                 $this->archive_date = $a_date;
00115         }
00116         function getDate()
00117         {
00118                 return $this->archive_date ? $this->archive_date : time();
00119         }
00120 
00121         function setSize($a_size)
00122         {
00123                 $this->archive_size = $a_size;
00124         }
00125         function getSize()
00126         {
00127                 return $this->archive_size;
00128         }
00129         function setName($a_name)
00130         {
00131                 $this->archive_name = $a_name;
00132         }
00133         function getName()
00134         {
00135                 return $this->archive_name;
00136         }
00137         function setLanguage($a_lang_code)
00138         {
00139                 $this->archive_lang = $a_lang_code;
00140         }
00141         function getLanguage()
00142         {
00143                 return $this->archive_lang;
00144         }
00145 
00146 
00147         function getArchiveFile($a_id)
00148         {
00149                 $archive = $this->getArchive($a_id);
00150                 $this->initCourseFilesObject();
00151 
00152                 return $this->course_files_obj->getArchiveFile($archive['archive_name']);
00153         }
00154 
00155         function addXML()
00156         {
00157                 $this->setType($this->ARCHIVE_XML);
00158                 $this->setName(time().'__'.$this->ilias->getSetting('inst_id').'__crs_'.$this->course_obj->getId());
00159                 $this->setDate(time());
00160 
00161                 // Step one create folder
00162                 $this->initCourseFilesObject();
00163                 $this->course_files_obj->addDirectory($this->getName());
00164 
00165                 // Step two create course xml
00166                 $this->initCourseXMLWriter();
00167 
00168                 $this->course_xml_writer->start();
00169                 $this->course_files_obj->writeToFile($this->course_xml_writer->getXML(),$this->getName().'/'.$this->getName().'.xml');
00170 
00171         
00172                 // Step three create child object xml
00173                 // add objects directory
00174                 $this->course_files_obj->addDirectory($this->getName().'/objects');
00175                 
00176                 $this->__addZipFiles($this->course_obj->getRefId());
00177 
00178 
00179                 // Step four zip
00180                 $this->setSize($this->course_files_obj->zipFile($this->getName(),$this->getName().'.zip'));
00181                 
00182                 
00183                 // Finally add entry in crs_archives table
00184                 $this->add();
00185 
00186                 return true;
00187         }
00188 
00189         function addHTML()
00190         {
00191                 $this->setType($this->ARCHIVE_HTML);
00192                 $this->setDate(time());
00193                 $this->setName($this->getDate().'__'.$this->ilias->getSetting('inst_id').'__crs_'.$this->course_obj->getId());
00194                 
00195                 // Step one create folder
00196                 $this->initCourseFilesObject();
00197                 $this->course_files_obj->addDirectory($this->getName());
00198 
00199                 // Step two, create child html
00200                 $this->course_files_obj->addDirectory($this->getName().'/objects');
00201                 $this->__addHTMLFiles($this->course_obj->getRefId());
00202 
00203                 // Step three create course html
00204                 $this->__addCourseHTML();
00205 
00206                 // Step three ² create copy in web dir
00207                 $this->course_files_obj->createOnlineVersion($this->getName());
00208 
00209                 // Step four zip
00210                 $this->setSize($this->course_files_obj->zipFile($this->getName(),$this->getName().'.zip'));
00211 
00212                 // Finally add entry in crs_archives table
00213                 $this->add();
00214                 
00215                 return true;
00216         }
00217 
00218 
00219         function add()
00220         {
00221                 $query = "INSERT INTO crs_archives ".
00222                         "VALUES ('','".$this->course_obj->getId()."','".$this->getName()."','".$this->getType()."','".
00223                         $this->getDate()."','".$this->getSize()."','".$this->getLanguage()."')";
00224 
00225                 $this->ilDB->query($query);
00226                 $this->__read();
00227 
00228                 return true;
00229         }
00230 
00231         function delete($a_id)
00232         {
00233                 // Delete in file system
00234                 $this->initCourseFilesObject();
00235 
00236                 $this->course_files_obj->deleteArchive($this->archives[$a_id]["archive_name"]);
00237 
00238                 $query = "DELETE FROM crs_archives ".
00239                         "WHERE course_id = '".$this->course_obj->getId()."' ".
00240                         "AND archive_id = '".$a_id."'";
00241                 
00242                 $this->ilDB->query($query);
00243                 $this->__read();
00244                 
00245                 return true;
00246         }
00247 
00248         function deleteAll()
00249         {
00250                 foreach($this->getArchives() as $id => $archive)
00251                 {
00252                         $this->delete($id);
00253                 }
00254         }
00255         
00256         function initCourseFilesObject()
00257         {
00258                 if(!is_object($this->course_files_obj))
00259                 {
00260                         include_once "./course/classes/class.ilFileDataCourse.php";
00261 
00262                         $this->course_files_obj =& new ilFileDataCourse($this->course_obj);
00263                 }
00264                 return true;
00265         }
00266 
00267         function initCourseXMLWriter()
00268         {
00269                 if(!is_object($this->course_xml_writer))
00270                 {
00271                         include_once "./course/classes/class.ilCourseXMLWriter.php";
00272 
00273                         $this->course_xml_writer =& new ilCourseXMLWriter($this->course_obj);
00274                 }
00275                 return true;
00276         }
00277 
00278         // PRIVATE
00279         function __addZipFiles($a_parent_id)
00280         {
00281                 $this->course_obj->initCourseItemObject();
00282                 $this->course_obj->items_obj->setParentId($a_parent_id);
00283 
00284                 foreach($this->course_obj->items_obj->getAllItems() as $item)
00285                 {
00286                         if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
00287                         {
00288                                 continue;
00289                         }
00290                         
00291                         // must return absolute path to zip file
00292                         if($abs_file_name = $tmp_obj->getXMLZip())
00293                         {
00294                                 $new_name = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['obj_id'].'.zip';
00295                                 $this->course_files_obj->copy($abs_file_name,$this->getName().'/objects/'.$new_name);
00296                         }
00297                         $this->__addZipFiles($item['child']);
00298                         unset($tmp_obj);
00299                 }
00300                 return true;
00301         }
00302 
00303         function __addHTMLFiles($a_parent_id)
00304         {
00305                 $this->course_obj->initCourseItemObject();
00306                 $this->course_obj->items_obj->setParentId($a_parent_id);
00307                 
00308                 foreach($this->course_obj->items_obj->getAllItems() as $item)
00309                 {
00310                         if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
00311                         {
00312                                 continue;
00313                         }
00314                         if($abs_dir_name = $tmp_obj->getHTMLDirectory())
00315                         {
00316                                 $new_name = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['obj_id'];
00317 
00318                                 $this->course_files_obj->addDirectory($this->getName().'/objects/'.$new_name);
00319                                 $this->course_files_obj->rCopy($abs_dir_name,$this->getName().'/objects/'.$new_name);
00320 
00321                                 // Store filename in hashtable (used for create course html tree)
00322                                 $this->html_files["$item[obj_id]"] = "objects/".$new_name."/index.html";
00323                         }
00324                         $this->__addHTMLFiles($item['child']);
00325                         unset($tmp_obj);
00326                 }
00327                 return true;
00328         }
00329 
00330         function __addCourseHTML()
00331         {
00332                 global $tpl;
00333 
00334                 // Get Language
00335                 if($this->getLanguage())
00336                 {
00337                         $lng =& new ilLanguage($this->getLanguage());
00338                         $lng->loadLanguageModule('crs');
00339                 }
00340                 else
00341                 {
00342                         $lng =& $this->lng;
00343                 }
00344 
00345                 $tmp_tpl =& new ilTemplate("tpl.crs_export.html",true,true,"course");
00346 
00347                 $this->course_files_obj->copy($tpl->tplPath.'/default.css',$this->getName().'/default.css');
00348 
00349                 $tmp_tpl->setVariable('TITLE',$lng->txt('crs_export'));
00350                 $tmp_tpl->setVariable("CRS_STRUCTURE",$lng->txt('crs_structure'));
00351 
00352 
00353                 $tmp_tpl->setVariable("DETAILS_TITLE",$lng->txt("crs_details"));
00354                 #$tmp_tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_crs_b.gif'));
00355                 #$tmp_tpl->setVariable("ALT_IMG",$lng->txt("crs_details"));
00356                 
00357                 // SET TXT VARIABLES
00358                 $tmp_tpl->setVariable("TXT_SYLLABUS",$lng->txt("crs_syllabus"));
00359                 $tmp_tpl->setVariable("TXT_CONTACT",$lng->txt("crs_contact"));
00360                 $tmp_tpl->setVariable("TXT_CONTACT_NAME",$lng->txt("crs_contact_name"));
00361                 $tmp_tpl->setVariable("TXT_CONTACT_RESPONSIBILITY",$lng->txt("crs_contact_responsibility"));
00362                 $tmp_tpl->setVariable("TXT_CONTACT_EMAIL",$lng->txt("crs_contact_email"));
00363                 $tmp_tpl->setVariable("TXT_CONTACT_PHONE",$lng->txt("crs_contact_phone"));
00364                 $tmp_tpl->setVariable("TXT_CONTACT_CONSULTATION",$lng->txt("crs_contact_consultation"));
00365                 $tmp_tpl->setVariable("TXT_DATES",$lng->txt("crs_dates"));
00366                 $tmp_tpl->setVariable("TXT_ACTIVATION",$lng->txt("crs_activation"));
00367                 $tmp_tpl->setVariable("TXT_SUBSCRIPTION",$lng->txt("crs_subscription"));
00368                 $tmp_tpl->setVariable("TXT_ARCHIVE",$lng->txt("crs_archive"));
00369 
00370                 // FILL 
00371                 $tmp_tpl->setVariable("SYLLABUS",nl2br($this->course_obj->getSyllabus() ? 
00372                                                                                                  $this->course_obj->getSyllabus() : 
00373                                                                                                  $lng->txt("crs_not_available")));
00374 
00375                 $tmp_tpl->setVariable("CONTACT_NAME",$this->course_obj->getContactName() ? 
00376                                                                 $this->course_obj->getContactName() : 
00377                                                                 $lng->txt("crs_not_available"));
00378                 $tmp_tpl->setVariable("CONTACT_RESPONSIBILITY",$this->course_obj->getContactResponsibility() ? 
00379                                                                 $this->course_obj->getContactResponsibility() : 
00380                                                                 $lng->txt("crs_not_available"));
00381                 $tmp_tpl->setVariable("CONTACT_PHONE",$this->course_obj->getContactPhone() ? 
00382                                                                 $this->course_obj->getContactPhone() : 
00383                                                                 $lng->txt("crs_not_available"));
00384                 $tmp_tpl->setVariable("CONTACT_CONSULTATION",nl2br($this->course_obj->getContactConsultation() ? 
00385                                                                 $this->course_obj->getContactConsultation() : 
00386                                                                 $lng->txt("crs_not_available")));
00387                 if($this->course_obj->getContactEmail())
00388                 {
00389                         $tmp_tpl->setCurrentBlock("email_link");
00390                         #$tmp_tpl->setVariable("EMAIL_LINK","mail_new.php?type=new&rcp_to=".$this->course_obj->getContactEmail());
00391                         $tmp_tpl->setVariable("CONTACT_EMAIL",$this->course_obj->getContactEmail());
00392                         $tmp_tpl->parseCurrentBlock();
00393                 }
00394                 else
00395                 {
00396                         $tmp_tpl->setCurrentBlock("no_mail");
00397                         $tmp_tpl->setVariable("NO_CONTACT_EMAIL",$this->course_obj->getContactEmail());
00398                         $tmp_tpl->parseCurrentBlock();
00399                 }
00400                 if($this->course_obj->getActivationUnlimitedStatus())
00401                 {
00402                         $tmp_tpl->setVariable("ACTIVATION",$lng->txt('crs_unlimited'));
00403                 }
00404                 else
00405                 {
00406                         $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getActivationStart())." ".
00407                                 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getActivationEnd());
00408                         $tmp_tpl->setVariable("ACTIVATION",$str);
00409                 }
00410                 if($this->course_obj->getSubscriptionUnlimitedStatus())
00411                 {
00412                         $tmp_tpl->setVariable("SUBSCRIPTION",$lng->txt('crs_unlimited'));
00413                 }
00414                 else
00415                 {
00416                         $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getSubscriptionStart())." ".
00417                                 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getSubscriptionEnd());
00418                         $tmp_tpl->setVariable("SUBSCRIPTION",$str);
00419                 }
00420                 if($this->course_obj->getArchiveType() == $this->course_obj->ARCHIVE_DISABLED)
00421                 {
00422                         $tmp_tpl->setVariable("ARCHIVE",$lng->txt('crs_archive_disabled'));
00423                 }
00424                 else
00425                 {
00426                         $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getArchiveStart())." ".
00427                                 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getArchiveEnd());
00428                         $tmp_tpl->setVariable("ARCHIVE",$str);
00429                 }
00430 
00431                 $this->structure = '';
00432                 $this->__buildStructure($tmp_tpl,$this->course_obj->getRefId());
00433                 $tmp_tpl->setVariable("STRUCTURE",$this->structure);
00434 
00435                 $this->course_files_obj->writeToFile($tmp_tpl->get(),$this->getName().'/index.html');
00436 
00437                 return true;
00438         }
00439 
00440         function __buildStructure(&$tmp_tpl,$a_parent_id)
00441         {
00442                 $this->course_obj->initCourseItemObject();
00443                 $this->course_obj->items_obj->setParentId($a_parent_id);
00444                 
00445                 $items = $this->course_obj->items_obj->getAllItems();
00446 
00447                 foreach($items as $key => $item)
00448                 {
00449                         if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
00450                         {
00451                                 continue;
00452                         }
00453 
00454 
00455                         if($key == 0)
00456                         {
00457                                 $this->structure .= "<ul>";
00458                         }
00459 
00460                         $this->structure .= "<li>";
00461 
00462                         if(isset($this->html_files["$item[obj_id]"]))
00463                         {
00464                                 $link = "<a href=\"./".$this->html_files["$item[obj_id]"]."\">".$item["title"]."</a>";
00465                         }
00466                         else
00467                         {
00468                                 $link = $item['title'];
00469                         }
00470                         $this->structure .= $link;
00471                         $this->structure .= "</li>";
00472 
00473                         $this->__buildStructure($tmp_tpl,$item['child']);
00474 
00475                         if($key == (count($items) - 1))
00476                         {
00477                                 $this->structure .= "</ul>";
00478                         }
00479                 
00480 
00481                         unset($tmp_obj);
00482                 }
00483                 return true;
00484         }
00485 
00486 
00487         function __read()
00488         {
00489                 $this->archives = array();
00490 
00491                 $query = "SELECT * FROM crs_archives ".
00492                         "WHERE course_id = '".$this->course_obj->getId()."' ".
00493                         "ORDER BY archive_date";
00494 
00495                 $res = $this->ilDB->query($query);
00496                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00497                 {
00498                         $this->archives[$row->archive_id]["archive_type"]       = $row->archive_type;
00499                         $this->archives[$row->archive_id]["archive_date"]       = $row->archive_date;
00500                         $this->archives[$row->archive_id]["archive_size"]       = $row->archive_size;
00501                         $this->archives[$row->archive_id]["archive_name"]       = $row->archive_name;
00502                         $this->archives[$row->archive_id]["archive_lang"]       = $row->archive_lang;
00503                 }
00504                 return true;
00505         }
00506 }
00507 ?>

Generated on Fri Dec 13 2013 09:06:36 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1