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("./Services/COPage/classes/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 global $ilDB;
00072
00073 $q = "SELECT * FROM glossary_definition WHERE id = ".$ilDB->quote($this->id);
00074 $def_set = $this->ilias->db->query($q);
00075 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00076
00077 $this->setTermId($def_rec["term_id"]);
00078 $this->setShortText($def_rec["short_text"]);
00079 $this->setNr($def_rec["nr"]);
00080
00081 $this->page_object =& new ilPageObject("gdf", $this->id);
00082 }
00083
00084 function setId($a_id)
00085 {
00086 $this->id = $a_id;
00087 }
00088
00089 function getId()
00090 {
00091 return $this->id;
00092 }
00093
00094 function getType()
00095 {
00096 return "gdf";
00097 }
00098
00099 function setTermId($a_term_id)
00100 {
00101 $this->term_id = $a_term_id;
00102 }
00103
00104 function getTermId()
00105 {
00106 return $this->term_id;
00107 }
00108
00109 function setShortText($a_text)
00110 {
00111 $this->short_text = $a_text;
00112 }
00113
00114 function getShortText()
00115 {
00116 return $this->short_text;
00117 }
00118
00119 function setNr($a_nr)
00120 {
00121 $this->nr = $a_nr;
00122 }
00123
00124 function getNr()
00125 {
00126 return $this->nr;
00127 }
00128
00129 function assignPageObject(&$a_page_object)
00130 {
00131 $this->page_object =& $a_page_object;
00132 }
00133
00134 function &getPageObject()
00135 {
00136 return $this->page_object;
00137 }
00138
00144 function getTitle()
00145 {
00146 return $this->title;
00147 }
00148
00152 function setTitle($a_title)
00153 {
00154 $this->title = $a_title;
00155 }
00156
00162 function getDescription()
00163 {
00164 return $this->description;
00165 }
00166
00170 function setDescription($a_description)
00171 {
00172 $this->description = $a_description;
00173 }
00174
00175 function create($a_upload = false)
00176 {
00177 global $ilDB;
00178
00179 $term =& new ilGlossaryTerm($this->getTermId());
00180
00181
00182 $q = "LOCK TABLES glossary_definition WRITE";
00183 $this->ilias->db->query($q);
00184
00185
00186 $q = "SELECT max(nr) AS max_nr FROM glossary_definition WHERE term_id = ".$ilDB->quote($this->getTermId());
00187 $max_set = $this->ilias->db->query($q);
00188 $max_rec = $max_set->fetchRow(DB_FETCHMODE_ASSOC);
00189 $max = (int) $max_rec["max_nr"];
00190
00191
00192 $q = "INSERT INTO glossary_definition (term_id, short_text, nr)".
00193 " VALUES (".$ilDB->quote($this->getTermId()).",".
00194 $ilDB->quote($this->getShortText()).", ".$ilDB->quote(($max + 1)).")";
00195 $this->ilias->db->query($q);
00196
00197
00198 $q = "UNLOCK TABLES";
00199 $this->ilias->db->query($q);
00200
00201 $this->setId($this->ilias->db->getLastInsertId());
00202
00203
00204 $q = "SELECT nr FROM glossary_definition WHERE id = ".$ilDB->quote($this->id);
00205 $def_set = $this->ilias->db->query($q);
00206 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00207 $this->setNr($def_rec["nr"]);
00208
00209
00210
00211 if (!$a_upload)
00212 {
00213 $this->createMetaData();
00214 }
00215
00216 $this->page_object =& new ilPageObject("gdf");
00217 $this->page_object->setId($this->getId());
00218 $this->page_object->setParentId($term->getGlossaryId());
00219 $this->page_object->create();
00220 }
00221
00222 function delete()
00223 {
00224 global $ilDB;
00225
00226
00227 $q = "LOCK TABLES glossary_definition WRITE";
00228 $this->ilias->db->query($q);
00229
00230
00231 $q = "SELECT * FROM glossary_definition WHERE id = ".$ilDB->quote($this->id);
00232 $def_set = $this->ilias->db->query($q);
00233 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00234 $this->setNr($def_rec["nr"]);
00235
00236
00237 $q = "UPDATE glossary_definition SET ".
00238 " nr = nr - 1 ".
00239 " WHERE term_id = ".$ilDB->quote($this->getTermId())." ".
00240 " AND nr > ".$ilDB->quote($this->getNr());
00241 $this->ilias->db->query($q);
00242
00243
00244 $q = "DELETE FROM glossary_definition ".
00245 " WHERE id = ".$ilDB->quote($this->getId())." ";
00246 $this->ilias->db->query($q);
00247
00248
00249 $q = "UNLOCK TABLES";
00250 $this->ilias->db->query($q);
00251
00252
00253 $this->page_object->delete();
00254
00255
00256 $this->deleteMetaData();
00257
00258
00259
00260
00261
00262 }
00263
00264
00265 function moveUp()
00266 {
00267 global $ilDB;
00268
00269
00270 $q = "LOCK TABLES glossary_definition WRITE";
00271 $this->ilias->db->query($q);
00272
00273
00274 $q = "SELECT * FROM glossary_definition WHERE id = ".$ilDB->quote($this->id);
00275 $def_set = $this->ilias->db->query($q);
00276 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00277 $this->setNr($def_rec["nr"]);
00278
00279 if ($this->getNr() < 2)
00280 {
00281 $q = "UNLOCK TABLES";
00282 $this->ilias->db->query($q);
00283 return;
00284 }
00285
00286
00287 $q = "UPDATE glossary_definition SET ".
00288 " nr = nr + 1 ".
00289 " WHERE term_id = ".$ilDB->quote($this->getTermId())." ".
00290 " AND nr = ".$ilDB->quote(($this->getNr() - 1));
00291 $this->ilias->db->query($q);
00292
00293
00294 $q = "UPDATE glossary_definition SET ".
00295 " nr = nr - 1 ".
00296 " WHERE term_id = ".$ilDB->quote($this->getTermId())." ".
00297 " AND id = ".$ilDB->quote($this->getId());
00298 $this->ilias->db->query($q);
00299
00300
00301 $q = "UNLOCK TABLES";
00302 $this->ilias->db->query($q);
00303
00304 }
00305
00306
00307 function moveDown()
00308 {
00309 global $ilDB;
00310
00311
00312 $q = "LOCK TABLES glossary_definition WRITE";
00313 $this->ilias->db->query($q);
00314
00315
00316 $q = "SELECT * FROM glossary_definition WHERE id = ".$ilDB->quote($this->id);
00317 $def_set = $this->ilias->db->query($q);
00318 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00319 $this->setNr($def_rec["nr"]);
00320
00321
00322 $q = "SELECT max(nr) as max_nr FROM glossary_definition WHERE term_id = ".
00323 $ilDB->quote($this->getTermId());
00324 $max_set = $this->ilias->db->query($q);
00325 $max_rec = $max_set->fetchRow(DB_FETCHMODE_ASSOC);
00326
00327 if ($this->getNr() >= $max_rec["max_nr"])
00328 {
00329 $q = "UNLOCK TABLES";
00330 $this->ilias->db->query($q);
00331 return;
00332 }
00333
00334
00335 $q = "UPDATE glossary_definition SET ".
00336 " nr = nr - 1 ".
00337 " WHERE term_id = ".$ilDB->quote($this->getTermId())." ".
00338 " AND nr = ".$ilDB->quote(($this->getNr() + 1));
00339 $this->ilias->db->query($q);
00340
00341
00342 $q = "UPDATE glossary_definition SET ".
00343 " nr = nr + 1 ".
00344 " WHERE term_id = ".$ilDB->quote($this->getTermId())." ".
00345 " AND id = ".$ilDB->quote($this->getId());
00346 $this->ilias->db->query($q);
00347
00348
00349 $q = "UNLOCK TABLES";
00350 $this->ilias->db->query($q);
00351
00352 }
00353
00354
00355 function update()
00356 {
00357 global $ilDB;
00358
00359 $this->updateMetaData();
00360
00361 $q = "UPDATE glossary_definition SET ".
00362 " term_id = ".$ilDB->quote($this->getTermId()).", ".
00363 " nr = ".$ilDB->quote($this->getNr()).", ".
00364 " short_text = ".$ilDB->quote($this->getShortText())." ".
00365 " WHERE id = ".$ilDB->quote($this->getId());
00366 $this->ilias->db->query($q);
00367 }
00368
00369 function updateShortText()
00370 {
00371 $this->page_object->buildDom();
00372 $text = $this->page_object->getFirstParagraphText();
00373
00374
00375 $text = str_replace("<br/>", "<br>", $text);
00376 $text = strip_tags($text, "<br>");
00377 if (is_int(strpos(substr($text, 175, 10), "[tex]")))
00378 {
00379 $offset = 5;
00380 }
00381 $short = ilUtil::shortenText($text, 180 + $offset, true);
00382
00383
00384 $ltexs = strrpos($short, "[tex]");
00385 $ltexe = strrpos($short, "[/tex]");
00386 if ($ltexs > $ltexe)
00387 {
00388 $ltexe = strpos($text, "[/tex]", $ltexs);
00389 if ($ltexe > 0)
00390 {
00391 $short = ilUtil::shortenText($text, $ltexe+6, true);
00392 }
00393 }
00394 $this->setShortText($short);
00395 $this->update();
00396 }
00397
00401 function getDefinitionList($a_term_id)
00402 {
00403 global $ilDB;
00404
00405 $defs = array();
00406 $q = "SELECT * FROM glossary_definition WHERE term_id = ".$ilDB->quote($a_term_id).
00407 " ORDER BY nr";
00408 $def_set = $ilDB->query($q);
00409 while ($def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC))
00410 {
00411 $defs[] = array("term_id" => $def_rec["term_id"],
00412 "page_id" => $def_rec["page_id"], "id" => $def_rec["id"],
00413 "short_text" => strip_tags($def_rec["short_text"], "<br>"),
00414 "nr" => $def_rec["nr"]);
00415 }
00416 return $defs;
00417 }
00418
00422 function exportXML(&$a_xml_writer, $a_inst)
00423 {
00424 $attrs = array();
00425 $a_xml_writer->xmlStartTag("Definition", $attrs);
00426
00427 $this->exportXMLMetaData($a_xml_writer);
00428 $this->exportXMLDefinition($a_xml_writer, $a_inst);
00429
00430 $a_xml_writer->xmlEndTag("Definition");
00431 }
00432
00433
00440 function exportXMLMetaData(&$a_xml_writer)
00441 {
00442 $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
00443 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00444 $md2xml = new ilMD2XML($glo_id, $this->getId(), $this->getType());
00445 $md2xml->setExportMode(true);
00446 $md2xml->startExport();
00447 $a_xml_writer->appendXML($md2xml->getXML());
00448 }
00449
00453 function modifyExportIdentifier($a_tag, $a_param, $a_value)
00454 {
00455 if ($a_tag == "Identifier" && $a_param == "Entry")
00456 {
00457 $a_value = "il_".IL_INST_ID."_gdf_".$this->getId();
00458 }
00459
00460 return $a_value;
00461 }
00462
00463
00470 function exportXMLDefinition(&$a_xml_writer, $a_inst = 0)
00471 {
00472
00473 $this->page_object->buildDom();
00474 $this->page_object->insertInstIntoIDs($a_inst);
00475 $this->mobs_contained = $this->page_object->collectMediaObjects(false);
00476 $this->files_contained = $this->page_object->collectFileItems();
00477 $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
00478 $xml = str_replace("&","&", $xml);
00479 $a_xml_writer->appendXML($xml);
00480
00481 $this->page_object->freeDom();
00482 }
00483
00487 function createMetaData()
00488 {
00489 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00490
00491 global $ilUser;
00492
00493 $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
00494 $lang = ilGlossaryTerm::_lookLanguage($this->getTermId());
00495 $md_creator = new ilMDCreator($glo_id,$this->getId(),$this->getType());
00496 $md_creator->setTitle($this->getTitle());
00497 $md_creator->setTitleLanguage($lang);
00498 $md_creator->setDescription($this->getDescription());
00499 $md_creator->setDescriptionLanguage($lang);
00500 $md_creator->setKeywordLanguage($lang);
00501 $md_creator->setLanguage($lang);
00502 $md_creator->create();
00503
00504 return true;
00505 }
00506
00510 function updateMetaData()
00511 {
00512 include_once("Services/MetaData/classes/class.ilMD.php");
00513 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00514 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00515
00516 $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
00517 $md =& new ilMD($glo_id, $this->getId(), $this->getType());
00518 $md_gen =& $md->getGeneral();
00519 $md_gen->setTitle($this->getTitle());
00520
00521
00522 $md_des_ids =& $md_gen->getDescriptionIds();
00523 if (count($md_des_ids) > 0)
00524 {
00525 $md_des =& $md_gen->getDescription($md_des_ids[0]);
00526 $md_des->setDescription($this->getDescription());
00527 $md_des->update();
00528 }
00529 $md_gen->update();
00530 }
00531
00535 function deleteMetaData()
00536 {
00537
00538 include_once('Services/MetaData/classes/class.ilMD.php');
00539 $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
00540 $md = new ilMD($glo_id, $this->getId(), $this->getType());
00541 $md->deleteAll();
00542 }
00543
00558 function MDUpdateListener($a_element)
00559 {
00560 include_once 'Services/MetaData/classes/class.ilMD.php';
00561
00562 switch($a_element)
00563 {
00564 case 'General':
00565
00566
00567 $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
00568 $md =& new ilMD($glo_id, $this->getId(), $this->getType());
00569 $md_gen = $md->getGeneral();
00570
00571
00572 $this->setTitle($md_gen->getTitle());
00573
00574 foreach($md_gen->getDescriptionIds() as $id)
00575 {
00576 $md_des = $md_gen->getDescription($id);
00577
00578 $this->setDescription($md_des->getDescription());
00579 break;
00580 }
00581
00582 break;
00583
00584 default:
00585 }
00586 return true;
00587 }
00588
00594 function _lookupTermId($a_def_id)
00595 {
00596 global $ilDB;
00597
00598 $q = "SELECT * FROM glossary_definition WHERE id = ".$ilDB->quote($a_def_id);
00599 $def_set = $ilDB->query($q);
00600 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00601
00602 return $def_rec["term_id"];
00603 }
00604 }
00605
00606 ?>