• 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                 if ($a_id == 0)
00048                 {
00049                         $this->initMeta();
00050                 }
00051 
00052         }
00053 
00057         function initMeta()
00058         {
00059                 if (!is_object($this->meta_data))
00060                 {
00061                         if ($this->getId())
00062                         {
00063                                 $new_meta =& new ilMetaData($this->getType(), $this->getId());
00064                         }       
00065                         else
00066                         {
00067                                 $new_meta =& new ilMetaData();
00068                         }
00069                         $this->assignMetaData($new_meta);
00070                 }
00071         }
00072 
00076         function create($a_upload = false)
00077         {
00078                 global $ilDB;
00079 
00080                 parent::create();
00081                 if (!$a_upload)
00082                 {
00083                         $this->initMeta();
00084                         $this->meta_data->setId($this->getId());
00085                         $this->meta_data->setType($this->getType());
00086                         $this->meta_data->setTitle($this->getTitle());
00087                         $this->meta_data->setDescription($this->getDescription());
00088                         $this->meta_data->setObject($this);
00089                         $this->meta_data->create();
00090                 }
00091 
00092                 $q = "INSERT INTO glossary (id, online) VALUES ".
00093                         " (".$ilDB->quote($this->getId()).",".$ilDB->quote("n").")";
00094                 $ilDB->query($q);
00095 
00096         }
00097 
00101         function read()
00102         {
00103                 parent::read();
00104 #               echo "Glossary<br>\n";
00105 
00106                 $q = "SELECT * FROM glossary WHERE id = '".$this->getId()."'";
00107                 $gl_set = $this->ilias->db->query($q);
00108                 $gl_rec = $gl_set->fetchRow(DB_FETCHMODE_ASSOC);
00109                 $this->setOnline(ilUtil::yn2tf($gl_rec["online"]));
00110 
00111         }
00112 
00118         function getDescription()
00119         {
00120                 return parent::getDescription();
00121         }
00122 
00126         function setDescription($a_description)
00127         {
00128                 parent::setDescription($a_description);
00129                 $this->meta_data->setDescription($a_description);
00130         }
00131 
00137         function getTitle()
00138         {
00139                 return parent::getTitle();
00140         }
00141 
00145         function setTitle($a_title)
00146         {
00147                 parent::setTitle($a_title);
00148                 $this->meta_data->setTitle($a_title);
00149         }
00150 
00151         function setOnline($a_online)
00152         {
00153                 $this->online = $a_online;
00154         }
00155 
00156         function getOnline()
00157         {
00158                 return $this->online;
00159         }
00160 
00164         function _lookupOnline($a_id)
00165         {
00166                 global $ilDB;
00167 
00168                 $q = "SELECT * FROM glossary WHERE id = '".$a_id."'";
00169                 $lm_set = $ilDB->query($q);
00170                 $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
00171 
00172                 return ilUtil::yn2tf($lm_rec["online"]);
00173         }
00174 
00180         function assignMetaData(&$a_meta_data)
00181         {
00182                 $this->meta_data =& $a_meta_data;
00183         }
00184 
00190         function &getMetaData()
00191         {
00192                 $this->initMeta();
00193                 return $this->meta_data;
00194         }
00195 
00199         function updateMetaData()
00200         {
00201                 $this->initMeta();
00202                 $this->meta_data->update();
00203                 if ($this->meta_data->section != "General")
00204                 {
00205                         $meta = $this->meta_data->getElement("Title", "General");
00206                         $this->meta_data->setTitle($meta[0]["value"]);
00207                         $meta = $this->meta_data->getElement("Description", "General");
00208                         $this->meta_data->setDescription($meta[0]["value"]);
00209                 }
00210                 else
00211                 {
00212                         $this->setTitle($this->meta_data->getTitle());
00213                         $this->setDescription($this->meta_data->getDescription());
00214                 }
00215                 parent::update();
00216         }
00217 
00221         function update()
00222         {
00223                 $this->updateMetaData();
00224 
00225                 $q = "UPDATE glossary SET ".
00226                         " online = '".ilUtil::tf2yn($this->getOnline())."'".
00227                         " WHERE id = '".$this->getId()."'";
00228                 $this->ilias->db->query($q);
00229 
00230         }
00231 
00232         function getImportId()
00233         {
00234                 $this->initMeta();
00235                 return $this->meta_data->getImportIdentifierEntryID();
00236         }
00237 
00238         function setImportId($a_id)
00239         {
00240                 $this->initMeta();
00241                 $this->meta_data->setImportIdentifierEntryID($a_id);
00242         }
00243 
00244 
00248         function getTermList($searchterm="")
00249         {
00250                 $list = ilGlossaryTerm::getTermList($this->getId(),$searchterm);
00251                 return $list;
00252         }
00253 
00259         function createImportDirectory()
00260         {
00261                 $glo_data_dir = ilUtil::getDataDir()."/glo_data";
00262                 ilUtil::makeDir($glo_data_dir);
00263                 if(!is_writable($glo_data_dir))
00264                 {
00265                         $this->ilias->raiseError("Glossary Data Directory (".$glo_data_dir
00266                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00267                 }
00268 
00269                 // create glossary directory (data_dir/glo_data/glo_<id>)
00270                 $glo_dir = $glo_data_dir."/glo_".$this->getId();
00271                 ilUtil::makeDir($glo_dir);
00272                 if(!@is_dir($glo_dir))
00273                 {
00274                         $this->ilias->raiseError("Creation of Glossary Directory failed.",$this->ilias->error_obj->FATAL);
00275                 }
00276                 // create Import subdirectory (data_dir/glo_data/glo_<id>/import)
00277                 $import_dir = $glo_dir."/import";
00278                 ilUtil::makeDir($import_dir);
00279                 if(!@is_dir($import_dir))
00280                 {
00281                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00282                 }
00283         }
00284 
00288         function getImportDirectory()
00289         {
00290                 $export_dir = ilUtil::getDataDir()."/glo_data"."/glo_".$this->getId()."/import";
00291 
00292                 return $export_dir;
00293         }
00294 
00300         function createExportDirectory()
00301         {
00302                 $glo_data_dir = ilUtil::getDataDir()."/glo_data";
00303                 ilUtil::makeDir($glo_data_dir);
00304                 if(!is_writable($glo_data_dir))
00305                 {
00306                         $this->ilias->raiseError("Glossary Data Directory (".$glo_data_dir
00307                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00308                 }
00309                 // create glossary directory (data_dir/glo_data/glo_<id>)
00310                 $glo_dir = $glo_data_dir."/glo_".$this->getId();
00311                 ilUtil::makeDir($glo_dir);
00312                 if(!@is_dir($glo_dir))
00313                 {
00314                         $this->ilias->raiseError("Creation of Glossary Directory failed.",$this->ilias->error_obj->FATAL);
00315                 }
00316                 // create Export subdirectory (data_dir/glo_data/glo_<id>/export)
00317                 $export_dir = $glo_dir."/export";
00318                 ilUtil::makeDir($export_dir);
00319                 if(!@is_dir($export_dir))
00320                 {
00321                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00322                 }
00323         }
00324 
00328         function getExportDirectory()
00329         {
00330                 $export_dir = ilUtil::getDataDir()."/glo_data"."/glo_".$this->getId()."/export";
00331 
00332                 return $export_dir;
00333         }
00334 
00338         function getExportFiles($dir)
00339         {
00340                 // quit if import dir not available
00341                 if (!@is_dir($dir) or
00342                         !is_writeable($dir))
00343                 {
00344                         return array();
00345                 }
00346 
00347                 // open directory
00348                 $dir = dir($dir);
00349 
00350                 // initialize array
00351                 $file = array();
00352 
00353                 // get files and save the in the array
00354                 while ($entry = $dir->read())
00355                 {
00356                         if ($entry != "." and
00357                                 $entry != ".." and
00358                                 substr($entry, -4) == ".zip" and
00359                                 ereg("^[0-9]{10}_{2}[0-9]+_{2}(glo_)*[0-9]+\.zip\$", $entry))
00360                         {
00361                                 $file[] = $entry;
00362                         }
00363                 }
00364 
00365                 // close import directory
00366                 $dir->close();
00367 
00368                 // sort files
00369                 sort ($file);
00370                 reset ($file);
00371 
00372                 return $file;
00373         }
00374 
00381         function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00382         {
00383                 global $ilBench;
00384 
00385                 // export glossary
00386                 $attrs = array();
00387                 $attrs["Type"] = "Glossary";
00388                 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
00389 
00390                 // MetaData
00391                 $this->exportXMLMetaData($a_xml_writer);
00392 
00393                 // collect media objects
00394                 $terms = $this->getTermList();
00395                 $this->mob_ids = array();
00396                 $this->file_ids = array();
00397                 foreach ($terms as $term)
00398                 {
00399                         include_once "./content/classes/class.ilGlossaryDefinition.php";
00400                         
00401                         $defs = ilGlossaryDefinition::getDefinitionList($term[id]);
00402 
00403                         foreach($defs as $def)
00404                         {
00405                                 $this->page_object =& new ilPageObject("gdf",
00406                                         $def["id"], $this->halt_on_error);
00407                                 $this->page_object->buildDom();
00408                                 $this->page_object->insertInstIntoIDs(IL_INST_ID);
00409                                 $mob_ids = $this->page_object->collectMediaObjects(false);
00410                                 $file_ids = $this->page_object->collectFileItems();
00411                                 foreach($mob_ids as $mob_id)
00412                                 {
00413                                         $this->mob_ids[$mob_id] = $mob_id;
00414                                 }
00415                                 foreach($file_ids as $file_id)
00416                                 {
00417                                         $this->file_ids[$file_id] = $file_id;
00418                                 }
00419                         }
00420                 }
00421 
00422                 // export media objects
00423                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
00424                 $ilBench->start("GlossaryExport", "exportMediaObjects");
00425                 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
00426                 $ilBench->stop("GlossaryExport", "exportMediaObjects");
00427                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
00428 
00429                 // FileItems
00430                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
00431                 $ilBench->start("ContentObjectExport", "exportFileItems");
00432                 $this->exportFileItems($a_target_dir, $expLog);
00433                 $ilBench->stop("ContentObjectExport", "exportFileItems");
00434                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
00435 
00436                 // Glossary
00437                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Glossary Items");
00438                 $ilBench->start("GlossaryExport", "exportGlossaryItems");
00439                 $this->exportXMLGlossaryItems($a_xml_writer, $a_inst, $expLog);
00440                 $ilBench->stop("GlossaryExport", "exportGlossaryItems");
00441                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Glossary Items");
00442 
00443                 $a_xml_writer->xmlEndTag("ContentObject");
00444         }
00445 
00452         function exportXMLGlossaryItems(&$a_xml_writer, $a_inst, &$expLog)
00453         {
00454                 global $ilBench;
00455 
00456                 $attrs = array();
00457                 $a_xml_writer->xmlStartTag("Glossary", $attrs);
00458 
00459                 // MetaData
00460                 $this->exportXMLMetaData($a_xml_writer);
00461 
00462                 $terms = $this->getTermList();
00463 
00464                 // export glossary terms
00465                 reset($terms);
00466                 foreach ($terms as $term)
00467                 {
00468                         $ilBench->start("GlossaryExport", "exportGlossaryItem");
00469                         $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
00470 
00471                         // export xml to writer object
00472                         $ilBench->start("GlossaryExport", "exportGlossaryItem_getGlossaryTerm");
00473                         $glo_term = new ilGlossaryTerm($term["id"]);
00474                         $ilBench->stop("GlossaryExport", "exportGlossaryItem_getGlossaryTerm");
00475                         $ilBench->start("GlossaryExport", "exportGlossaryItem_XML");
00476                         $glo_term->exportXML($a_xml_writer, $a_inst);
00477                         $ilBench->stop("GlossaryExport", "exportGlossaryItem_XML");
00478 
00479                         // collect all file items
00480                         /*
00481                         $ilBench->start("GlossaryExport", "exportGlossaryItem_CollectFileItems");
00482                         $file_ids = $page_obj->getFileItemIds();
00483                         foreach($file_ids as $file_id)
00484                         {
00485                                 $this->file_ids[$file_id] = $file_id;
00486                         }
00487                         $ilBench->stop("GlossaryExport", "exportGlossaryItem_CollectFileItems");
00488                         */
00489 
00490                         unset($glo_term);
00491 
00492                         $ilBench->stop("GlossaryExport", "exportGlossaryItem");
00493                 }
00494 
00495                 $a_xml_writer->xmlEndTag("Glossary");
00496         }
00497 
00504         function exportXMLMetaData(&$a_xml_writer)
00505         {
00506                 $nested = new ilNestedSetXML();
00507                 $nested->setParameterModifier($this, "modifyExportIdentifier");
00508                 $a_xml_writer->appendXML($nested->export($this->getId(),
00509                         $this->getType()));
00510         }
00511 
00518         function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
00519         {
00520                 include_once("content/classes/Media/class.ilObjMediaObject.php");
00521 
00522                 foreach ($this->mob_ids as $mob_id)
00523                 {
00524                         $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
00525                         $media_obj = new ilObjMediaObject($mob_id);
00526                         $media_obj->exportXML($a_xml_writer, $a_inst);
00527                         $media_obj->exportFiles($a_target_dir);
00528                         unset($media_obj);
00529                 }
00530         }
00531 
00536         function exportFileItems($a_target_dir, &$expLog)
00537         {
00538                 include_once("classes/class.ilObjFile.php");
00539 
00540                 foreach ($this->file_ids as $file_id)
00541                 {
00542                         $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
00543                         $file_obj = new ilObjFile($file_id, false);
00544                         $file_obj->export($a_target_dir);
00545                         unset($file_obj);
00546                 }
00547         }
00548 
00549 
00550 
00554         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00555         {
00556                 if ($a_tag == "Identifier" && $a_param == "Entry")
00557                 {
00558                         $a_value = "il_".IL_INST_ID."_glo_".$this->getId();
00559                 }
00560 
00561                 return $a_value;
00562         }
00563 
00564 
00565 
00566 
00573         function ilClone($a_parent_ref)
00574         {
00575                 global $rbacadmin;
00576 
00577                 // always call parent ilClone function first!!
00578                 $new_ref_id = parent::ilClone($a_parent_ref);
00579 
00580                 // todo: put here glossary specific stuff
00581 
00582                 // ... and finally always return new reference ID!!
00583                 return $new_ref_id;
00584         }
00585 
00596         function delete()
00597         {
00598                 // always call parent delete function first!!
00599                 if (!parent::delete())
00600                 {
00601                         return false;
00602                 }
00603 
00604                 // delete terms
00605                 $terms = $this->getTermList();
00606                 foreach ($terms as $term)
00607                 {
00608                         $term_obj =& new ilGlossaryTerm($term["id"]);
00609                         $term_obj->delete();
00610                 }
00611                 
00612                 // delete glossary data entry
00613                 $q = "DELETE FROM glossary WHERE id = ".$this->getId();
00614                 $this->ilias->db->query($q);
00615 
00616                 // delete meta data
00617                 $nested = new ilNestedSetXML();
00618                 $nested->init($this->getId(), $this->getType());
00619                 $nested->deleteAllDBData();
00620 
00621                 return true;
00622         }
00623 
00634         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00635         {
00636                 global $tree;
00637                 
00638                 switch ($a_event)
00639                 {
00640                         case "link":
00641                                 
00642                                 //var_dump("<pre>",$a_params,"</pre>");
00643                                 //echo "Glossary ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00644                                 //exit;
00645                                 break;
00646                         
00647                         case "cut":
00648                                 
00649                                 //echo "Glossary ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00650                                 //exit;
00651                                 break;
00652                                 
00653                         case "copy":
00654                         
00655                                 //var_dump("<pre>",$a_params,"</pre>");
00656                                 //echo "Glossary ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00657                                 //exit;
00658                                 break;
00659 
00660                         case "paste":
00661                                 
00662                                 //echo "Glossary ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00663                                 //exit;
00664                                 break;
00665 
00666                         case "new":
00667 
00668                                 //echo "Glossary ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00669                                 //exit;
00670                                 break;
00671                 }
00672                 
00673                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00674                 if ($a_node_id==$_GET["ref_id"])
00675                 {       
00676                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00677                         $parent_type = $parent_obj->getType();
00678                         if($parent_type == $this->getType())
00679                         {
00680                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00681                         }
00682                 }
00683                 
00684                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00685         }
00686 
00687 
00688         function getXMLZip()
00689         {
00690                 include_once("content/classes/class.ilGlossaryExport.php");
00691 
00692                 $glo_exp = new ilGlossaryExport($this);
00693 
00694                 return $glo_exp->buildExportFile();
00695         }
00696 
00697 
00698 } // END class.ilObjGlossary
00699 
00700 ?>

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