Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once("content/classes/Pages/class.ilPageObject.php");
00025
00034 class ilGlossaryDefinition
00035 {
00036 var $ilias;
00037 var $lng;
00038 var $tpl;
00039
00040 var $id;
00041 var $term_id;
00042 var $glo_id;
00043 var $page_object;
00044 var $short_text;
00045 var $nr;
00046
00051 function ilGlossaryDefinition($a_id = 0)
00052 {
00053 global $lng, $ilias, $tpl;
00054
00055 $this->lng =& $lng;
00056 $this->ilias =& $ilias;
00057 $this->tpl =& $tpl;
00058
00059 $this->id = $a_id;
00060 if ($a_id != 0)
00061 {
00062 $this->read();
00063 }
00064 }
00065
00069 function read()
00070 {
00071 $q = "SELECT * FROM glossary_definition WHERE id = '".$this->id."'";
00072 $def_set = $this->ilias->db->query($q);
00073 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00074
00075 $this->setTermId($def_rec["term_id"]);
00076 $this->setShortText($def_rec["short_text"]);
00077 $this->setNr($def_rec["nr"]);
00078
00079 $this->page_object =& new ilPageObject("gdf", $this->id);
00080 }
00081
00082 function setId($a_id)
00083 {
00084 $this->id = $a_id;
00085 }
00086
00087 function getId()
00088 {
00089 return $this->id;
00090 }
00091
00092 function getType()
00093 {
00094 return "gdf";
00095 }
00096
00097 function setTermId($a_term_id)
00098 {
00099 $this->term_id = $a_term_id;
00100 }
00101
00102 function getTermId()
00103 {
00104 return $this->term_id;
00105 }
00106
00107 function setShortText($a_text)
00108 {
00109 $this->short_text = $a_text;
00110 }
00111
00112 function getShortText()
00113 {
00114 return $this->short_text;
00115 }
00116
00117 function setNr($a_nr)
00118 {
00119 $this->nr = $a_nr;
00120 }
00121
00122 function getNr()
00123 {
00124 return $this->nr;
00125 }
00126
00127 function assignPageObject(&$a_page_object)
00128 {
00129 $this->page_object =& $a_page_object;
00130 }
00131
00132 function &getPageObject()
00133 {
00134 return $this->page_object;
00135 }
00136
00142 function getTitle()
00143 {
00144 return $this->title;
00145 }
00146
00150 function setTitle($a_title)
00151 {
00152 $this->title = $a_title;
00153 }
00154
00160 function getDescription()
00161 {
00162 return $this->description;
00163 }
00164
00168 function setDescription($a_description)
00169 {
00170 $this->description = $a_description;
00171 }
00172
00173 function create($a_upload = false)
00174 {
00175 $term =& new ilGlossaryTerm($this->getTermId());
00176
00177
00178 $q = "LOCK TABLES glossary_definition WRITE";
00179 $this->ilias->db->query($q);
00180
00181
00182 $q = "SELECT max(nr) AS max_nr FROM glossary_definition WHERE term_id = '".$this->getTermId()."'";
00183 $max_set = $this->ilias->db->query($q);
00184 $max_rec = $max_set->fetchRow(DB_FETCHMODE_ASSOC);
00185 $max = (int) $max_rec["max_nr"];
00186
00187
00188 $q = "INSERT INTO glossary_definition (term_id, short_text, nr)".
00189 " VALUES ('".$this->getTermId()."','".ilUtil::prepareDBString($this->getShortText())."', '".($max + 1)."')";
00190 $this->ilias->db->query($q);
00191
00192
00193 $q = "UNLOCK TABLES";
00194 $this->ilias->db->query($q);
00195
00196 $this->setId($this->ilias->db->getLastInsertId());
00197
00198
00199 $q = "SELECT nr FROM glossary_definition WHERE id = '".$this->id."'";
00200 $def_set = $this->ilias->db->query($q);
00201 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00202 $this->setNr($def_rec["nr"]);
00203
00204
00205
00206 if (!$a_upload)
00207 {
00208 $this->createMetaData();
00209 }
00210
00211 $this->page_object =& new ilPageObject("gdf");
00212 $this->page_object->setId($this->getId());
00213 $this->page_object->setParentId($term->getGlossaryId());
00214 $this->page_object->create();
00215 }
00216
00217 function delete()
00218 {
00219
00220 $q = "LOCK TABLES glossary_definition WRITE";
00221 $this->ilias->db->query($q);
00222
00223
00224 $q = "SELECT * FROM glossary_definition WHERE id = '".$this->id."'";
00225 $def_set = $this->ilias->db->query($q);
00226 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00227 $this->setNr($def_rec["nr"]);
00228
00229
00230 $q = "UPDATE glossary_definition SET ".
00231 " nr = nr - 1 ".
00232 " WHERE term_id = '".$this->getTermId()."' ".
00233 " AND nr > ".$this->getNr();
00234 $this->ilias->db->query($q);
00235
00236
00237 $q = "DELETE FROM glossary_definition ".
00238 " WHERE id = '".$this->getId()."' ";
00239 $this->ilias->db->query($q);
00240
00241
00242 $q = "UNLOCK TABLES";
00243 $this->ilias->db->query($q);
00244
00245
00246 $this->page_object->delete();
00247
00248
00249 $this->deleteMetaData();
00250
00251
00252
00253
00254
00255 }
00256
00257
00258 function moveUp()
00259 {
00260
00261 $q = "LOCK TABLES glossary_definition WRITE";
00262 $this->ilias->db->query($q);
00263
00264
00265 $q = "SELECT * FROM glossary_definition WHERE id = '".$this->id."'";
00266 $def_set = $this->ilias->db->query($q);
00267 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00268 $this->setNr($def_rec["nr"]);
00269
00270 if ($this->getNr() < 2)
00271 {
00272 $q = "UNLOCK TABLES";
00273 $this->ilias->db->query($q);
00274 return;
00275 }
00276
00277
00278 $q = "UPDATE glossary_definition SET ".
00279 " nr = nr + 1 ".
00280 " WHERE term_id = '".$this->getTermId()."' ".
00281 " AND nr = ".($this->getNr() - 1);
00282 $this->ilias->db->query($q);
00283
00284
00285 $q = "UPDATE glossary_definition SET ".
00286 " nr = nr - 1 ".
00287 " WHERE term_id = '".$this->getTermId()."' ".
00288 " AND id = ".$this->getId();
00289 $this->ilias->db->query($q);
00290
00291
00292 $q = "UNLOCK TABLES";
00293 $this->ilias->db->query($q);
00294
00295 }
00296
00297
00298 function moveDown()
00299 {
00300
00301 $q = "LOCK TABLES glossary_definition WRITE";
00302 $this->ilias->db->query($q);
00303
00304
00305 $q = "SELECT * FROM glossary_definition WHERE id = '".$this->id."'";
00306 $def_set = $this->ilias->db->query($q);
00307 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00308 $this->setNr($def_rec["nr"]);
00309
00310
00311 $q = "SELECT max(nr) as max_nr FROM glossary_definition WHERE term_id = '".$this->getTermId()."'";
00312 $max_set = $this->ilias->db->query($q);
00313 $max_rec = $max_set->fetchRow(DB_FETCHMODE_ASSOC);
00314
00315 if ($this->getNr() >= $max_rec["max_nr"])
00316 {
00317 $q = "UNLOCK TABLES";
00318 $this->ilias->db->query($q);
00319 return;
00320 }
00321
00322
00323 $q = "UPDATE glossary_definition SET ".
00324 " nr = nr - 1 ".
00325 " WHERE term_id = '".$this->getTermId()."' ".
00326 " AND nr = ".($this->getNr() + 1);
00327 $this->ilias->db->query($q);
00328
00329
00330 $q = "UPDATE glossary_definition SET ".
00331 " nr = nr + 1 ".
00332 " WHERE term_id = '".$this->getTermId()."' ".
00333 " AND id = ".$this->getId();
00334 $this->ilias->db->query($q);
00335
00336
00337 $q = "UNLOCK TABLES";
00338 $this->ilias->db->query($q);
00339
00340 }
00341
00342
00343 function update()
00344 {
00345 $this->updateMetaData();
00346
00347 $q = "UPDATE glossary_definition SET ".
00348 " term_id = '".$this->getTermId()."', ".
00349 " nr = '".$this->getNr()."', ".
00350 " short_text = '".ilUtil::prepareDBString($this->getShortText())."' ".
00351 " WHERE id = '".$this->getId()."'";
00352 $this->ilias->db->query($q);
00353 }
00354
00355 function updateShortText()
00356 {
00357 $this->page_object->buildDom();
00358 $text = $this->page_object->getFirstParagraphText();
00359
00360 $text = str_replace("<br/>", "<br>", $text);
00361
00362 $this->setShortText(ilUtil::shortenText(strip_tags($text, "<br>"), 180, true));
00363 $this->update();
00364 }
00365
00369 function getDefinitionList($a_term_id)
00370 {
00371 $defs = array();
00372 $q = "SELECT * FROM glossary_definition WHERE term_id ='".$a_term_id."' ORDER BY nr";
00373 $def_set = $this->ilias->db->query($q);
00374 while ($def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC))
00375 {
00376 $defs[] = array("term_id" => $def_rec["term_id"],
00377 "page_id" => $def_rec["page_id"], "id" => $def_rec["id"],
00378 "short_text" => strip_tags($def_rec["short_text"], "<br>"),
00379 "nr" => $def_rec["nr"]);
00380 }
00381 return $defs;
00382 }
00383
00387 function exportXML(&$a_xml_writer, $a_inst)
00388 {
00389 $attrs = array();
00390 $a_xml_writer->xmlStartTag("Definition", $attrs);
00391
00392 $this->exportXMLMetaData($a_xml_writer);
00393 $this->exportXMLDefinition($a_xml_writer, $a_inst);
00394
00395 $a_xml_writer->xmlEndTag("Definition");
00396 }
00397
00398
00405 function exportXMLMetaData(&$a_xml_writer)
00406 {
00407 $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
00408 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00409 $md2xml = new ilMD2XML($glo_id, $this->getId(), $this->getType());
00410 $md2xml->setExportMode(true);
00411 $md2xml->startExport();
00412 $a_xml_writer->appendXML($md2xml->getXML());
00413 }
00414
00418 function modifyExportIdentifier($a_tag, $a_param, $a_value)
00419 {
00420 if ($a_tag == "Identifier" && $a_param == "Entry")
00421 {
00422 $a_value = "il_".IL_INST_ID."_gdf_".$this->getId();
00423 }
00424
00425 return $a_value;
00426 }
00427
00428
00435 function exportXMLDefinition(&$a_xml_writer, $a_inst = 0)
00436 {
00437
00438 $this->page_object->buildDom();
00439 $this->page_object->insertInstIntoIDs($a_inst);
00440 $this->mobs_contained = $this->page_object->collectMediaObjects(false);
00441 $this->files_contained = $this->page_object->collectFileItems();
00442 $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
00443 $xml = str_replace("&","&", $xml);
00444 $a_xml_writer->appendXML($xml);
00445
00446 $this->page_object->freeDom();
00447 }
00448
00452 function createMetaData()
00453 {
00454 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00455
00456 global $ilUser;
00457
00458 $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
00459 $lang = ilGlossaryTerm::_lookLanguage($this->getTermId());
00460 $md_creator = new ilMDCreator($glo_id,$this->getId(),$this->getType());
00461 $md_creator->setTitle($this->getTitle());
00462 $md_creator->setTitleLanguage($lang);
00463 $md_creator->setDescription($this->getDescription());
00464 $md_creator->setDescriptionLanguage($lang);
00465 $md_creator->setKeywordLanguage($lang);
00466 $md_creator->setLanguage($lang);
00467 $md_creator->create();
00468
00469 return true;
00470 }
00471
00475 function updateMetaData()
00476 {
00477 include_once("Services/MetaData/classes/class.ilMD.php");
00478 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00479 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00480
00481 $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
00482 $md =& new ilMD($glo_id, $this->getId(), $this->getType());
00483 $md_gen =& $md->getGeneral();
00484 $md_gen->setTitle($this->getTitle());
00485
00486
00487 $md_des_ids =& $md_gen->getDescriptionIds();
00488 if (count($md_des_ids) > 0)
00489 {
00490 $md_des =& $md_gen->getDescription($md_des_ids[0]);
00491 $md_des->setDescription($this->getDescription());
00492 $md_des->update();
00493 }
00494 $md_gen->update();
00495 }
00496
00500 function deleteMetaData()
00501 {
00502
00503 include_once('Services/MetaData/classes/class.ilMD.php');
00504 $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
00505 $md = new ilMD($glo_id, $this->getId(), $this->getType());
00506 $md->deleteAll();
00507 }
00508
00523 function MDUpdateListener($a_element)
00524 {
00525 include_once 'Services/MetaData/classes/class.ilMD.php';
00526
00527 switch($a_element)
00528 {
00529 case 'General':
00530
00531
00532 $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
00533 $md =& new ilMD($glo_id, $this->getId(), $this->getType());
00534 $md_gen = $md->getGeneral();
00535
00536
00537 $this->setTitle($md_gen->getTitle());
00538
00539 foreach($md_gen->getDescriptionIds() as $id)
00540 {
00541 $md_des = $md_gen->getDescription($id);
00542
00543 $this->setDescription($md_des->getDescription());
00544 break;
00545 }
00546
00547 break;
00548
00549 default:
00550 }
00551 return true;
00552 }
00553
00554
00555 }
00556
00557 ?>