ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilGlossaryTerm.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
14 var $ilias;
15 var $lng;
16 var $tpl;
17
18 var $id;
20 var $term;
24
29 function ilGlossaryTerm($a_id = 0)
30 {
31 global $lng, $ilias, $tpl;
32
33 $this->lng =& $lng;
34 $this->ilias =& $ilias;
35 $this->tpl =& $tpl;
36
37 $this->id = $a_id;
38 $this->type = "term";
39 if ($a_id != 0)
40 {
41 $this->read();
42 }
43 }
44
48 function read()
49 {
50 global $ilDB;
51
52 $q = "SELECT * FROM glossary_term WHERE id = ".
53 $ilDB->quote($this->id, "integer");
54 $term_set = $ilDB->query($q);
55 $term_rec = $ilDB->fetchAssoc($term_set);
56
57 $this->setTerm($term_rec["term"]);
58 $this->setImportId($term_rec["import_id"]);
59 $this->setLanguage($term_rec["language"]);
60 $this->setGlossaryId($term_rec["glo_id"]);
61
62 }
63
71 function _getIdForImportId($a_import_id)
72 {
73 global $ilDB;
74
75 if ($a_import_id == "")
76 {
77 return 0;
78 }
79
80 $q = "SELECT * FROM glossary_term WHERE import_id = ".
81 $ilDB->quote($a_import_id, "text").
82 " ORDER BY create_date DESC";
83 $term_set = $ilDB->query($q);
84 while ($term_rec = $ilDB->fetchAssoc($term_set))
85 {
87
88 $ref_ids = ilObject::_getAllReferences($glo_id); // will be 0 if import of lm is in progress (new import)
89 if (count($ref_ids) == 0 || ilObject::_hasUntrashedReference($glo_id))
90 {
91 return $term_rec["id"];
92 }
93 }
94
95 return 0;
96 }
97
98
106 function _exists($a_id)
107 {
108 global $ilDB;
109
110 include_once("./Services/Link/classes/class.ilInternalLink.php");
111 if (is_int(strpos($a_id, "_")))
112 {
114 }
115
116 $q = "SELECT * FROM glossary_term WHERE id = ".
117 $ilDB->quote($a_id, "integer");
118 $obj_set = $ilDB->query($q);
119 if ($obj_rec = $ilDB->fetchAssoc($obj_set))
120 {
121 return true;
122 }
123 else
124 {
125 return false;
126 }
127
128 }
129
130
136 function setId($a_id)
137 {
138 $this->id = $a_id;
139 }
140
141
147 function getId()
148 {
149 return $this->id;
150 }
151
157 function setGlossary(&$a_glossary)
158 {
159 $this->glossary =& $a_glossary;
160 $this->setGlossaryId($a_glossary->getId());
161 }
162
163
169 function setGlossaryId($a_glo_id)
170 {
171 $this->glo_id = $a_glo_id;
172 }
173
174
180 function getGlossaryId()
181 {
182 return $this->glo_id;
183 }
184
185
191 function setTerm($a_term)
192 {
193 $this->term = $a_term;
194 }
195
196
202 function getTerm()
203 {
204 return $this->term;
205 }
206
207
213 function setLanguage($a_language)
214 {
215 $this->language = $a_language;
216 }
217
222 function getLanguage()
223 {
224 return $this->language;
225 }
226
227
231 function setImportId($a_import_id)
232 {
233 $this->import_id = $a_import_id;
234 }
235
236
240 function getImportId()
241 {
242 return $this->import_id;
243 }
244
245
249 function create()
250 {
251 global $ilDB;
252
253 $this->setId($ilDB->nextId("glossary_term"));
254 $ilDB->manipulate("INSERT INTO glossary_term (id, glo_id, term, language, import_id, create_date, last_update)".
255 " VALUES (".
256 $ilDB->quote($this->getId(), "integer").", ".
257 $ilDB->quote($this->getGlossaryId(), "integer").", ".
258 $ilDB->quote($this->term, "text").", ".
259 $ilDB->quote($this->language, "text").",".
260 $ilDB->quote($this->getImportId(), "text").",".
261 $ilDB->now().", ".
262 $ilDB->now().")");
263 }
264
265
269 function delete()
270 {
271 global $ilDB;
272
273 require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
275 foreach($defs as $def)
276 {
277 $def_obj =& new ilGlossaryDefinition($def["id"]);
278 $def_obj->delete();
279 }
280 $ilDB->manipulate("DELETE FROM glossary_term ".
281 " WHERE id = ".$ilDB->quote($this->getId(), "integer"));
282 }
283
284
288 function update()
289 {
290 global $ilDB;
291
292 $ilDB->manipulate("UPDATE glossary_term SET ".
293 " glo_id = ".$ilDB->quote($this->getGlossaryId(), "integer").", ".
294 " term = ".$ilDB->quote($this->getTerm(), "text").", ".
295 " import_id = ".$ilDB->quote($this->getImportId(), "text").", ".
296 " language = ".$ilDB->quote($this->getLanguage(), "text").", ".
297 " last_update = ".$ilDB->now()." ".
298 " WHERE id = ".$ilDB->quote($this->getId(), "integer"));
299 }
300
304 static function _lookGlossaryID($term_id)
305 {
306 global $ilDB;
307
308 $query = "SELECT * FROM glossary_term WHERE id = ".
309 $ilDB->quote($term_id, "integer");
310 $obj_set = $ilDB->query($query);
311 $obj_rec = $ilDB->fetchAssoc($obj_set);
312
313 return $obj_rec["glo_id"];
314 }
315
319 static function _lookGlossaryTerm($term_id)
320 {
321 global $ilDB;
322
323 $query = "SELECT * FROM glossary_term WHERE id = ".
324 $ilDB->quote($term_id, "integer");
325 $obj_set = $ilDB->query($query);
326 $obj_rec = $ilDB->fetchAssoc($obj_set);
327
328 return $obj_rec["term"];
329 }
330
334 static function _lookLanguage($term_id)
335 {
336 global $ilDB;
337
338 $query = "SELECT * FROM glossary_term WHERE id = ".
339 $ilDB->quote($term_id, "integer");
340 $obj_set = $ilDB->query($query);
341 $obj_rec = $ilDB->fetchAssoc($obj_set);
342
343 return $obj_rec["language"];
344 }
345
354 static function getTermList($a_glo_id, $searchterm = "", $a_first_letter = "", $a_def = "",
355 $a_tax_node = 0, $a_add_amet_fields = false, array $a_amet_filter = null)
356 {
357 global $ilDB;
358
359 $terms = array();
360
361 // get all term ids under taxonomy node (if given)
362 if ($a_tax_node > 1)
363 {
364 include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
365 $tax_ids = ilObjTaxonomy::getUsageOfObject($a_glo_id);
366 if (count($tax_ids) > 0)
367 {
368 $items = ilObjTaxonomy::getSubTreeItems("glo", $a_glo_id, "term", $tax_ids[0], $a_tax_node);
369 $sub_tree_ids = array();
370 foreach ($items as $i)
371 {
372 $sub_tree_ids[] = $i["item_id"];
373 }
374 $in = " AND ".$ilDB->in("gt.id", $sub_tree_ids, false, "integer");
375 }
376 }
377
378 if ($a_def != "")
379 {
380 // meta glossary?
381 if (is_array($a_glo_id))
382 {
383 $glo_where = $ilDB->in("page_object.parent_id", $a_glo_id, false, "integer");
384 }
385 else
386 {
387 $glo_where = " page_object.parent_id = ".$ilDB->quote($a_glo_id, "integer");
388 }
389
390 $join = " JOIN glossary_definition gd ON (gd.term_id = gt.id)".
391 " JOIN page_object ON (".
392 $glo_where.
393 " AND page_object.parent_type = ".$ilDB->quote("gdf", "text").
394 " AND page_object.page_id = gd.id".
395 " AND ".$ilDB->like("page_object.content", "text", "%".$a_def."%").
396 ")";
397 }
398
399 $searchterm = (!empty ($searchterm))
400 ? " AND ".$ilDB->like("term", "text", "%".$searchterm."%")." "
401 : "";
402
403 if ($a_first_letter != "")
404 {
405 $searchterm.= " AND ".$ilDB->upper($ilDB->substr("term", 1, 1))." = ".$ilDB->upper($ilDB->quote($a_first_letter, "text"))." ";
406 }
407
408 // meta glossary
409 if (is_array($a_glo_id))
410 {
411 $where = $ilDB->in("glo_id", $a_glo_id, false, "integer");
412 }
413 else
414 {
415 $where = " glo_id = ".$ilDB->quote($a_glo_id, "integer")." ";
416 }
417
418 $where.= $in;
419
420 $q = "SELECT DISTINCT(gt.term), gt.id, gt.glo_id, gt.language FROM glossary_term gt ".$join." WHERE ".$where.$searchterm." ORDER BY term";
421 $term_set = $ilDB->query($q);
422//var_dump($q);
423 while ($term_rec = $ilDB->fetchAssoc($term_set))
424 {
425 $terms[] = array("term" => $term_rec["term"],
426 "language" => $term_rec["language"], "id" => $term_rec["id"], "glo_id" => $term_rec["glo_id"]);
427 }
428
429 // add advanced metadata
430 if ($a_add_amet_fields || is_array($a_amet_filter))
431 {
432 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
433 $terms = ilAdvancedMDValues::queryForRecords($a_glo_id, "term", $terms, "glo_id", "id", $a_amet_filter);
434 }
435 return $terms;
436 }
437
446 static function getFirstLetters($a_glo_id, $a_tax_node = 0)
447 {
448 global $ilDB;
449
450 $terms = array();
451
452 // meta glossary
453 if (is_array($a_glo_id))
454 {
455 $where = $ilDB->in("glo_id", $a_glo_id, false, "integer");
456 }
457 else
458 {
459 $where = " glo_id = ".$ilDB->quote($a_glo_id, "integer")." ";
460
461 // get all term ids under taxonomy node (if given)
462 if ($a_tax_node > 1)
463 {
464 include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
465 $tax_ids = ilObjTaxonomy::getUsageOfObject($a_glo_id);
466 if (count($tax_ids) > 0)
467 {
468 $items = ilObjTaxonomy::getSubTreeItems("glo", $a_glo_id, "term", $tax_ids[0], $a_tax_node);
469 $sub_tree_ids = array();
470 foreach ($items as $i)
471 {
472 $sub_tree_ids[] = $i["item_id"];
473 }
474 $in = " AND ".$ilDB->in("id", $sub_tree_ids, false, "integer");
475 }
476 }
477
478 $where.= $in;
479 }
480
481 $q = "SELECT DISTINCT ".$ilDB->upper($ilDB->substr("term", 1, 1))." let FROM glossary_term WHERE ".$where." ORDER BY let";
482 $let_set = $ilDB->query($q);
483
484 $lets = array();
485 while ($let_rec = $ilDB->fetchAssoc($let_set))
486 {
487 $let[$let_rec["let"]] = $let_rec["let"];
488 }
489 return $let;
490 }
491
495 function exportXML(&$a_xml_writer, $a_inst)
496 {
497
498 $attrs = array();
499 $attrs["Language"] = $this->getLanguage();
500 $attrs["Id"] = "il_".IL_INST_ID."_git_".$this->getId();
501 $a_xml_writer->xmlStartTag("GlossaryItem", $attrs);
502
503 $attrs = array();
504 $a_xml_writer->xmlElement("GlossaryTerm", $attrs, $this->getTerm());
505
507
508 foreach($defs as $def)
509 {
510 $definition = new ilGlossaryDefinition($def["id"]);
511 $definition->exportXML($a_xml_writer, $a_inst);
512 }
513
514 $a_xml_writer->xmlEndTag("GlossaryItem");
515 }
516
523 static function getNumberOfUsages($a_term_id)
524 {
525 return count(ilGlossaryTerm::getUsages($a_term_id));
526 }
527
534 static function getUsages($a_term_id)
535 {
536 include_once("./Services/Link/classes/class.ilInternalLink.php");
537 return (ilInternalLink::_getSourcesOfTarget("git", $a_term_id, 0));
538 }
539
546 function _copyTerm($a_term_id, $a_glossary_id)
547 {
548 $old_term = new ilGlossaryTerm($a_term_id);
549
550 // copy the term
551 $new_term = new ilGlossaryTerm();
552 $new_term->setTerm($old_term->getTerm());
553 $new_term->setLanguage($old_term->getLanguage());
554 $new_term->setGlossaryId($a_glossary_id);
555 $new_term->create();
556
557 // copy the definitions
558 include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
559 $def_list = ilGlossaryDefinition::getDefinitionList($a_term_id);
560 foreach ($def_list as $def)
561 {
562 $old_def = new ilGlossaryDefinition($def["id"]);
563
564 $new_def = new ilGlossaryDefinition();
565 $new_def->setShortText($old_def->getShortText());
566 $new_def->setNr($old_def->getNr());
567 $new_def->setTermId($new_term->getId());
568 $new_def->create();
569
570 // copy meta data
571 include_once("Services/MetaData/classes/class.ilMD.php");
572 $md = new ilMD($old_term->getGlossaryId(),
573 $old_def->getPageObject()->getId(),
574 $old_def->getPageObject()->getParentType());
575 $new_md = $md->cloneMD($a_glossary_id,
576 $new_def->getPageObject()->getId(),
577 $old_def->getPageObject()->getParentType());
578
579
580 $new_page = $new_def->getPageObject();
581 $old_def->getPageObject()->copy($new_page->getId(), $new_page->getParentType(), $new_page->getParentId(), true);
582
583 // page content
584 //$new_def->getPageObject()->setXMLContent($old_def->getPageObject()->copyXmlContent(true));
585 //$new_def->getPageObject()->buildDom();
586 //$new_def->getPageObject()->update();
587
588 }
589
590 return $new_term->getId();
591 }
592
599 static function getTermsOfGlossary($a_glo_id)
600 {
601 global $ilDB;
602
603 $set = $ilDB->query("SELECT id FROM glossary_term WHERE ".
604 " glo_id = ".$ilDB->quote($a_glo_id, "integer")
605 );
606 $ids = array();
607 while ($rec = $ilDB->fetchAssoc($set))
608 {
609 $ids[] = $rec["id"];
610 }
611 return $ids;
612 }
613}
614
615?>
static queryForRecords($a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key, array $a_amet_filter=null)
Query data for given object records.
Class ilGlossaryDefinition.
Class ilGlossaryTerm.
getId()
get term id (= glossary item id)
static getNumberOfUsages($a_term_id)
Get number of usages.
ilGlossaryTerm($a_id=0)
Constructor @access public.
setLanguage($a_language)
set language
create()
create new glossary term
static _lookGlossaryID($term_id)
get glossary id form term id
getGlossaryId()
get glossary id
_getIdForImportId($a_import_id)
get current term id for import id (static)
update()
update glossary term
setGlossaryId($a_glo_id)
set glossary id
_copyTerm($a_term_id, $a_glossary_id)
Copy a term to a glossary.
static getUsages($a_term_id)
Get number of usages.
static _lookGlossaryTerm($term_id)
get glossary term
static getTermList($a_glo_id, $searchterm="", $a_first_letter="", $a_def="", $a_tax_node=0, $a_add_amet_fields=false, array $a_amet_filter=null)
Get all terms for given set of glossary ids.
setId($a_id)
set glossary term id (= glossary item id)
static getFirstLetters($a_glo_id, $a_tax_node=0)
Get all terms for given set of glossary ids.
setGlossary(&$a_glossary)
set glossary object
read()
read glossary term data
getLanguage()
get language
static _lookLanguage($term_id)
lookup term language
exportXML(&$a_xml_writer, $a_inst)
export xml
_exists($a_id)
checks wether a glossary term with specified id exists or not
getImportId()
get import id
setTerm($a_term)
set term
setImportId($a_import_id)
set import id
static getTermsOfGlossary($a_glo_id)
Get terms of glossary.
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
static getSubTreeItems($a_comp, $a_obj_id, $a_item_type, $a_tax_id, $a_node)
Get all assigned items under a node.
_hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static _getAllReferences($a_id)
get all reference ids of object
redirection script todo: (a better solution should control the processing via a xml file)
global $ilDB