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