Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00033 class ilGlossaryTerm
00034 {
00035 var $ilias;
00036 var $lng;
00037 var $tpl;
00038
00039 var $id;
00040 var $glossary;
00041 var $term;
00042 var $language;
00043 var $glo_id;
00044 var $import_id;
00045
00050 function ilGlossaryTerm($a_id = 0)
00051 {
00052 global $lng, $ilias, $tpl;
00053
00054 $this->lng =& $lng;
00055 $this->ilias =& $ilias;
00056 $this->tpl =& $tpl;
00057
00058 $this->id = $a_id;
00059 $this->type = "term";
00060 if ($a_id != 0)
00061 {
00062 $this->read();
00063 }
00064 }
00065
00069 function read()
00070 {
00071 global $ilDB;
00072
00073 $q = "SELECT * FROM glossary_term WHERE id = ".$ilDB->quote($this->id);
00074 $term_set = $this->ilias->db->query($q);
00075 $term_rec = $term_set->fetchRow(DB_FETCHMODE_ASSOC);
00076
00077 $this->setTerm($term_rec["term"]);
00078 $this->setImportId($term_rec["import_id"]);
00079 $this->setLanguage($term_rec["language"]);
00080 $this->setGlossaryId($term_rec["glo_id"]);
00081
00082 }
00083
00091 function _getIdForImportId($a_import_id)
00092 {
00093 global $ilDB;
00094
00095 $q = "SELECT * FROM glossary_term WHERE import_id = ".$ilDB->quote($a_import_id).
00096 " ORDER BY create_date DESC LIMIT 1";
00097 $term_set = $ilDB->query($q);
00098 while ($term_rec = $term_set->fetchRow(DB_FETCHMODE_ASSOC))
00099 {
00100 $glo_id = ilGlossaryTerm::_lookGlossaryID($term_rec["id"]);
00101
00102 if (ilObject::_hasUntrashedReference($glo_id))
00103 {
00104 return $term_rec["id"];
00105 }
00106 }
00107
00108 return 0;
00109 }
00110
00111
00119 function _exists($a_id)
00120 {
00121 global $ilDB;
00122
00123 include_once("./Services/COPage/classes/class.ilInternalLink.php");
00124 if (is_int(strpos($a_id, "_")))
00125 {
00126 $a_id = ilInternalLink::_extractObjIdOfTarget($a_id);
00127 }
00128
00129 $q = "SELECT * FROM glossary_term WHERE id = ".$ilDB->quote($a_id);
00130 $obj_set = $ilDB->query($q);
00131 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00132 {
00133 return true;
00134 }
00135 else
00136 {
00137 return false;
00138 }
00139
00140 }
00141
00142
00148 function setId($a_id)
00149 {
00150 $this->id = $a_id;
00151 }
00152
00153
00159 function getId()
00160 {
00161 return $this->id;
00162 }
00163
00169 function setGlossary(&$a_glossary)
00170 {
00171 $this->glossary =& $a_glossary;
00172 $this->setGlossaryId($a_glossary->getId());
00173 }
00174
00175
00181 function setGlossaryId($a_glo_id)
00182 {
00183 $this->glo_id = $a_glo_id;
00184 }
00185
00186
00192 function getGlossaryId()
00193 {
00194 return $this->glo_id;
00195 }
00196
00197
00203 function setTerm($a_term)
00204 {
00205 $this->term = $a_term;
00206 }
00207
00208
00214 function getTerm()
00215 {
00216 return $this->term;
00217 }
00218
00219
00225 function setLanguage($a_language)
00226 {
00227 $this->language = $a_language;
00228 }
00229
00234 function getLanguage()
00235 {
00236 return $this->language;
00237 }
00238
00239
00243 function setImportId($a_import_id)
00244 {
00245 $this->import_id = $a_import_id;
00246 }
00247
00248
00252 function getImportId()
00253 {
00254 return $this->import_id;
00255 }
00256
00257
00261 function create()
00262 {
00263 global $ilDB;
00264
00265 $q = "INSERT INTO glossary_term (glo_id, term, language, import_id, create_date, last_update)".
00266 " VALUES (".$ilDB->quote($this->getGlossaryId()).", ".
00267 $ilDB->quote($this->term).
00268 ", ".$ilDB->quote($this->language).",".$ilDB->quote($this->getImportId()).",now(), now())";
00269 $this->ilias->db->query($q);
00270 $this->setId($this->ilias->db->getLastInsertId());
00271 }
00272
00273
00277 function delete()
00278 {
00279 global $ilDB;
00280
00281 require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
00282 $defs = ilGlossaryDefinition::getDefinitionList($this->getId());
00283 foreach($defs as $def)
00284 {
00285 $def_obj =& new ilGlossaryDefinition($def["id"]);
00286 $def_obj->delete();
00287 }
00288 $q = "DELETE FROM glossary_term ".
00289 " WHERE id = ".$ilDB->quote($this->getId());
00290 $this->ilias->db->query($q);
00291 }
00292
00293
00297 function update()
00298 {
00299 global $ilDB;
00300
00301 $q = "UPDATE glossary_term SET ".
00302 " glo_id = ".$ilDB->quote($this->getGlossaryId()).", ".
00303 " term = ".$ilDB->quote($this->getTerm()).", ".
00304 " import_id = ".$ilDB->quote($this->getImportId()).", ".
00305 " language = ".$ilDB->quote($this->getLanguage()).", ".
00306 " last_update = now() ".
00307 " WHERE id = ".$ilDB->quote($this->getId());
00308 $this->ilias->db->query($q);
00309 }
00310
00314 function _lookGlossaryID($term_id)
00315 {
00316 global $ilDB;
00317
00318 $query = "SELECT * FROM glossary_term WHERE id = ".$ilDB->quote($term_id);
00319 $obj_set = $ilDB->query($query);
00320 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00321
00322 return $obj_rec["glo_id"];
00323 }
00324
00328 function _lookGlossaryTerm($term_id)
00329 {
00330 global $ilDB;
00331
00332 $query = "SELECT * FROM glossary_term WHERE id = ".$ilDB->quote($term_id);
00333 $obj_set = $ilDB->query($query);
00334 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00335
00336 return $obj_rec["term"];
00337 }
00338
00342 function _lookLanguage($term_id)
00343 {
00344 global $ilDB;
00345
00346 $query = "SELECT * FROM glossary_term WHERE id = ".$ilDB->quote($term_id);
00347 $obj_set = $ilDB->query($query);
00348 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00349
00350 return $obj_rec["language"];
00351 }
00352
00360 function getTermList($a_glo_id, $searchterm="")
00361 {
00362 global $ilDB;
00363
00364 $terms = array();
00365
00366 $searchterm = (!empty ($searchterm))
00367 ? " AND term like ".$ilDB->quote("%".$searchterm."%")." "
00368 : "";
00369
00370
00371 if (is_array($a_glo_id))
00372 {
00373 $where = "IN(".implode(",",$a_glo_id).") ";
00374 }
00375 else
00376 {
00377 $where = "= ".$ilDB->quote($a_glo_id)." ";
00378 }
00379
00380 $q = "SELECT * FROM glossary_term WHERE glo_id ".$where.$searchterm." ORDER BY language, term";
00381 $term_set = $ilDB->query($q);
00382
00383 while ($term_rec = $term_set->fetchRow(DB_FETCHMODE_ASSOC))
00384 {
00385 $terms[] = array("term" => $term_rec["term"],
00386 "language" => $term_rec["language"], "id" => $term_rec["id"], "glo_id" => $term_rec["glo_id"]);
00387 }
00388 return $terms;
00389 }
00390
00394 function exportXML(&$a_xml_writer, $a_inst)
00395 {
00396
00397 $attrs = array();
00398 $attrs["Language"] = $this->getLanguage();
00399 $attrs["Id"] = "il_".IL_INST_ID."_git_".$this->getId();
00400 $a_xml_writer->xmlStartTag("GlossaryItem", $attrs);
00401
00402 $attrs = array();
00403 $a_xml_writer->xmlElement("GlossaryTerm", $attrs, $this->getTerm());
00404
00405 $defs = ilGlossaryDefinition::getDefinitionList($this->getId());
00406
00407 foreach($defs as $def)
00408 {
00409 $definition = new ilGlossaryDefinition($def["id"]);
00410 $definition->exportXML($a_xml_writer, $a_inst);
00411 }
00412
00413 $a_xml_writer->xmlEndTag("GlossaryItem");
00414 }
00415
00416 }
00417
00418 ?>