44         $this->db = $DIC->database();
    45         $lng = $DIC->language();
    56         $this->event_handler = $DIC->event();
    59     public function read(): void
    63         $q = 
"SELECT * FROM glossary_term WHERE id = " .
    66         $term_rec = 
$ilDB->fetchAssoc($term_set);
    68         $this->
setTerm((
string) $term_rec[
"term"]);
    69         $this->
setImportId((
string) $term_rec[
"import_id"]);
    83         $ilDB = $DIC->database();
    85         if ($a_import_id == 
"") {
    89         $q = 
"SELECT * FROM glossary_term WHERE import_id = " .
    90             $ilDB->quote($a_import_id, 
"text") .
    91             " ORDER BY create_date DESC";
    93         while ($term_rec = 
$ilDB->fetchAssoc($term_set)) {
    94             $glo_id = self::_lookGlossaryID($term_rec[
"id"]);
    98                 return (
int) $term_rec[
"id"];
   109     public static function _exists(
int $a_id): bool
   113         $ilDB = $DIC->database();
   115         if (is_int(strpos($a_id, 
"_"))) {
   119         $q = 
"SELECT * FROM glossary_term WHERE id = " .
   120             $ilDB->quote($a_id, 
"integer");
   122         if ($obj_rec = 
$ilDB->fetchAssoc($obj_set)) {
   133     public function setId(
int $a_id): void
   146         $this->glossary = $a_glossary;
   153         $this->glo_id = $a_glo_id;
   163         $this->term = $a_term;
   184         $this->import_id = $a_import_id;
   204         $this->short_text_dirty = $a_val;
   214         $this->page_object = $a_page_object;
   222     public function create(
bool $a_omit_page_creation = 
false): void
   227         $ilDB->manipulate(
"INSERT INTO glossary_term" .
   228             " (id, glo_id, term, language, import_id, create_date, last_update, short_text, short_text_dirty)" .
   230             $ilDB->quote($this->getId(), 
"integer") . 
", " .
   231             $ilDB->quote($this->getGlossaryId(), 
"integer") . 
", " .
   232             $ilDB->quote($this->getTerm(), 
"text") . 
", " .
   233             $ilDB->quote($this->getLanguage(), 
"text") . 
", " .
   234             $ilDB->quote($this->getImportId(), 
"text") . 
", " .
   235             $ilDB->now() . 
", " .
   236             $ilDB->now() . 
", " .
   240         if (!$a_omit_page_creation) {
   242             $this->page_object->setId($this->
getId());
   244             $this->page_object->create(
false);
   251     public function delete(): 
void   259         $ilDB->manipulate(
"DELETE FROM glossary_term " .
   260             " WHERE id = " . 
$ilDB->quote($this->getId(), 
"integer"));
   262         $this->page_object->delete();
   265         $this->event_handler->raise(
"Modules/Glossary", 
"deleteTerm", [
"term_id" => $this->
getId()]);
   272         $ilDB->manipulate(
"UPDATE glossary_term SET " .
   273             " glo_id = " . 
$ilDB->quote($this->getGlossaryId(), 
"integer") . 
", " .
   274             " term = " . 
$ilDB->quote($this->getTerm(), 
"text") . 
", " .
   275             " import_id = " . 
$ilDB->quote($this->getImportId(), 
"text") . 
", " .
   276             " language = " . 
$ilDB->quote($this->getLanguage(), 
"text") . 
", " .
   277             " last_update = " . 
$ilDB->now() . 
", " .
   280             " WHERE id = " . 
$ilDB->quote($this->
getId(), 
"integer"));
   290         if ($this->
getId() > 0) {
   291             $glo_id = self::_lookGlossaryID($this->
getId());
   293             if ($snippet_length > 0) {
   294                 $a_length = $snippet_length;
   298         $text = str_replace(
"<br/>", 
"<br>", $text);
   299         $text = strip_tags($text, 
"<br>");
   301         if (is_int(strpos(substr($text, $a_length - 16 - 5, 10), 
"[tex]"))) {
   307         $ltexs = strrpos($short, 
"[tex]");
   308         $ltexe = strrpos($short, 
"[/tex]");
   309         if ($ltexs > $ltexe) {
   310             $ltexe = strpos($text, 
"[/tex]", $ltexs);
   323         $this->page_object->buildDom();
   324         $text = $this->page_object->getFirstParagraphText();
   340         $ilDB = $DIC->database();
   342         $term_ids = self::getTermsOfGlossary($a_glo_id);
   344         foreach ($term_ids as $term_id) {
   346                 "UPDATE glossary_term SET " .
   347                 " short_text_dirty = " . 
$ilDB->quote(1, 
"integer") .
   348                 " WHERE id = " . 
$ilDB->quote($term_id, 
"integer")
   360         $ilDB = $DIC->database();
   363             "UPDATE glossary_term SET " .
   364             " short_text_dirty = " . 
$ilDB->quote(1, 
"integer")
   375         $ilDB = $DIC->database();
   377         $query = 
"SELECT * FROM glossary_term WHERE id = " .
   378             $ilDB->quote($term_id, 
"integer");
   379         $obj_set = 
$ilDB->query($query);
   380         $obj_rec = 
$ilDB->fetchAssoc($obj_set);
   382         return (
int) ($obj_rec[
"glo_id"] ?? 0);
   392         $ilDB = $DIC->database();
   394         $query = 
"SELECT * FROM glossary_term WHERE id = " .
   395             $ilDB->quote($term_id, 
"integer");
   396         $obj_set = 
$ilDB->query($query);
   397         $obj_rec = 
$ilDB->fetchAssoc($obj_set);
   399         return $obj_rec[
"term"] ?? 
"";
   409         $ilDB = $DIC->database();
   411         $query = 
"SELECT * FROM glossary_term WHERE id = " .
   412             $ilDB->quote($term_id, 
"integer");
   413         $obj_set = 
$ilDB->query($query);
   414         $obj_rec = 
$ilDB->fetchAssoc($obj_set);
   416         return $obj_rec[
"language"];
   426         $ilDB = $DIC->database();
   428         $query = 
"SELECT * FROM glossary_term WHERE id = " .
   429             $ilDB->quote($term_id, 
"integer");
   430         $obj_set = 
$ilDB->query($query);
   431         $obj_rec = 
$ilDB->fetchAssoc($obj_set);
   433         return $obj_rec[
"short_text"] ?? 
"";
   443         $ilDB = $DIC->database();
   445         $query = 
"SELECT * FROM glossary_term WHERE id = " .
   446             $ilDB->quote($term_id, 
"integer");
   447         $obj_set = 
$ilDB->query($query);
   448         $obj_rec = 
$ilDB->fetchAssoc($obj_set);
   450         return (
int) ($obj_rec[
"short_text_dirty"] ?? 0);
   458         string $searchterm = 
"",
   459         string $a_first_letter = 
"",
   462         bool $a_add_amet_fields = 
false,
   463         array $a_amet_filter = null,
   464         bool $a_include_references = 
false   468         if (count($a_glo_ref_id) > 1) {
   469             $a_glo_id = array_map(
static function ($id): 
int {
   475         $ilDB = $DIC->database();
   482         if ($a_tax_node > 1) {
   484             if (count($tax_ids) > 0) {
   486                 $sub_tree_ids = array();
   487                 foreach ($items as $i) {
   488                     $sub_tree_ids[] = $i[
"item_id"];
   490                 $in = 
" AND " . 
$ilDB->in(
"gt.id", $sub_tree_ids, 
false, 
"integer");
   496             if (is_array($a_glo_id)) {
   497                 $glo_where = 
$ilDB->in(
"page_object.parent_id", $a_glo_id, 
false, 
"integer");
   499                 $glo_where = 
" page_object.parent_id = " . 
$ilDB->quote($a_glo_id, 
"integer");
   502             $join = 
" JOIN page_object ON (" .
   504             " AND page_object.parent_type = " . 
$ilDB->quote(
"term", 
"text") .
   505             " AND page_object.page_id = gt.id" .
   506             " AND " . 
$ilDB->like(
"page_object.content", 
"text", 
"%" . $a_def . 
"%") .
   510         $searchterm = (!empty($searchterm))
   511             ? 
" AND " . 
$ilDB->like(
"term", 
"text", 
"%" . $searchterm . 
"%") . 
" "   514         if ($a_first_letter != 
"") {
   515             $searchterm .= 
" AND " . 
$ilDB->upper(
$ilDB->substr(
"term", 1, 1)) . 
" = " . 
$ilDB->upper(
$ilDB->quote($a_first_letter, 
"text")) . 
" ";
   519         $where_glo_id_or = 
"";
   520         if ($a_include_references) {
   521             $join .= 
" LEFT JOIN glo_term_reference tr ON (gt.id = tr.term_id) ";
   522             if (is_array($a_glo_id)) {
   523                 $where_glo_id_or = 
" OR " . 
$ilDB->in(
"tr.glo_id", $a_glo_id, 
false, 
"integer");
   525                 $where_glo_id_or = 
" OR tr.glo_id = " . 
$ilDB->quote($a_glo_id, 
"integer");
   530         if (is_array($a_glo_id)) {
   531             $where = 
"(" . 
$ilDB->in(
"gt.glo_id", $a_glo_id, 
false, 
"integer") . $where_glo_id_or . 
")";
   533             $where = 
"(gt.glo_id = " . 
$ilDB->quote($a_glo_id, 
"integer") . $where_glo_id_or . 
")";
   539         $q = 
"SELECT DISTINCT(gt.term), gt.id, gt.glo_id, gt.language, gt.short_text, gt.short_text_dirty FROM glossary_term gt " .
   540             $join . 
" WHERE " . $where . $searchterm . 
" ORDER BY gt.term, gt.id";
   544         while ($term_rec = 
$ilDB->fetchAssoc($term_set)) {
   545             $terms[] = array(
"term" => $term_rec[
"term"],
   546                 "language" => $term_rec[
"language"], 
"id" => $term_rec[
"id"], 
"glo_id" => $term_rec[
"glo_id"],
   547                 "short_text" => strip_tags((
string) $term_rec[
"short_text"], 
"<br>"),
   548                 "short_text_dirty" => $term_rec[
"short_text_dirty"]);
   549             $glo_ids[] = $term_rec[
"glo_id"];
   553         if (($a_add_amet_fields || is_array($a_amet_filter)) && count($a_glo_ref_id) == 1) {
   565         $ilDB = $DIC->database();
   568         if (count($a_glo_id) > 1) {
   569             $where = 
$ilDB->in(
"glo_id", $a_glo_id, 
false, 
"integer");
   571             $a_glo_id = current($a_glo_id);
   572             $where = 
" glo_id = " . 
$ilDB->quote($a_glo_id, 
"integer") . 
" ";
   575             if ($a_tax_node > 1) {
   577                 if (count($tax_ids) > 0) {
   579                     $sub_tree_ids = array();
   580                     foreach ($items as $i) {
   581                         $sub_tree_ids[] = $i[
"item_id"];
   583                     $in = 
" AND " . 
$ilDB->in(
"id", $sub_tree_ids, 
false, 
"integer");
   590         $q = 
"SELECT DISTINCT " . 
$ilDB->upper(
$ilDB->substr(
"term", 1, 1)) . 
" let FROM glossary_term WHERE " . $where . 
" ORDER BY let";
   594         while ($let_rec = 
$ilDB->fetchAssoc($let_set)) {
   595             $let[$let_rec[
"let"]] = $let_rec[
"let"];
   607         $a_xml_writer->
xmlStartTag(
"GlossaryItem", $attrs);
   612         $a_xml_writer->
xmlEndTag(
"GlossaryItem");
   617         return count(self::getUsages($a_term_id));
   625             $usages[
"glo:termref:" . $glo_id . 
":-"] = array(
   626                 "type" => 
"glo:termref",
   647         $new_term->setTerm($old_term->getTerm());
   648         $new_term->setLanguage($old_term->getLanguage());
   649         $new_term->setGlossaryId($a_glossary_id);
   650         $new_term->setShortText($old_term->getShortText());
   651         $new_term->setShortTextDirty($old_term->getShortTextDirty());
   656             $old_term->getGlossaryId(),
   657             $old_term->getPageObject()->getId(),
   658             $old_term->getPageObject()->getParentType()
   662             $new_term->getPageObject()->getId(),
   663             $old_term->getPageObject()->getParentType()
   666         $new_page = $new_term->getPageObject();
   667         $old_term->getPageObject()->copy($new_page->getId(), $new_page->getParentType(), $new_page->getParentId(), 
true);
   672         foreach ($old_recs as $old_record_obj) {
   674             foreach ($new_recs as $new_record_obj) {
   675                 if ($old_record_obj->getRecordId() == $new_record_obj->getRecordId()) {
   681                         $source_primary = array(
"obj_id" => array(
"integer", $old_term->getGlossaryId()));
   682                         $source_primary[
"sub_type"] = array(
"text", 
"term");
   683                         $source_primary[
"sub_id"] = array(
"integer", $old_term->getId());
   684                         $source_primary[
"field_id"] = array(
"integer", $def->getFieldId());
   685                         $target_primary = array(
"obj_id" => array(
"integer", $new_term->getGlossaryId()));
   686                         $target_primary[
"sub_type"] = array(
"text", 
"term");
   687                         $target_primary[
"sub_id"] = array(
"integer", $new_term->getId());
   693                                 "obj_id" => 
"integer",
   694                                 "sub_type" => 
"text",
   695                                 "sub_id" => 
"integer",
   696                                 "field_id" => 
"integer"   700                             array(
"disabled" => 
"integer")
   707         return $new_term->getId();
   718         $ilDB = $DIC->database();
   721             "SELECT id FROM glossary_term WHERE " .
   722             " glo_id = " . 
$ilDB->quote($a_glo_id, 
"integer")
   725         while ($rec = 
$ilDB->fetchAssoc($set)) {
   726             $ids[] = (
int) $rec[
"id"];
 
static deleteReferencesOfTerm(int $a_term_id)
Delete all references of a term. 
 
static _getSourcesOfTarget(string $a_target_type, int $a_target_id, int $a_target_inst)
get all sources of a link target 
 
static getUsages(int $a_term_id)
 
setShortTextDirty(int $a_val)
 
static _extractObjIdOfTarget(string $a_target)
Extract object id out of target. 
 
ilGlossaryDefPage $page_object
 
static getSubTreeItems(string $a_comp, int $a_obj_id, string $a_item_type, int $a_tax_id, $a_node)
Get all assigned items under a node. 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
static _exists(int $a_id)
checks whether a glossary term with specified id exists or not 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
assignPageObject(ilGlossaryDefPage $a_page_object)
 
static _getIdForImportId(string $a_import_id)
 
static _getAllReferences(int $id)
get all reference ids for object ID 
 
ilAppEventHandler $event_handler
 
setShortText(string $a_text)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash 
 
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
 
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
 
static getTermList(array $a_glo_ref_id, string $searchterm="", string $a_first_letter="", string $a_def="", int $a_tax_node=0, bool $a_add_amet_fields=false, array $a_amet_filter=null, bool $a_include_references=false)
Get all terms for given set of glossary ids. 
 
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id. 
 
static _lookShortTextDirty(int $term_id)
get definition short text dirty 
 
setGlossary(ilObjGlossary $a_glossary)
 
static _copyTerm(int $a_term_id, int $a_glossary_id)
Copy a term to a glossary. 
 
xmlEndTag(string $tag)
Writes an endtag. 
 
exportXML(ilXmlWriter $a_xml_writer, int $a_inst)
 
static lookupReferencesOfTerm(int $a_term_id)
 
create(bool $a_omit_page_creation=false)
 
shortenShortText(string $text)
Shorten short text. 
 
static _lookGlossaryTerm(int $term_id)
get glossary term 
 
static _lookupObjectId(int $ref_id)
 
static getTermsOfGlossary(int $a_glo_id)
 
static _lookShortText(int $term_id)
get definition short text 
 
ilGlobalTemplateInterface $tpl
 
setId(int $a_id)
set glossary term id (= glossary item id) 
 
static _lookLanguage(int $term_id)
lookup term language 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
setLanguage(string $a_language)
 
static cloneByPrimary(string $a_table, array $a_primary_def, array $a_source_primary, array $a_target_primary, array $a_additional=null)
Clone values by (partial) primary key. 
 
static queryForRecords(int $adv_rec_obj_ref_id, string $adv_rec_obj_type, string $adv_rec_obj_subtype, array $a_obj_id, string $a_subtype, array $a_records, string $a_obj_id_key, string $a_obj_subid_key, array $a_amet_filter=null)
 
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
 
static lookupSnippetLength(int $a_id)
 
static setShortTextsDirty(int $a_glo_id)
Set all short texts of glossary dirty (e.g. 
 
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag. 
 
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content) 
 
static getNumberOfUsages(int $a_term_id)
 
setGlossaryId(int $a_glo_id)
 
static setShortTextsDirtyGlobally()
Set short texts dirty (for all glossaries) 
 
static getFirstLetters(array $a_glo_id, int $a_tax_node=0)
 
setImportId(string $a_import_id)
 
cloneMD(int $a_rbac_id, int $a_obj_id, string $a_obj_type)
 
static _lookGlossaryID(int $term_id)
get glossary id form term id