ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilGlossaryDefinition.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once("./Modules/Glossary/classes/class.ilGlossaryDefPage.php");
5
15{
16 var $ilias;
17 var $lng;
18 var $tpl;
19
20 var $id;
25 var $nr;
26 var $short_text_dirty = false;
27
32 function ilGlossaryDefinition($a_id = 0)
33 {
34 global $lng, $ilias, $tpl;
35
36 $this->lng =& $lng;
37 $this->ilias =& $ilias;
38 $this->tpl =& $tpl;
39
40 $this->id = $a_id;
41 if ($a_id != 0)
42 {
43 $this->read();
44 }
45 }
46
50 function read()
51 {
52 global $ilDB;
53
54 $q = "SELECT * FROM glossary_definition WHERE id = ".
55 $ilDB->quote($this->id, "integer");
56 $def_set = $ilDB->query($q);
57 $def_rec = $ilDB->fetchAssoc($def_set);
58
59 $this->setTermId($def_rec["term_id"]);
60 $this->setShortText($def_rec["short_text"]);
61 $this->setNr($def_rec["nr"]);
62 $this->setShortTextDirty($def_rec["short_text_dirty"]);
63
64 $this->page_object = new ilGlossaryDefPage($this->id);
65 }
66
67 function setId($a_id)
68 {
69 $this->id = $a_id;
70 }
71
72 function getId()
73 {
74 return $this->id;
75 }
76
77 function getType()
78 {
79 return "gdf";
80 }
81
82 function setTermId($a_term_id)
83 {
84 $this->term_id = $a_term_id;
85 }
86
87 function getTermId()
88 {
89 return $this->term_id;
90 }
91
92 function setShortText($a_text)
93 {
94 $this->short_text = $this->shortenShortText($a_text);
95 }
96
97 function getShortText()
98 {
99 return $this->short_text;
100 }
101
102 function setNr($a_nr)
103 {
104 $this->nr = $a_nr;
105 }
106
107 function getNr()
108 {
109 return $this->nr;
110 }
111
112 function assignPageObject(&$a_page_object)
113 {
114 $this->page_object =& $a_page_object;
115 }
116
117 function &getPageObject()
118 {
119 return $this->page_object;
120 }
121
127 function getTitle()
128 {
129 return $this->title;
130 }
131
135 function setTitle($a_title)
136 {
137 $this->title = $a_title;
138 }
139
145 function getDescription()
146 {
147 return $this->description;
148 }
149
155 function setDescription($a_description)
156 {
157 $this->description = $a_description;
158 }
159
165 function setShortTextDirty($a_val)
166 {
167 $this->short_text_dirty = $a_val;
168 }
169
176 {
178 }
184 function create($a_upload = false, $a_omit_page_creation = false)
185 {
186 global $ilDB;
187
188 $term =& new ilGlossaryTerm($this->getTermId());
189
190 $this->setId($ilDB->nextId("glossary_definition"));
191
192 // lock glossary_definition table
193 $ilDB->lockTables(
194 array(
195 0 => array('name' => 'glossary_definition', 'type' => ilDB::LOCK_WRITE)));
196
197 // get maximum definition number
198 $q = "SELECT max(nr) AS max_nr FROM glossary_definition WHERE term_id = ".
199 $ilDB->quote($this->getTermId(), "integer");
200 $max_set = $ilDB->query($q);
201 $max_rec = $ilDB->fetchAssoc($max_set);
202 $max = (int) $max_rec["max_nr"];
203
204 // insert new definition record
205 $ilDB->manipulate("INSERT INTO glossary_definition (id, term_id, short_text, nr, short_text_dirty)".
206 " VALUES (".
207 $ilDB->quote($this->getId(), "integer").",".
208 $ilDB->quote($this->getTermId(), "integer").",".
209 $ilDB->quote($this->getShortText(), "text").", ".
210 $ilDB->quote(($max + 1), "integer").", ".
211 $ilDB->quote($this->getShortTextDirty(), "integer").
212 ")");
213
214 // unlock glossary definition table
215 $ilDB->unlockTables();
216
217 // get number
218 $q = "SELECT nr FROM glossary_definition WHERE id = ".
219 $ilDB->quote($this->id, "integer");
220 $def_set = $ilDB->query($q);
221 $def_rec = $ilDB->fetchAssoc($def_set);
222 $this->setNr($def_rec["nr"]);
223
224 // meta data will be created by
225 // import parser
226 if (!$a_upload)
227 {
228 $this->createMetaData();
229 }
230
231 if (!$a_omit_page_creation)
232 {
233 $this->page_object = new ilGlossaryDefPage();
234 $this->page_object->setId($this->getId());
235 $this->page_object->setParentId($term->getGlossaryId());
236 $this->page_object->create();
237 }
238 }
239
240 function delete()
241 {
242 global $ilDB;
243
244 // lock glossary_definition table
245 #ilDB::_lockTables(array('glossary_definition' => 'WRITE'));
246 $ilDB->lockTables(
247 array(
248 0 => array('name' => 'glossary_definition', 'type' => ilDB::LOCK_WRITE)));
249
250
251 // be sure to get the right number
252 $q = "SELECT * FROM glossary_definition WHERE id = ".
253 $ilDB->quote($this->id, "integer");
254 $def_set = $ilDB->query($q);
255 $def_rec = $ilDB->fetchAssoc($def_set);
256 $this->setNr($def_rec["nr"]);
257
258 // update numbers of other definitions
259 $ilDB->manipulate("UPDATE glossary_definition SET ".
260 " nr = nr - 1 ".
261 " WHERE term_id = ".$ilDB->quote($this->getTermId(), "integer")." ".
262 " AND nr > ".$ilDB->quote($this->getNr(), "integer"));
263
264 // delete current definition
265 $ilDB->manipulate("DELETE FROM glossary_definition ".
266 " WHERE id = ".$ilDB->quote($this->getId(), "integer"));
267
268 // unlock glossary_definition table
269 $ilDB->unlockTables();
270
271 // delete page and meta data
272 $this->page_object->delete();
273
274 // delete meta data
275 $this->deleteMetaData();
276/*
277 $nested = new ilNestedSetXML();
278 $nested->init($this->getId(), $this->getType());
279 $nested->deleteAllDBData();
280*/
281 }
282
283
284 function moveUp()
285 {
286 global $ilDB;
287
288 // lock glossary_definition table
289 #ilDB::_lockTables(array('glossary_definition' => 'WRITE'));
290 $ilDB->lockTables(
291 array(
292 0 => array('name' => 'glossary_definition', 'type' => ilDB::LOCK_WRITE)));
293
294
295 // be sure to get the right number
296 $q = "SELECT * FROM glossary_definition WHERE id = ".
297 $ilDB->quote($this->id, "integer");
298 $def_set = $ilDB->query($q);
299 $def_rec = $ilDB->fetchAssoc($def_set);
300 $this->setNr($def_rec["nr"]);
301
302 if ($this->getNr() < 2)
303 {
304 $ilDB->unlockTables();
305 return;
306 }
307
308 // update numbers of other definitions
309 $ilDB->manipulate("UPDATE glossary_definition SET ".
310 " nr = nr + 1 ".
311 " WHERE term_id = ".$ilDB->quote($this->getTermId(), "integer")." ".
312 " AND nr = ".$ilDB->quote(($this->getNr() - 1), "integer"));
313
314 // delete current definition
315 $ilDB->manipulate("UPDATE glossary_definition SET ".
316 " nr = nr - 1 ".
317 " WHERE term_id = ".$ilDB->quote($this->getTermId(), "integer")." ".
318 " AND id = ".$ilDB->quote($this->getId(), "integer"));
319
320 // unlock glossary_definition table
321 $ilDB->unlockTables();
322 }
323
324
325 function moveDown()
326 {
327 global $ilDB;
328
329 // lock glossary_definition table
330 #ilDB::_lockTables(array('glossary_definition' => 'WRITE'));
331 $ilDB->lockTables(
332 array(
333 0 => array('name' => 'glossary_definition', 'type' => ilDB::LOCK_WRITE)));
334
335 // be sure to get the right number
336 $q = "SELECT * FROM glossary_definition WHERE id = ".
337 $ilDB->quote($this->id, "integer");
338 $def_set = $ilDB->query($q);
339 $def_rec = $ilDB->fetchAssoc($def_set);
340 $this->setNr($def_rec["nr"]);
341
342 // get max number
343 $q = "SELECT max(nr) as max_nr FROM glossary_definition WHERE term_id = ".
344 $ilDB->quote($this->getTermId(), "integer");
345 $max_set = $ilDB->query($q);
346 $max_rec = $ilDB->fetchAssoc($max_set);
347
348 if ($this->getNr() >= $max_rec["max_nr"])
349 {
350 $ilDB->unlockTables();
351 return;
352 }
353
354 // update numbers of other definitions
355 $ilDB->manipulate("UPDATE glossary_definition SET ".
356 " nr = nr - 1 ".
357 " WHERE term_id = ".$ilDB->quote($this->getTermId(), "integer")." ".
358 " AND nr = ".$ilDB->quote(($this->getNr() + 1), "integer"));
359
360 // delete current definition
361 $ilDB->manipulate("UPDATE glossary_definition SET ".
362 " nr = nr + 1 ".
363 " WHERE term_id = ".$ilDB->quote($this->getTermId(), "integer")." ".
364 " AND id = ".$ilDB->quote($this->getId(), "integer"));
365
366 // unlock glossary_definition table
367 $ilDB->unlockTables();
368
369 }
370
371
372 function update()
373 {
374 global $ilDB;
375
376 $this->updateMetaData();
377
378 $ilDB->manipulate("UPDATE glossary_definition SET ".
379 " term_id = ".$ilDB->quote($this->getTermId(), "integer").", ".
380 " nr = ".$ilDB->quote($this->getNr(), "integer").", ".
381 " short_text = ".$ilDB->quote($this->getShortText(), "text").", ".
382 " short_text_dirty = ".$ilDB->quote($this->getShortTextDirty(), "integer")." ".
383 " WHERE id = ".$ilDB->quote($this->getId(), "integer"));
384 }
385
393 {
394 $a_length = 196;
395
396 if ($this->getTermId() > 0)
397 {
398 include_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
399 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
400 $glo_id = ilGlossaryTerm::_lookGlossaryId($this->getTermId());
402 if ($snippet_length > 0)
403 {
404 $a_length = $snippet_length;
405 }
406 }
407
408 $text = str_replace("<br/>", "<br>", $text);
409 $text = strip_tags($text, "<br>");
410 if (is_int(strpos(substr($text, $a_length - 16 - 5, 10), "[tex]")))
411 {
412 $offset = 5;
413 }
414 $short = ilUtil::shortenText($text, $a_length - 16 + $offset, true);
415
416 // make short text longer, if tex end tag is missing
417 $ltexs = strrpos($short, "[tex]");
418 $ltexe = strrpos($short, "[/tex]");
419 if ($ltexs > $ltexe)
420 {
421 $ltexe = strpos($text, "[/tex]", $ltexs);
422 if ($ltexe > 0)
423 {
424 $short = ilUtil::shortenText($text, $ltexe+6, true);
425 }
426 }
427
428 $short = ilUtil::shortenText($text, $a_length, true);
429
430 return $short;
431 }
432
434 {
435 $this->page_object->buildDom();
436 $text = $this->page_object->getFirstParagraphText();
437
438 $short = $this->shortenShortText($text);
439
440 $this->setShortText($short);
441 $this->setShortTextDirty(false);
442 $this->update();
443 }
444
448 function getDefinitionList($a_term_id)
449 {
450 global $ilDB;
451
452 $defs = array();
453 $q = "SELECT * FROM glossary_definition WHERE term_id = ".
454 $ilDB->quote($a_term_id, "integer").
455 " ORDER BY nr";
456 $def_set = $ilDB->query($q);
457 while ($def_rec = $ilDB->fetchAssoc($def_set))
458 {
459 $defs[] = array("term_id" => $def_rec["term_id"],
460 "page_id" => $def_rec["page_id"], "id" => $def_rec["id"],
461 "short_text" => strip_tags($def_rec["short_text"], "<br>"),
462 "nr" => $def_rec["nr"],
463 "short_text_dirty" => $def_rec["short_text_dirty"]);
464 }
465 return $defs;
466 }
467
471 function exportXML(&$a_xml_writer, $a_inst)
472 {
473 $attrs = array();
474 $a_xml_writer->xmlStartTag("Definition", $attrs);
475
476 $this->exportXMLMetaData($a_xml_writer);
477 $this->exportXMLDefinition($a_xml_writer, $a_inst);
478
479 $a_xml_writer->xmlEndTag("Definition");
480 }
481
482
489 function exportXMLMetaData(&$a_xml_writer)
490 {
492 include_once("Services/MetaData/classes/class.ilMD2XML.php");
493 $md2xml = new ilMD2XML($glo_id, $this->getId(), $this->getType());
494 $md2xml->setExportMode(true);
495 $md2xml->startExport();
496 $a_xml_writer->appendXML($md2xml->getXML());
497 }
498
502 function modifyExportIdentifier($a_tag, $a_param, $a_value)
503 {
504 if ($a_tag == "Identifier" && $a_param == "Entry")
505 {
506 $a_value = "il_".IL_INST_ID."_gdf_".$this->getId();
507 }
508
509 return $a_value;
510 }
511
512
519 function exportXMLDefinition(&$a_xml_writer, $a_inst = 0)
520 {
521
522 $this->page_object->buildDom();
523 $this->page_object->insertInstIntoIDs($a_inst);
524 $this->mobs_contained = $this->page_object->collectMediaObjects(false);
525 include_once("./Services/COPage/classes/class.ilPCFileList.php");
526 $this->files_contained = ilPCFileList::collectFileItems($this->page_object, $this->page_object->getDomDoc());
527 $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
528 $xml = str_replace("&","&amp;", $xml);
529 $a_xml_writer->appendXML($xml);
530
531 $this->page_object->freeDom();
532 }
533
537 function createMetaData()
538 {
539 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
540
541 global $ilUser;
542
545 $md_creator = new ilMDCreator($glo_id,$this->getId(),$this->getType());
546 $md_creator->setTitle($this->getTitle());
547 $md_creator->setTitleLanguage($lang);
548 $md_creator->setDescription($this->getDescription());
549 $md_creator->setDescriptionLanguage($lang);
550 $md_creator->setKeywordLanguage($lang);
551 $md_creator->setLanguage($lang);
552//echo "-".$this->getTitle()."-"; exit;
553 $md_creator->create();
554
555 return true;
556 }
557
561 function updateMetaData()
562 {
563 include_once("Services/MetaData/classes/class.ilMD.php");
564 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
565 include_once("Services/MetaData/classes/class.ilMDDescription.php");
566
568 $md =& new ilMD($glo_id, $this->getId(), $this->getType());
569 $md_gen =& $md->getGeneral();
570 $md_gen->setTitle($this->getTitle());
571
572 // sets first description (maybe not appropriate)
573 $md_des_ids =& $md_gen->getDescriptionIds();
574 if (count($md_des_ids) > 0)
575 {
576 $md_des =& $md_gen->getDescription($md_des_ids[0]);
577 $md_des->setDescription($this->getDescription());
578 $md_des->update();
579 }
580 $md_gen->update();
581 }
582
586 function deleteMetaData()
587 {
588 // Delete meta data
589 include_once('Services/MetaData/classes/class.ilMD.php');
591 $md = new ilMD($glo_id, $this->getId(), $this->getType());
592 $md->deleteAll();
593 }
594
609 function MDUpdateListener($a_element)
610 {
611 include_once 'Services/MetaData/classes/class.ilMD.php';
612
613 switch($a_element)
614 {
615 case 'General':
616
617 // Update Title and description
619 $md =& new ilMD($glo_id, $this->getId(), $this->getType());
620 $md_gen = $md->getGeneral();
621
622 //ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
623 $this->setTitle($md_gen->getTitle());
624
625 foreach($md_gen->getDescriptionIds() as $id)
626 {
627 $md_des = $md_gen->getDescription($id);
628 //ilObject::_writeDescription($this->getId(),$md_des->getDescription());
629 $this->setDescription($md_des->getDescription());
630 break;
631 }
632
633 break;
634
635 default:
636 }
637 return true;
638 }
639
645 function _lookupTermId($a_def_id)
646 {
647 global $ilDB;
648
649 $q = "SELECT * FROM glossary_definition WHERE id = ".
650 $ilDB->quote($a_def_id, "integer");
651 $def_set = $ilDB->query($q);
652 $def_rec = $ilDB->fetchAssoc($def_set);
653
654 return $def_rec["term_id"];
655 }
656
663 static function setShortTextsDirty($a_glo_id)
664 {
665 global $ilDB;
666
667 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
668 $term_ids = ilGlossaryTerm::getTermsOfGlossary($a_glo_id);
669
670 foreach ($term_ids as $term_id)
671 {
672 $ilDB->manipulate("UPDATE glossary_definition SET ".
673 " short_text_dirty = ".$ilDB->quote(1, "integer").
674 " WHERE term_id = ".$ilDB->quote($term_id, "integer")
675 );
676 }
677 }
678}
679
680?>
const LOCK_WRITE
Definition: class.ilDB.php:30
Glossary definition page object.
Class ilGlossaryDefinition.
exportXML(&$a_xml_writer, $a_inst)
export xml
createMetaData()
create meta data entry
getTitle()
get title of content object
updateMetaData()
update meta data entry
setDescription($a_description)
Set description.
_lookupTermId($a_def_id)
Looks up term id for a definition id.
setTitle($a_title)
set title of content object
setShortTextDirty($a_val)
Set short text dirty.
static setShortTextsDirty($a_glo_id)
Set short texts dirty.
exportXMLDefinition(&$a_xml_writer, $a_inst=0)
export page objects meta data to xml (see ilias_co.dtd)
getShortTextDirty()
Get short text dirty.
deleteMetaData()
delete meta data entry
modifyExportIdentifier($a_tag, $a_param, $a_value)
read()
read data of content object
create($a_upload=false, $a_omit_page_creation=false)
Create definition.
exportXMLMetaData(&$a_xml_writer)
export content objects meta data to xml (see ilias_co.dtd)
shortenShortText($text)
Shorten short text.
ilGlossaryDefinition($a_id=0)
Constructor @access public.
MDUpdateListener($a_element)
Meta data update listener.
Class ilGlossaryTerm.
static _lookGlossaryID($term_id)
get glossary id form term id
static _lookLanguage($term_id)
lookup term language
static getTermsOfGlossary($a_glo_id)
Get terms of glossary.
static lookupSnippetLength($a_id)
Lookup snippet length.
static collectFileItems($a_page, $a_domdoc)
Get all file items that are used within the page.
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
$text
redirection script todo: (a better solution should control the processing via a xml file)
global $ilDB
global $ilUser
Definition: imgupload.php:15