ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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{
19 protected $db;
20
24 protected $user;
25
26 public $lng;
27 public $tpl;
28
29 public $id;
30 public $term_id;
31 public $glo_id;
34 public $nr;
35 public $short_text_dirty = false;
36
41 public function __construct($a_id = 0)
42 {
43 global $DIC;
44
45 $this->db = $DIC->database();
46 $this->user = $DIC->user();
47 $lng = $DIC->language();
48 $tpl = $DIC["tpl"];
49
50 $this->lng = $lng;
51 $this->tpl = $tpl;
52
53 $this->id = $a_id;
54 if ($a_id != 0) {
55 $this->read();
56 }
57 }
58
62 public function read()
63 {
65
66 $q = "SELECT * FROM glossary_definition WHERE id = " .
67 $ilDB->quote($this->id, "integer");
68 $def_set = $ilDB->query($q);
69 $def_rec = $ilDB->fetchAssoc($def_set);
70
71 $this->setTermId($def_rec["term_id"]);
72 $this->setShortText($def_rec["short_text"]);
73 $this->setNr($def_rec["nr"]);
74 $this->setShortTextDirty($def_rec["short_text_dirty"]);
75
76 $this->page_object = new ilGlossaryDefPage($this->id);
77 }
78
79 public function setId($a_id)
80 {
81 $this->id = $a_id;
82 }
83
84 public function getId()
85 {
86 return $this->id;
87 }
88
89 public function getType()
90 {
91 return "gdf";
92 }
93
94 public function setTermId($a_term_id)
95 {
96 $this->term_id = $a_term_id;
97 }
98
99 public function getTermId()
100 {
101 return $this->term_id;
102 }
103
104 public function setShortText($a_text)
105 {
106 $this->short_text = $this->shortenShortText($a_text);
107 }
108
109 public function getShortText()
110 {
111 return $this->short_text;
112 }
113
114 public function setNr($a_nr)
115 {
116 $this->nr = $a_nr;
117 }
118
119 public function getNr()
120 {
121 return $this->nr;
122 }
123
124 public function assignPageObject(&$a_page_object)
125 {
126 $this->page_object = $a_page_object;
127 }
128
129 public function &getPageObject()
130 {
131 return $this->page_object;
132 }
133
139 public function getTitle()
140 {
141 return $this->title;
142 }
143
147 public function setTitle($a_title)
148 {
149 $this->title = $a_title;
150 }
151
157 public function getDescription()
158 {
159 return $this->description;
160 }
161
167 public function setDescription($a_description)
168 {
169 $this->description = $a_description;
170 }
171
177 public function setShortTextDirty($a_val)
178 {
179 $this->short_text_dirty = $a_val;
180 }
181
187 public function getShortTextDirty()
188 {
190 }
196 public function create($a_upload = false, $a_omit_page_creation = false)
197 {
199
200 $term = new ilGlossaryTerm($this->getTermId());
201
202 $this->setId($ilDB->nextId("glossary_definition"));
203
204 $ilAtomQuery = $ilDB->buildAtomQuery();
205 $ilAtomQuery->addTableLock('glossary_definition');
206
207 $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) {
208
209 // get maximum definition number
210 $q = "SELECT max(nr) AS max_nr FROM glossary_definition WHERE term_id = " .
211 $ilDB->quote($this->getTermId(), "integer");
212 $max_set = $ilDB->query($q);
213 $max_rec = $ilDB->fetchAssoc($max_set);
214 $max = (int) $max_rec["max_nr"];
215
216 // insert new definition record
217 $ilDB->manipulate("INSERT INTO glossary_definition (id, term_id, short_text, nr, short_text_dirty)" .
218 " VALUES (" .
219 $ilDB->quote($this->getId(), "integer") . "," .
220 $ilDB->quote($this->getTermId(), "integer") . "," .
221 $ilDB->quote($this->getShortText(), "text") . ", " .
222 $ilDB->quote(($max + 1), "integer") . ", " .
223 $ilDB->quote($this->getShortTextDirty(), "integer") .
224 ")");
225 });
226
227 $ilAtomQuery->run();
228
229 // get number
230 $q = "SELECT nr FROM glossary_definition WHERE id = " .
231 $ilDB->quote($this->id, "integer");
232 $def_set = $ilDB->query($q);
233 $def_rec = $ilDB->fetchAssoc($def_set);
234 $this->setNr($def_rec["nr"]);
235
236 // meta data will be created by
237 // import parser
238 if (!$a_upload) {
239 $this->createMetaData();
240 }
241
242 if (!$a_omit_page_creation) {
243 $this->page_object = new ilGlossaryDefPage();
244 $this->page_object->setId($this->getId());
245 $this->page_object->setParentId($term->getGlossaryId());
246 $this->page_object->create();
247 }
248 }
249
250 public function delete()
251 {
253
254 $ilAtomQuery = $ilDB->buildAtomQuery();
255 $ilAtomQuery->addTableLock("glossary_definition");
256
257 $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) {
258
259 // be sure to get the right number
260 $q = "SELECT * FROM glossary_definition WHERE id = " .
261 $ilDB->quote($this->id, "integer");
262 $def_set = $ilDB->query($q);
263 $def_rec = $ilDB->fetchAssoc($def_set);
264 $this->setNr($def_rec["nr"]);
265
266 // update numbers of other definitions
267 $ilDB->manipulate("UPDATE glossary_definition SET " .
268 " nr = nr - 1 " .
269 " WHERE term_id = " . $ilDB->quote($this->getTermId(), "integer") . " " .
270 " AND nr > " . $ilDB->quote($this->getNr(), "integer"));
271
272 // delete current definition
273 $ilDB->manipulate("DELETE FROM glossary_definition " .
274 " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
275 });
276 $ilAtomQuery->run();
277
278 // delete page and meta data
279 $this->page_object->delete();
280
281 // delete meta data
282 $this->deleteMetaData();
283 }
284
285
286 public function moveUp()
287 {
289
290 $ilAtomQuery = $ilDB->buildAtomQuery();
291 $ilAtomQuery->addTableLock('glossary_definition');
292
293 $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) {
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 return;
304 }
305
306 // update numbers of other definitions
307 $ilDB->manipulate("UPDATE glossary_definition SET " .
308 " nr = nr + 1 " .
309 " WHERE term_id = " . $ilDB->quote($this->getTermId(), "integer") . " " .
310 " AND nr = " . $ilDB->quote(($this->getNr() - 1), "integer"));
311
312 // delete current definition
313 $ilDB->manipulate("UPDATE glossary_definition SET " .
314 " nr = nr - 1 " .
315 " WHERE term_id = " . $ilDB->quote($this->getTermId(), "integer") . " " .
316 " AND id = " . $ilDB->quote($this->getId(), "integer"));
317 });
318 $ilAtomQuery->run();
319 }
320
321 public function moveDown()
322 {
324
325 $ilAtomQuery = $ilDB->buildAtomQuery();
326 $ilAtomQuery->addTableLock('glossary_definition');
327
328 $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) {
329
330 // be sure to get the right number
331 $q = "SELECT * FROM glossary_definition WHERE id = " .
332 $ilDB->quote($this->id, "integer");
333 $def_set = $ilDB->query($q);
334 $def_rec = $ilDB->fetchAssoc($def_set);
335 $this->setNr($def_rec["nr"]);
336
337 // get max number
338 $q = "SELECT max(nr) as max_nr FROM glossary_definition WHERE term_id = " .
339 $ilDB->quote($this->getTermId(), "integer");
340 $max_set = $ilDB->query($q);
341 $max_rec = $ilDB->fetchAssoc($max_set);
342
343 if ($this->getNr() >= $max_rec["max_nr"]) {
344 return;
345 }
346
347 // update numbers of other definitions
348 $ilDB->manipulate("UPDATE glossary_definition SET " .
349 " nr = nr - 1 " .
350 " WHERE term_id = " . $ilDB->quote($this->getTermId(), "integer") . " " .
351 " AND nr = " . $ilDB->quote(($this->getNr() + 1), "integer"));
352
353 // delete current definition
354 $ilDB->manipulate("UPDATE glossary_definition SET " .
355 " nr = nr + 1 " .
356 " WHERE term_id = " . $ilDB->quote($this->getTermId(), "integer") . " " .
357 " AND id = " . $ilDB->quote($this->getId(), "integer"));
358 });
359
360 $ilAtomQuery->run();
361 }
362
363
364 public function update()
365 {
367
368 $this->updateMetaData();
369
370 $ilDB->manipulate("UPDATE glossary_definition SET " .
371 " term_id = " . $ilDB->quote($this->getTermId(), "integer") . ", " .
372 " nr = " . $ilDB->quote($this->getNr(), "integer") . ", " .
373 " short_text = " . $ilDB->quote($this->getShortText(), "text") . ", " .
374 " short_text_dirty = " . $ilDB->quote($this->getShortTextDirty(), "integer") . " " .
375 " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
376 }
377
384 public function shortenShortText($text)
385 {
386 $a_length = 196;
387
388 if ($this->getTermId() > 0) {
389 include_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
390 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
391 $glo_id = ilGlossaryTerm::_lookGlossaryId($this->getTermId());
393 if ($snippet_length > 0) {
394 $a_length = $snippet_length;
395 }
396 }
397
398 $text = str_replace("<br/>", "<br>", $text);
399 $text = strip_tags($text, "<br>");
400 if (is_int(strpos(substr($text, $a_length - 16 - 5, 10), "[tex]"))) {
401 $offset = 5;
402 }
403 $short = ilUtil::shortenText($text, $a_length - 16 + $offset, true);
404
405 // make short text longer, if tex end tag is missing
406 $ltexs = strrpos($short, "[tex]");
407 $ltexe = strrpos($short, "[/tex]");
408 if ($ltexs > $ltexe) {
409 $ltexe = strpos($text, "[/tex]", $ltexs);
410 if ($ltexe > 0) {
411 $text = ilUtil::shortenText($text, $ltexe + 6, true);
412 }
413 }
414
415 $short = ilUtil::shortenText($text, $a_length, true);
416
417 return $short;
418 }
419
420 public function updateShortText()
421 {
422 $this->page_object->buildDom();
423 $text = $this->page_object->getFirstParagraphText();
424 $short = $this->shortenShortText($text);
425
426 $this->setShortText($short);
427 $this->setShortTextDirty(false);
428 $this->update();
429 }
430
434 public static function getDefinitionList($a_term_id)
435 {
436 global $DIC;
437
438 $ilDB = $DIC->database();
439
440 $defs = array();
441 $q = "SELECT * FROM glossary_definition WHERE term_id = " .
442 $ilDB->quote($a_term_id, "integer") .
443 " ORDER BY nr";
444 $def_set = $ilDB->query($q);
445 while ($def_rec = $ilDB->fetchAssoc($def_set)) {
446 $defs[] = array("term_id" => $def_rec["term_id"],
447 "page_id" => $def_rec["page_id"], "id" => $def_rec["id"],
448 "short_text" => strip_tags($def_rec["short_text"], "<br>"),
449 "nr" => $def_rec["nr"],
450 "short_text_dirty" => $def_rec["short_text_dirty"]);
451 }
452 return $defs;
453 }
454
458 public function exportXML(&$a_xml_writer, $a_inst)
459 {
460 $attrs = array();
461 $a_xml_writer->xmlStartTag("Definition", $attrs);
462
463 $this->exportXMLMetaData($a_xml_writer);
464 $this->exportXMLDefinition($a_xml_writer, $a_inst);
465
466 $a_xml_writer->xmlEndTag("Definition");
467 }
468
469
476 public function exportXMLMetaData(&$a_xml_writer)
477 {
479 include_once("Services/MetaData/classes/class.ilMD2XML.php");
480 $md2xml = new ilMD2XML($glo_id, $this->getId(), $this->getType());
481 $md2xml->setExportMode(true);
482 $md2xml->startExport();
483 $a_xml_writer->appendXML($md2xml->getXML());
484 }
485
489 public function modifyExportIdentifier($a_tag, $a_param, $a_value)
490 {
491 if ($a_tag == "Identifier" && $a_param == "Entry") {
492 $a_value = "il_" . IL_INST_ID . "_gdf_" . $this->getId();
493 }
494
495 return $a_value;
496 }
497
498
505 public function exportXMLDefinition(&$a_xml_writer, $a_inst = 0)
506 {
507 $this->page_object->buildDom();
508 $this->page_object->insertInstIntoIDs($a_inst);
509 $this->mobs_contained = $this->page_object->collectMediaObjects(false);
510 include_once("./Services/COPage/classes/class.ilPCFileList.php");
511 $this->files_contained = ilPCFileList::collectFileItems($this->page_object, $this->page_object->getDomDoc());
512 $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
513 $xml = str_replace("&", "&amp;", $xml);
514 $a_xml_writer->appendXML($xml);
515
516 $this->page_object->freeDom();
517 }
518
522 public function createMetaData()
523 {
524 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
525
527
530 $md_creator = new ilMDCreator($glo_id, $this->getId(), $this->getType());
531 $md_creator->setTitle($this->getTitle());
532 $md_creator->setTitleLanguage($lang);
533 $md_creator->setDescription($this->getDescription());
534 $md_creator->setDescriptionLanguage($lang);
535 $md_creator->setKeywordLanguage($lang);
536 $md_creator->setLanguage($lang);
537 //echo "-".$this->getTitle()."-"; exit;
538 $md_creator->create();
539
540 return true;
541 }
542
546 public function updateMetaData()
547 {
548 include_once("Services/MetaData/classes/class.ilMD.php");
549 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
550 include_once("Services/MetaData/classes/class.ilMDDescription.php");
551
553 $md = new ilMD($glo_id, $this->getId(), $this->getType());
554 $md_gen = $md->getGeneral();
555 $md_gen->setTitle($this->getTitle());
556
557 // sets first description (maybe not appropriate)
558 $md_des_ids = $md_gen->getDescriptionIds();
559 if (count($md_des_ids) > 0) {
560 $md_des = $md_gen->getDescription($md_des_ids[0]);
561 $md_des->setDescription($this->getDescription());
562 $md_des->update();
563 }
564 $md_gen->update();
565 }
566
570 public function deleteMetaData()
571 {
572 // Delete meta data
573 include_once('Services/MetaData/classes/class.ilMD.php');
575 $md = new ilMD($glo_id, $this->getId(), $this->getType());
576 $md->deleteAll();
577 }
578
593 public function MDUpdateListener($a_element)
594 {
595 include_once 'Services/MetaData/classes/class.ilMD.php';
596
597 switch ($a_element) {
598 case 'General':
599
600 // Update Title and description
602 $md = new ilMD($glo_id, $this->getId(), $this->getType());
603 $md_gen = $md->getGeneral();
604
605 //ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
606 $this->setTitle($md_gen->getTitle());
607
608 foreach ($md_gen->getDescriptionIds() as $id) {
609 $md_des = $md_gen->getDescription($id);
610 //ilObject::_writeDescription($this->getId(),$md_des->getDescription());
611 $this->setDescription($md_des->getDescription());
612 break;
613 }
614
615 break;
616
617 default:
618 }
619 return true;
620 }
621
627 public static function _lookupTermId($a_def_id)
628 {
629 global $DIC;
630
631 $ilDB = $DIC->database();
632
633 $q = "SELECT * FROM glossary_definition WHERE id = " .
634 $ilDB->quote($a_def_id, "integer");
635 $def_set = $ilDB->query($q);
636 $def_rec = $ilDB->fetchAssoc($def_set);
637
638 return $def_rec["term_id"];
639 }
640
647 public static function setShortTextsDirty($a_glo_id)
648 {
649 global $DIC;
650
651 $ilDB = $DIC->database();
652
653 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
654 $term_ids = ilGlossaryTerm::getTermsOfGlossary($a_glo_id);
655
656 foreach ($term_ids as $term_id) {
657 $ilDB->manipulate(
658 "UPDATE glossary_definition SET " .
659 " short_text_dirty = " . $ilDB->quote(1, "integer") .
660 " WHERE term_id = " . $ilDB->quote($term_id, "integer")
661 );
662 }
663 }
664
671 public static function setShortTextsDirtyGlobally()
672 {
673 global $DIC;
674
675 $ilDB = $DIC->database();
676
677 $ilDB->manipulate(
678 "UPDATE glossary_definition SET " .
679 " short_text_dirty = " . $ilDB->quote(1, "integer")
680 );
681 }
682}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Glossary definition page object.
Class ilGlossaryDefinition.
exportXML(&$a_xml_writer, $a_inst)
export xml
createMetaData()
create meta data entry
static _lookupTermId($a_def_id)
Looks up term id for a definition id.
getTitle()
get title of content object
updateMetaData()
update meta data entry
static getDefinitionList($a_term_id)
static
setDescription($a_description)
Set description.
setTitle($a_title)
set title of content object
setShortTextDirty($a_val)
Set short text dirty.
static setShortTextsDirtyGlobally()
Set short texts dirty.
static setShortTextsDirty($a_glo_id)
Set short texts dirty.
__construct($a_id=0)
Constructor @access public.
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.
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.
Interface ilDBInterface.
manipulate($query)
Run a (write) Query on the database.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18
$text
Definition: errorreport.php:18