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

content/classes/class.ilObjGlossary.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 require_once("classes/class.ilObject.php");
00025 //require_once("classes/class.ilMetaData.php");
00026 require_once("./content/classes/class.ilGlossaryTerm.php");
00027 
00036 class ilObjGlossary extends ilObject
00037 {
00038 
00043         function ilObjGlossary($a_id = 0,$a_call_by_reference = true)
00044         {
00045                 $this->type = "glo";
00046                 $this->ilObject($a_id,$a_call_by_reference);
00047         }
00048 
00052         function create($a_upload = false)
00053         {
00054                 global $ilDB;
00055 
00056                 parent::create();
00057                 
00058                 // meta data will be created by
00059                 // import parser
00060                 if (!$a_upload)
00061                 {
00062                         $this->createMetaData();
00063                 }
00064                 
00065                 $q = "INSERT INTO glossary (id, online, virtual) VALUES ".
00066                         " (".$ilDB->quote($this->getId()).",".$ilDB->quote("n").",".$ilDB->quote($this->getVirtualMode()).")";
00067                 $ilDB->query($q);
00068 
00069         }
00070 
00074         function read()
00075         {
00076                 parent::read();
00077 #               echo "Glossary<br>\n";
00078 
00079                 $q = "SELECT * FROM glossary WHERE id = '".$this->getId()."'";
00080                 $gl_set = $this->ilias->db->query($q);
00081                 $gl_rec = $gl_set->fetchRow(DB_FETCHMODE_ASSOC);
00082                 $this->setOnline(ilUtil::yn2tf($gl_rec["online"]));
00083                 $this->setVirtualMode($gl_rec["virtual"]);
00084                 $this->setPublicExportFile("xml", $gl_rec["public_xml_file"]);
00085                 $this->setPublicExportFile("html", $gl_rec["public_html_file"]);
00086                 $this->setActiveGlossaryMenu(ilUtil::yn2tf($gl_rec["glo_menu_active"]));
00087                 $this->setActiveDownloads(ilUtil::yn2tf($gl_rec["downloads_active"]));
00088         }
00089 
00095         function getDescription()
00096         {
00097                 return parent::getDescription();
00098         }
00099 
00103         function setDescription($a_description)
00104         {
00105                 parent::setDescription($a_description);
00106         }
00107 
00108         
00112         function setVirtualMode($a_mode)
00113         {
00114                 switch ($a_mode)
00115                 {
00116                         case "level":
00117                         case "subtree":
00118                         // case "fixed":
00119                                 $this->virtual_mode = $a_mode;
00120                                 $this->virtual = true;
00121                                 break;
00122                                 
00123                         default:
00124                                 $this->virtual_mode = "none";
00125                                 $this->virtual = false;
00126                                 break;
00127                 }
00128         }
00129         
00133         function getVirtualMode()
00134         {
00135                 return $this->virtual_mode;
00136         }
00137         
00141         function isVirtual()
00142         {
00143                 return $this->virtual;
00144         }
00145 
00151         function getTitle()
00152         {
00153                 return parent::getTitle();
00154         }
00155 
00159         function setTitle($a_title)
00160         {
00161                 parent::setTitle($a_title);
00162 //              $this->meta_data->setTitle($a_title);
00163         }
00164 
00165         function setOnline($a_online)
00166         {
00167                 $this->online = $a_online;
00168         }
00169 
00170         function getOnline()
00171         {
00172                 return $this->online;
00173         }
00174 
00178         function _lookupOnline($a_id)
00179         {
00180                 global $ilDB;
00181 
00182                 $q = "SELECT * FROM glossary WHERE id = '".$a_id."'";
00183                 $lm_set = $ilDB->query($q);
00184                 $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
00185 
00186                 return ilUtil::yn2tf($lm_rec["online"]);
00187         }
00188         
00189         function setActiveGlossaryMenu($a_act_glo_menu)
00190         {
00191                 $this->glo_menu_active = $a_act_glo_menu;
00192         }
00193 
00194         function isActiveGlossaryMenu()
00195         {
00196                 return $this->glo_menu_active;
00197         }
00198 
00199         function setActiveDownloads($a_down)
00200         {
00201                 $this->downloads_active = $a_down;
00202         }
00203 
00204         function isActiveDownloads()
00205         {
00206                 return $this->downloads_active;
00207         }
00208 
00214 /*
00215         function assignMetaData(&$a_meta_data)
00216         {
00217                 $this->meta_data =& $a_meta_data;
00218         }
00219 */
00220 
00226 /*
00227         function &getMetaData()
00228         {
00229                 $this->initMeta();
00230                 return $this->meta_data;
00231         }
00232 */
00233 
00237         function update()
00238         {
00239                 $this->updateMetaData();
00240 
00241                 $q = "UPDATE glossary SET ".
00242                         " online = '".ilUtil::tf2yn($this->getOnline())."',".
00243                         " virtual = '".$this->getVirtualMode()."',".
00244                         " public_xml_file = '".$this->getPublicExportFile("xml")."',".
00245                         " public_html_file = '".$this->getPublicExportFile("html")."',".
00246                         " glo_menu_active = '".ilUtil::tf2yn($this->isActiveGlossaryMenu())."',".
00247                         " downloads_active = '".ilUtil::tf2yn($this->isActiveDownloads())."'".
00248                         " WHERE id = '".$this->getId()."'";
00249                 $this->ilias->db->query($q);
00250                 
00251                 parent::update();
00252         }
00253 
00254 
00258         function getTermList($searchterm="")
00259         {
00260                 if ($this->isVirtual())
00261                 {
00262                         global $tree;
00263                         
00264                         $glo_ids = array();
00265                         
00266                         switch ($this->getVirtualMode())
00267                         {
00268                                 case "level":
00269                                         $glo_arr = $tree->getChildsByType($tree->getParentId($this->getRefId()),"glo");
00270                                         
00271                                         foreach ($glo_arr as $glo)
00272                                         {
00273                                                 {
00274                                                         $glo_ids[] = $glo['obj_id'];
00275                                                 }
00276                                         }
00277                                         break;
00278 
00279                                 case "subtree":
00280                                         $subtree_nodes = $tree->getSubTree($tree->getNodeData($tree->getParentId($this->getRefId())));
00281 
00282                                         foreach ($subtree_nodes as $node)
00283                                         {
00284                                                 if ($node['type'] == 'glo')
00285                                                 {
00286                                                         $glo_ids[] = $node['obj_id'];
00287                                                 }
00288                                         }
00289                                         break;
00290                                 
00291 /* for futere enhancements
00292                                 case "fixed":
00293                                         
00294                                         break;
00295 */
00296                                 // fallback to none virtual mode in case of error
00297                                 default:
00298                                         $glo_ids[] = $this->getId();
00299                                         break;
00300                         }
00301                 }
00302                 else
00303                 {
00304                         $glo_ids = $this->getId();
00305                 }
00306                 
00307                 $list = ilGlossaryTerm::getTermList($glo_ids,$searchterm);
00308                 return $list;
00309         }
00310 
00316         function createImportDirectory()
00317         {
00318                 $glo_data_dir = ilUtil::getDataDir()."/glo_data";
00319                 ilUtil::makeDir($glo_data_dir);
00320                 if(!is_writable($glo_data_dir))
00321                 {
00322                         $this->ilias->raiseError("Glossary Data Directory (".$glo_data_dir
00323                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00324                 }
00325 
00326                 // create glossary directory (data_dir/glo_data/glo_<id>)
00327                 $glo_dir = $glo_data_dir."/glo_".$this->getId();
00328                 ilUtil::makeDir($glo_dir);
00329                 if(!@is_dir($glo_dir))
00330                 {
00331                         $this->ilias->raiseError("Creation of Glossary Directory failed.",$this->ilias->error_obj->FATAL);
00332                 }
00333                 // create Import subdirectory (data_dir/glo_data/glo_<id>/import)
00334                 $import_dir = $glo_dir."/import";
00335                 ilUtil::makeDir($import_dir);
00336                 if(!@is_dir($import_dir))
00337                 {
00338                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00339                 }
00340         }
00341 
00345         function getImportDirectory()
00346         {
00347                 $export_dir = ilUtil::getDataDir()."/glo_data"."/glo_".$this->getId()."/import";
00348 
00349                 return $export_dir;
00350         }
00351 
00357         function createExportDirectory($a_type = "xml")
00358         {
00359                 $glo_data_dir = ilUtil::getDataDir()."/glo_data";
00360                 ilUtil::makeDir($glo_data_dir);
00361                 if(!is_writable($glo_data_dir))
00362                 {
00363                         $this->ilias->raiseError("Glossary Data Directory (".$glo_data_dir
00364                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00365                 }
00366                 // create glossary directory (data_dir/glo_data/glo_<id>)
00367                 $glo_dir = $glo_data_dir."/glo_".$this->getId();
00368                 ilUtil::makeDir($glo_dir);
00369                 if(!@is_dir($glo_dir))
00370                 {
00371                         $this->ilias->raiseError("Creation of Glossary Directory failed.",$this->ilias->error_obj->FATAL);
00372                 }
00373 
00374                 // create Export subdirectory (data_dir/glo_data/glo_<id>/Export)
00375                 switch ($a_type)
00376                 {
00377                         // html
00378                         case "html":
00379                                 $export_dir = $glo_dir."/export_html";
00380                                 break;
00381                                 
00382                         default:                // = xml
00383                                 $export_dir = $glo_dir."/export";
00384                                 break;
00385                 }
00386                 ilUtil::makeDir($export_dir);
00387 
00388                 if(!@is_dir($export_dir))
00389                 {
00390                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00391                 }
00392         }
00393 
00397         function getExportDirectory($a_type = "xml")
00398         {
00399                 switch  ($a_type)
00400                 {
00401                         case "html":
00402                                 $export_dir = ilUtil::getDataDir()."/glo_data"."/glo_".$this->getId()."/export_html";
00403                                 break;
00404 
00405                         default:                        // = xml
00406                                 $export_dir = ilUtil::getDataDir()."/glo_data"."/glo_".$this->getId()."/export";
00407                                 break;
00408                 }
00409 
00410                 return $export_dir;
00411         }
00412 
00416         function getExportFiles()
00417         {
00418                 // initialize array
00419                 $file = array();
00420                 
00421                 $types = array("xml", "html");
00422 
00423                 foreach($types as $type)
00424                 {
00425                         $dir = $this->getExportDirectory($type);
00426                         
00427                         // quit if import dir not available
00428                         if (!@is_dir($dir) or
00429                                 !is_writeable($dir))
00430                         {
00431                                 continue;
00432                         }
00433 
00434                         // open directory
00435                         $h_dir = dir($dir);
00436 
00437                         // get files and save the in the array
00438                         while ($entry = $h_dir->read())
00439                         {
00440                                 if ($entry != "." and
00441                                         $entry != ".." and
00442                                         substr($entry, -4) == ".zip" and
00443                                         ereg("^[0-9]{10}_{2}[0-9]+_{2}(glo_)*[0-9]+\.zip\$", $entry))
00444                                 {
00445                                         $file[$entry.$type] = array("type" => $type, "file" => $entry,
00446                                                 "size" => filesize($dir."/".$entry));
00447                                 }
00448                         }
00449         
00450                         // close import directory
00451                         $h_dir->close();
00452                 }
00453 
00454                 // sort files
00455                 ksort ($file);
00456                 reset ($file);
00457                 return $file;
00458         }
00459         
00466         function setPublicExportFile($a_type, $a_file)
00467         {
00468                 $this->public_export_file[$a_type] = $a_file;
00469         }
00470 
00478         function getPublicExportFile($a_type)
00479         {
00480                 return $this->public_export_file[$a_type];
00481         }
00482 
00486         function exportHTML($a_target_dir, $log)
00487         {
00488                 global $ilias, $tpl;
00489 
00490                 // initialize temporary target directory
00491                 ilUtil::delDir($a_target_dir);
00492                 ilUtil::makeDir($a_target_dir);
00493                 $mob_dir = $a_target_dir."/mobs";
00494                 ilUtil::makeDir($mob_dir);
00495                 $file_dir = $a_target_dir."/files";
00496                 ilUtil::makeDir($file_dir);
00497 
00498                 // export system style sheet
00499                 $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
00500                 $style_name = $ilias->account->prefs["style"].".css";
00501                 copy($location_stylesheet, $a_target_dir."/".$style_name);
00502                 $location_stylesheet = ilUtil::getStyleSheetLocation();
00503                 
00504                 // export content style sheet
00505                 /*
00506                 if ($this->getStyleSheetId() < 1)
00507                 {*/
00508                         $cont_stylesheet = "content/content.css";
00509                         copy($cont_stylesheet, $a_target_dir."/content.css");
00510                 /*}
00511                 else
00512                 {
00513                         $style = new ilObjStyleSheet($this->getStyleSheetId());
00514                         $style->writeCSSFile($a_target_dir."/content.css");
00515                 }*/
00516                 
00517                 // export syntax highlighting style
00518                 $syn_stylesheet = "content/syntaxhighlight.css";
00519                 copy($syn_stylesheet, $a_target_dir."/syntaxhighlight.css");
00520 
00521                 // get glossary presentation gui class
00522                 include_once("content/classes/class.ilGlossaryPresentationGUI.php");
00523                 $_GET["cmd"] = "nop";
00524                 $glo_gui =& new ilGlossaryPresentationGUI();
00525                 $glo_gui->setOfflineMode(true);
00526                 
00527                 // could be implemented in the future if other export
00528                 // formats are supported (e.g. scorm)
00529                 //$glo_gui->setExportFormat($a_export_format);
00530 
00531                 // export terms
00532                 $this->exportHTMLGlossaryTerms($glo_gui, $a_target_dir);
00533                                 
00534                 // export all media objects
00535                 foreach ($this->offline_mobs as $mob)
00536                 {
00537                         $this->exportHTMLMOB($a_target_dir, $glo_gui, $mob, "_new");
00538                 }
00539                 $_GET["obj_type"]  = "MediaObject";
00540                 $_GET["obj_id"]  = $a_mob_id;
00541                 $_GET["cmd"] = "";
00542                 
00543                 // export all file objects
00544                 foreach ($this->offline_files as $file)
00545                 {
00546                         $this->exportHTMLFile($a_target_dir, $file);
00547                 }
00548                 
00549                 // export images
00550                 $image_dir = $a_target_dir."/images";
00551                 ilUtil::makeDir($image_dir);
00552                 ilUtil::makeDir($image_dir."/browser");
00553                 copy(ilUtil::getImagePath("enlarge.gif", false, "filesystem"),
00554                         $image_dir."/enlarge.gif");
00555                 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
00556                         $image_dir."/browser/plus.gif");
00557                 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
00558                         $image_dir."/browser/minus.gif");
00559                 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
00560                         $image_dir."/browser/blank.gif");
00561                 copy(ilUtil::getImagePath("icon_st.gif", false, "filesystem"),
00562                         $image_dir."/icon_st.gif");
00563                 copy(ilUtil::getImagePath("icon_pg.gif", false, "filesystem"),
00564                         $image_dir."/icon_pg.gif");
00565                 copy(ilUtil::getImagePath("nav_arr_L.gif", false, "filesystem"),
00566                         $image_dir."/nav_arr_L.gif");
00567                 copy(ilUtil::getImagePath("nav_arr_R.gif", false, "filesystem"),
00568                         $image_dir."/nav_arr_R.gif");
00569                         
00570                 // template workaround: reset of template 
00571                 $tpl = new ilTemplate("tpl.main.html", true, true);
00572                 $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
00573                 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00574                 
00575                 // zip everything
00576                 if (true)
00577                 {
00578                         // zip it all
00579                         $date = time();
00580                         $zip_file = $this->getExportDirectory("html")."/".$date."__".IL_INST_ID."__".
00581                                 $this->getType()."_".$this->getId().".zip";
00582 //echo "zip-".$a_target_dir."-to-".$zip_file;
00583                         ilUtil::zip($a_target_dir, $zip_file);
00584                         ilUtil::delDir($a_target_dir);
00585                 }
00586         }
00587         
00588 
00592         function exportHTMLGlossaryTerms(&$a_glo_gui, $a_target_dir)
00593         {
00594                 global $ilUser;
00595                 
00596                 // index.html file
00597                 $a_glo_gui->tpl = new ilTemplate("tpl.main.html", true, true);
00598                 $style_name = $ilUser->prefs["style"].".css";;
00599                 $a_glo_gui->tpl->setVariable("LOCATION_STYLESHEET","./".$style_name);
00600                 $a_glo_gui->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00601                 $a_glo_gui->tpl->setVariable("HEADER", $this->getTitle());
00602 
00603                 $content = $a_glo_gui->listTerms();
00604                 $file = $a_target_dir."/index.html";
00605                                                 
00606                 // open file
00607                 if (!($fp = @fopen($file,"w+")))
00608                 {
00609                         die ("<b>Error</b>: Could not open \"".$file."\" for writing".
00610                                 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
00611                 }
00612                 chmod($file, 0770);
00613                 fwrite($fp, $content);
00614                 fclose($fp);
00615                 
00616                 $terms = $this->getTermList();
00617                 
00618                 $this->offline_mobs = array();
00619                 $this->offline_files = array();
00620                 
00621                 foreach($terms as $term)
00622                 {
00623                         $a_glo_gui->tpl = new ilTemplate("tpl.main.html", true, true);
00624                         //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00625                         
00626                         // set style
00627                         $style_name = $ilUser->prefs["style"].".css";;
00628                         $a_glo_gui->tpl->setVariable("LOCATION_STYLESHEET","./".$style_name);
00629 
00630                         $_GET["term_id"] = $term["id"];
00631                         $_GET["frame"] = "_new";
00632                         $content =& $a_glo_gui->listDefinitions();
00633                         $file = $a_target_dir."/term_".$term["id"].".html";
00634                                                         
00635                         // open file
00636                         if (!($fp = @fopen($file,"w+")))
00637                         {
00638                                 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
00639                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
00640                         }
00641                         chmod($file, 0770);
00642                         fwrite($fp, $content);
00643                         fclose($fp);
00644 
00645                         // store linked/embedded media objects of glosssary term
00646                         include_once("content/classes/class.ilGlossaryDefinition.php");
00647                         $defs = ilGlossaryDefinition::getDefinitionList($term["id"]);
00648                         foreach($defs as $def)
00649                         {
00650                                 $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
00651                                 foreach($def_mobs as $def_mob)
00652                                 {
00653                                         $this->offline_mobs[$def_mob] = $def_mob;
00654                                 }
00655                                 
00656                                 // get all files of page
00657                                 include_once("classes/class.ilObjFile.php");
00658                                 $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $def["id"]);
00659                                 $this->offline_files = array_merge($this->offline_files, $def_files);
00660 
00661                         }
00662                 }
00663         }
00664         
00668         function exportHTMLMOB($a_target_dir, &$a_glo_gui, $a_mob_id)
00669         {
00670                 global $tpl;
00671 
00672                 $mob_dir = $a_target_dir."/mobs";
00673 
00674                 $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
00675                 if (@is_dir($source_dir))
00676                 {
00677                         ilUtil::makeDir($mob_dir."/mm_".$a_mob_id);
00678                         ilUtil::rCopy($source_dir, $mob_dir."/mm_".$a_mob_id);
00679                 }
00680                 
00681                 $tpl = new ilTemplate("tpl.main.html", true, true);
00682                 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00683                 $_GET["obj_type"]  = "MediaObject";
00684                 $_GET["mob_id"]  = $a_mob_id;
00685                 $_GET["cmd"] = "";
00686                 $content =& $a_glo_gui->media();
00687                 $file = $a_target_dir."/media_".$a_mob_id.".html";
00688 
00689                 // open file
00690                 if (!($fp = @fopen($file,"w+")))
00691                 {
00692                         die ("<b>Error</b>: Could not open \"".$file."\" for writing".
00693                                 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
00694                 }
00695                 chmod($file, 0770);
00696                 fwrite($fp, $content);
00697                 fclose($fp);
00698                 
00699                 // fullscreen
00700                 include_once("content/classes/Media/class.ilObjMediaObject.php");
00701                 $mob_obj = new ilObjMediaObject($a_mob_id);
00702                 if ($mob_obj->hasFullscreenItem())
00703                 {
00704                         $tpl = new ilTemplate("tpl.main.html", true, true);
00705                         $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00706                         $_GET["mob_id"]  = $a_mob_id;
00707                         $_GET["cmd"] = "fullscreen";
00708                         $content =& $a_glo_gui->fullscreen();
00709                         $file = $a_target_dir."/fullscreen_".$a_mob_id.".html";
00710         
00711                         // open file
00712                         if (!($fp = @fopen($file,"w+")))
00713                         {
00714                                 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
00715                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
00716                         }
00717                         chmod($file, 0770);
00718                         fwrite($fp, $content);
00719                         fclose($fp);
00720                 }
00721         }
00722 
00726         function exportHTMLFile($a_target_dir, $a_file_id)
00727         {
00728                 $file_dir = $a_target_dir."/files/file_".$a_file_id;
00729                 ilUtil::makeDir($file_dir);
00730                 include_once("classes/class.ilObjFile.php");
00731                 $file_obj = new ilObjFile($a_file_id, false);
00732                 $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
00733                 if (!is_file($source_file))
00734                 {
00735                         $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
00736                 }
00737                 copy($source_file, $file_dir."/".$file_obj->getFileName());
00738         }
00739 
00740 
00747         function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00748         {
00749                 global $ilBench;
00750 
00751                 // export glossary
00752                 $attrs = array();
00753                 $attrs["Type"] = "Glossary";
00754                 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
00755 
00756                 // MetaData
00757                 $this->exportXMLMetaData($a_xml_writer);
00758 
00759                 // collect media objects
00760                 $terms = $this->getTermList();
00761                 $this->mob_ids = array();
00762                 $this->file_ids = array();
00763                 foreach ($terms as $term)
00764                 {
00765                         include_once "./content/classes/class.ilGlossaryDefinition.php";
00766                         
00767                         $defs = ilGlossaryDefinition::getDefinitionList($term[id]);
00768 
00769                         foreach($defs as $def)
00770                         {
00771                                 $this->page_object =& new ilPageObject("gdf",
00772                                         $def["id"], $this->halt_on_error);
00773                                 $this->page_object->buildDom();
00774                                 $this->page_object->insertInstIntoIDs(IL_INST_ID);
00775                                 $mob_ids = $this->page_object->collectMediaObjects(false);
00776                                 $file_ids = $this->page_object->collectFileItems();
00777                                 foreach($mob_ids as $mob_id)
00778                                 {
00779                                         $this->mob_ids[$mob_id] = $mob_id;
00780                                 }
00781                                 foreach($file_ids as $file_id)
00782                                 {
00783                                         $this->file_ids[$file_id] = $file_id;
00784                                 }
00785                         }
00786                 }
00787 
00788                 // export media objects
00789                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
00790                 $ilBench->start("GlossaryExport", "exportMediaObjects");
00791                 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
00792                 $ilBench->stop("GlossaryExport", "exportMediaObjects");
00793                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
00794 
00795                 // FileItems
00796                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
00797                 $ilBench->start("ContentObjectExport", "exportFileItems");
00798                 $this->exportFileItems($a_target_dir, $expLog);
00799                 $ilBench->stop("ContentObjectExport", "exportFileItems");
00800                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
00801 
00802                 // Glossary
00803                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Glossary Items");
00804                 $ilBench->start("GlossaryExport", "exportGlossaryItems");
00805                 $this->exportXMLGlossaryItems($a_xml_writer, $a_inst, $expLog);
00806                 $ilBench->stop("GlossaryExport", "exportGlossaryItems");
00807                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Glossary Items");
00808 
00809                 $a_xml_writer->xmlEndTag("ContentObject");
00810         }
00811 
00818         function exportXMLGlossaryItems(&$a_xml_writer, $a_inst, &$expLog)
00819         {
00820                 global $ilBench;
00821 
00822                 $attrs = array();
00823                 $a_xml_writer->xmlStartTag("Glossary", $attrs);
00824 
00825                 // MetaData
00826                 $this->exportXMLMetaData($a_xml_writer);
00827 
00828                 $terms = $this->getTermList();
00829 
00830                 // export glossary terms
00831                 reset($terms);
00832                 foreach ($terms as $term)
00833                 {
00834                         $ilBench->start("GlossaryExport", "exportGlossaryItem");
00835                         $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
00836 
00837                         // export xml to writer object
00838                         $ilBench->start("GlossaryExport", "exportGlossaryItem_getGlossaryTerm");
00839                         $glo_term = new ilGlossaryTerm($term["id"]);
00840                         $ilBench->stop("GlossaryExport", "exportGlossaryItem_getGlossaryTerm");
00841                         $ilBench->start("GlossaryExport", "exportGlossaryItem_XML");
00842                         $glo_term->exportXML($a_xml_writer, $a_inst);
00843                         $ilBench->stop("GlossaryExport", "exportGlossaryItem_XML");
00844 
00845                         // collect all file items
00846                         /*
00847                         $ilBench->start("GlossaryExport", "exportGlossaryItem_CollectFileItems");
00848                         $file_ids = $page_obj->getFileItemIds();
00849                         foreach($file_ids as $file_id)
00850                         {
00851                                 $this->file_ids[$file_id] = $file_id;
00852                         }
00853                         $ilBench->stop("GlossaryExport", "exportGlossaryItem_CollectFileItems");
00854                         */
00855 
00856                         unset($glo_term);
00857 
00858                         $ilBench->stop("GlossaryExport", "exportGlossaryItem");
00859                 }
00860 
00861                 $a_xml_writer->xmlEndTag("Glossary");
00862         }
00863 
00870         function exportXMLMetaData(&$a_xml_writer)
00871         {
00872                 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00873                 $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
00874                 $md2xml->setExportMode(true);
00875                 $md2xml->startExport();
00876                 $a_xml_writer->appendXML($md2xml->getXML());
00877         }
00878 
00885         function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00886         {
00887                 include_once("content/classes/Media/class.ilObjMediaObject.php");
00888 
00889                 foreach ($this->mob_ids as $mob_id)
00890                 {
00891                         $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
00892                         $media_obj = new ilObjMediaObject($mob_id);
00893                         $media_obj->exportXML($a_xml_writer, $a_inst);
00894                         $media_obj->exportFiles($a_target_dir);
00895                         unset($media_obj);
00896                 }
00897         }
00898 
00903         function exportFileItems($a_target_dir, &$expLog)
00904         {
00905                 include_once("classes/class.ilObjFile.php");
00906 
00907                 foreach ($this->file_ids as $file_id)
00908                 {
00909                         $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
00910                         $file_obj = new ilObjFile($file_id, false);
00911                         $file_obj->export($a_target_dir);
00912                         unset($file_obj);
00913                 }
00914         }
00915 
00916 
00917 
00921         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00922         {
00923                 if ($a_tag == "Identifier" && $a_param == "Entry")
00924                 {
00925                         $a_value = "il_".IL_INST_ID."_glo_".$this->getId();
00926                 }
00927 
00928                 return $a_value;
00929         }
00930 
00931 
00932 
00933 
00940         function ilClone($a_parent_ref)
00941         {
00942                 global $rbacadmin;
00943 
00944                 // always call parent ilClone function first!!
00945                 $new_ref_id = parent::ilClone($a_parent_ref);
00946 
00947                 // todo: put here glossary specific stuff
00948 
00949                 // ... and finally always return new reference ID!!
00950                 return $new_ref_id;
00951         }
00952 
00963         function delete()
00964         {
00965                 // always call parent delete function first!!
00966                 if (!parent::delete())
00967                 {
00968                         return false;
00969                 }
00970 
00971                 // delete terms
00972                 $terms = $this->getTermList();
00973                 foreach ($terms as $term)
00974                 {
00975                         $term_obj =& new ilGlossaryTerm($term["id"]);
00976                         $term_obj->delete();
00977                 }
00978                 
00979                 // delete glossary data entry
00980                 $q = "DELETE FROM glossary WHERE id = ".$this->getId();
00981                 $this->ilias->db->query($q);
00982 
00983                 // delete meta data
00984                 $this->deleteMetaData();
00985 /*
00986                 $nested = new ilNestedSetXML();
00987                 $nested->init($this->getId(), $this->getType());
00988                 $nested->deleteAllDBData();
00989 */
00990 
00991                 return true;
00992         }
00993 
01004         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
01005         {
01006                 global $tree;
01007                 
01008                 switch ($a_event)
01009                 {
01010                         case "link":
01011                                 
01012                                 //var_dump("<pre>",$a_params,"</pre>");
01013                                 //echo "Glossary ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
01014                                 //exit;
01015                                 break;
01016                         
01017                         case "cut":
01018                                 
01019                                 //echo "Glossary ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
01020                                 //exit;
01021                                 break;
01022                                 
01023                         case "copy":
01024                         
01025                                 //var_dump("<pre>",$a_params,"</pre>");
01026                                 //echo "Glossary ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
01027                                 //exit;
01028                                 break;
01029 
01030                         case "paste":
01031                                 
01032                                 //echo "Glossary ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
01033                                 //exit;
01034                                 break;
01035 
01036                         case "new":
01037 
01038                                 //echo "Glossary ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
01039                                 //exit;
01040                                 break;
01041                 }
01042                 
01043                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
01044                 if ($a_node_id==$_GET["ref_id"])
01045                 {       
01046                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
01047                         $parent_type = $parent_obj->getType();
01048                         if($parent_type == $this->getType())
01049                         {
01050                                 $a_node_id = (int) $tree->getParentId($a_node_id);
01051                         }
01052                 }
01053                 
01054                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
01055         }
01056 
01057 
01058         function getXMLZip()
01059         {
01060                 include_once("content/classes/class.ilGlossaryExport.php");
01061 
01062                 $glo_exp = new ilGlossaryExport($this);
01063 
01064                 return $glo_exp->buildExportFile();
01065         }
01066 
01067 
01068 } // END class.ilObjGlossary
01069 
01070 ?>

Generated on Fri Dec 13 2013 10:18:29 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1