• 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                         if($abs_file_name = $tmp_obj->getXMLZip())
00292                         {
00293                                 $new_name = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['obj_id'].'.zip';
00294                                 $this->course_files_obj->copy($abs_file_name,$this->getName().'/objects/'.$new_name);
00295                         }
00296                         $this->__addZipFiles($item['child']);
00297                         unset($tmp_obj);
00298                 }
00299                 return true;
00300         }
00301 
00302         function __addHTMLFiles($a_parent_id)
00303         {
00304                 $this->course_obj->initCourseItemObject();
00305                 $this->course_obj->items_obj->setParentId($a_parent_id);
00306                 
00307                 foreach($this->course_obj->items_obj->getAllItems() as $item)
00308                 {
00309                         if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
00310                         {
00311                                 continue;
00312                         }
00313                         if($abs_dir_name = $tmp_obj->getHTMLDirectory())
00314                         {
00315                                 $new_name = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['obj_id'];
00316 
00317                                 $this->course_files_obj->addDirectory($this->getName().'/objects/'.$new_name);
00318                                 $this->course_files_obj->rCopy($abs_dir_name,$this->getName().'/objects/'.$new_name);
00319 
00320                                 // Store filename in hashtable (used for create course html tree)
00321                                 $this->html_files["$item[obj_id]"] = "objects/".$new_name."/index.html";
00322                         }
00323                         $this->__addHTMLFiles($item['child']);
00324                         unset($tmp_obj);
00325                 }
00326                 return true;
00327         }
00328 
00329         function __addCourseHTML()
00330         {
00331                 global $tpl;
00332 
00333                 // Get Language
00334                 if($this->getLanguage())
00335                 {
00336                         $lng =& new ilLanguage($this->getLanguage());
00337                         $lng->loadLanguageModule('crs');
00338                 }
00339                 else
00340                 {
00341                         $lng =& $this->lng;
00342                 }
00343 
00344                 $tmp_tpl =& new ilTemplate("tpl.crs_export.html",true,true,"course");
00345 
00346                 $this->course_files_obj->copy($tpl->tplPath.'/default.css',$this->getName().'/default.css');
00347 
00348                 $tmp_tpl->setVariable('TITLE',$lng->txt('crs_export'));
00349                 $tmp_tpl->setVariable("CRS_STRUCTURE",$lng->txt('crs_structure'));
00350 
00351 
00352                 $tmp_tpl->setVariable("DETAILS_TITLE",$lng->txt("crs_details"));
00353                 #$tmp_tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_crs_b.gif'));
00354                 #$tmp_tpl->setVariable("ALT_IMG",$lng->txt("crs_details"));
00355                 
00356                 // SET TXT VARIABLES
00357                 $tmp_tpl->setVariable("TXT_SYLLABUS",$lng->txt("crs_syllabus"));
00358                 $tmp_tpl->setVariable("TXT_CONTACT",$lng->txt("crs_contact"));
00359                 $tmp_tpl->setVariable("TXT_CONTACT_NAME",$lng->txt("crs_contact_name"));
00360                 $tmp_tpl->setVariable("TXT_CONTACT_RESPONSIBILITY",$lng->txt("crs_contact_responsibility"));
00361                 $tmp_tpl->setVariable("TXT_CONTACT_EMAIL",$lng->txt("crs_contact_email"));
00362                 $tmp_tpl->setVariable("TXT_CONTACT_PHONE",$lng->txt("crs_contact_phone"));
00363                 $tmp_tpl->setVariable("TXT_CONTACT_CONSULTATION",$lng->txt("crs_contact_consultation"));
00364                 $tmp_tpl->setVariable("TXT_DATES",$lng->txt("crs_dates"));
00365                 $tmp_tpl->setVariable("TXT_ACTIVATION",$lng->txt("crs_activation"));
00366                 $tmp_tpl->setVariable("TXT_SUBSCRIPTION",$lng->txt("crs_subscription"));
00367                 $tmp_tpl->setVariable("TXT_ARCHIVE",$lng->txt("crs_archive"));
00368 
00369                 // FILL 
00370                 $tmp_tpl->setVariable("SYLLABUS",nl2br($this->course_obj->getSyllabus() ? 
00371                                                                                                  $this->course_obj->getSyllabus() : 
00372                                                                                                  $lng->txt("crs_not_available")));
00373 
00374                 $tmp_tpl->setVariable("CONTACT_NAME",$this->course_obj->getContactName() ? 
00375                                                                 $this->course_obj->getContactName() : 
00376                                                                 $lng->txt("crs_not_available"));
00377                 $tmp_tpl->setVariable("CONTACT_RESPONSIBILITY",$this->course_obj->getContactResponsibility() ? 
00378                                                                 $this->course_obj->getContactResponsibility() : 
00379                                                                 $lng->txt("crs_not_available"));
00380                 $tmp_tpl->setVariable("CONTACT_PHONE",$this->course_obj->getContactPhone() ? 
00381                                                                 $this->course_obj->getContactPhone() : 
00382                                                                 $lng->txt("crs_not_available"));
00383                 $tmp_tpl->setVariable("CONTACT_CONSULTATION",nl2br($this->course_obj->getContactConsultation() ? 
00384                                                                 $this->course_obj->getContactConsultation() : 
00385                                                                 $lng->txt("crs_not_available")));
00386                 if($this->course_obj->getContactEmail())
00387                 {
00388                         $tmp_tpl->setCurrentBlock("email_link");
00389                         #$tmp_tpl->setVariable("EMAIL_LINK","mail_new.php?type=new&rcp_to=".$this->course_obj->getContactEmail());
00390                         $tmp_tpl->setVariable("CONTACT_EMAIL",$this->course_obj->getContactEmail());
00391                         $tmp_tpl->parseCurrentBlock();
00392                 }
00393                 else
00394                 {
00395                         $tmp_tpl->setCurrentBlock("no_mail");
00396                         $tmp_tpl->setVariable("NO_CONTACT_EMAIL",$this->course_obj->getContactEmail());
00397                         $tmp_tpl->parseCurrentBlock();
00398                 }
00399                 if($this->course_obj->getActivationUnlimitedStatus())
00400                 {
00401                         $tmp_tpl->setVariable("ACTIVATION",$lng->txt('crs_unlimited'));
00402                 }
00403                 else
00404                 {
00405                         $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getActivationStart())." ".
00406                                 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getActivationEnd());
00407                         $tmp_tpl->setVariable("ACTIVATION",$str);
00408                 }
00409                 if($this->course_obj->getSubscriptionUnlimitedStatus())
00410                 {
00411                         $tmp_tpl->setVariable("SUBSCRIPTION",$lng->txt('crs_unlimited'));
00412                 }
00413                 else
00414                 {
00415                         $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getSubscriptionStart())." ".
00416                                 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getSubscriptionEnd());
00417                         $tmp_tpl->setVariable("SUBSCRIPTION",$str);
00418                 }
00419                 if($this->course_obj->getArchiveType() == $this->course_obj->ARCHIVE_DISABLED)
00420                 {
00421                         $tmp_tpl->setVariable("ARCHIVE",$lng->txt('crs_archive_disabled'));
00422                 }
00423                 else
00424                 {
00425                         $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getArchiveStart())." ".
00426                                 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getArchiveEnd());
00427                         $tmp_tpl->setVariable("ARCHIVE",$str);
00428                 }
00429 
00430                 $this->structure = '';
00431                 $this->__buildStructure($tmp_tpl,$this->course_obj->getRefId());
00432                 $tmp_tpl->setVariable("STRUCTURE",$this->structure);
00433 
00434                 $this->course_files_obj->writeToFile($tmp_tpl->get(),$this->getName().'/index.html');
00435 
00436                 return true;
00437         }
00438 
00439         function __buildStructure(&$tmp_tpl,$a_parent_id)
00440         {
00441                 $this->course_obj->initCourseItemObject();
00442                 $this->course_obj->items_obj->setParentId($a_parent_id);
00443                 
00444                 $items = $this->course_obj->items_obj->getAllItems();
00445 
00446                 foreach($items as $key => $item)
00447                 {
00448                         if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
00449                         {
00450                                 continue;
00451                         }
00452 
00453 
00454                         if($key == 0)
00455                         {
00456                                 $this->structure .= "<ul>";
00457                         }
00458 
00459                         $this->structure .= "<li>";
00460 
00461                         if(isset($this->html_files["$item[obj_id]"]))
00462                         {
00463                                 $link = "<a href=\"./".$this->html_files["$item[obj_id]"]."\">".$item["title"]."</a>";
00464                         }
00465                         else
00466                         {
00467                                 $link = $item['title'];
00468                         }
00469                         $this->structure .= $link;
00470                         $this->structure .= "</li>";
00471 
00472                         $this->__buildStructure($tmp_tpl,$item['child']);
00473 
00474                         if($key == (count($items) - 1))
00475                         {
00476                                 $this->structure .= "</ul>";
00477                         }
00478                 
00479 
00480                         unset($tmp_obj);
00481                 }
00482                 return true;
00483         }
00484 
00485 
00486         function __read()
00487         {
00488                 $this->archives = array();
00489 
00490                 $query = "SELECT * FROM crs_archives ".
00491                         "WHERE course_id = '".$this->course_obj->getId()."' ".
00492                         "ORDER BY archive_date";
00493 
00494                 $res = $this->ilDB->query($query);
00495                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00496                 {
00497                         $this->archives[$row->archive_id]["archive_type"]       = $row->archive_type;
00498                         $this->archives[$row->archive_id]["archive_date"]       = $row->archive_date;
00499                         $this->archives[$row->archive_id]["archive_size"]       = $row->archive_size;
00500                         $this->archives[$row->archive_id]["archive_name"]       = $row->archive_name;
00501                         $this->archives[$row->archive_id]["archive_lang"]       = $row->archive_lang;
00502                 }
00503                 return true;
00504         }
00505 }
00506 ?>

Generated on Fri Dec 13 2013 08:00:16 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1