• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

content/classes/class.ilGlossaryTerm.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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                 $q = "SELECT * FROM glossary_term WHERE id = '".$this->id."'";
00072                 $term_set = $this->ilias->db->query($q);
00073                 $term_rec = $term_set->fetchRow(DB_FETCHMODE_ASSOC);
00074 
00075                 $this->setTerm($term_rec["term"]);
00076                 $this->setImportId($term_rec["import_id"]);
00077                 $this->setLanguage($term_rec["language"]);
00078                 $this->setGlossaryId($term_rec["glo_id"]);
00079 
00080         }
00081 
00089         function _getIdForImportId($a_import_id)
00090         {
00091                 global $ilDB;
00092                 
00093                 $q = "SELECT * FROM glossary_term WHERE import_id = '".$a_import_id."'".
00094                         " ORDER BY create_date DESC LIMIT 1";
00095                 $term_set = $ilDB->query($q);
00096                 while ($term_rec = $term_set->fetchRow(DB_FETCHMODE_ASSOC))
00097                 {
00098                         $glo_id = ilGlossaryTerm::_lookGlossaryID($term_rec["id"]);
00099 
00100                         if (ilObject::_hasUntrashedReference($glo_id))
00101                         {
00102                                 return $term_rec["id"];
00103                         }
00104                 }
00105 
00106                 return 0;
00107         }
00108         
00109         
00117         function _exists($a_id)
00118         {
00119                 global $ilDB;
00120                 
00121                 include_once("content/classes/Pages/class.ilInternalLink.php");
00122                 if (is_int(strpos($a_id, "_")))
00123                 {
00124                         $a_id = ilInternalLink::_extractObjIdOfTarget($a_id);
00125                 }
00126 
00127                 $q = "SELECT * FROM glossary_term WHERE id = '".$a_id."'";
00128                 $obj_set = $ilDB->query($q);
00129                 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00130                 {
00131                         return true;
00132                 }
00133                 else
00134                 {
00135                         return false;
00136                 }
00137 
00138         }
00139 
00140 
00146         function setId($a_id)
00147         {
00148                 $this->id = $a_id;
00149         }
00150 
00151 
00157         function getId()
00158         {
00159                 return $this->id;
00160         }
00161 
00167         function setGlossary(&$a_glossary)
00168         {
00169                 $this->glossary =& $a_glossary;
00170                 $this->setGlossaryId($a_glossary->getId());
00171         }
00172 
00173 
00179         function setGlossaryId($a_glo_id)
00180         {
00181                 $this->glo_id = $a_glo_id;
00182         }
00183 
00184 
00190         function getGlossaryId()
00191         {
00192                 return $this->glo_id;
00193         }
00194 
00195 
00201         function setTerm($a_term)
00202         {
00203                 $this->term = $a_term;
00204         }
00205 
00206 
00212         function getTerm()
00213         {
00214                 return $this->term;
00215         }
00216 
00217 
00223         function setLanguage($a_language)
00224         {
00225                 $this->language = $a_language;
00226         }
00227 
00232         function getLanguage()
00233         {
00234                 return $this->language;
00235         }
00236 
00237 
00241         function setImportId($a_import_id)
00242         {
00243                 $this->import_id = $a_import_id;
00244         }
00245 
00246 
00250         function getImportId()
00251         {
00252                 return $this->import_id;
00253         }
00254 
00255 
00259         function create()
00260         {
00261                 $q = "INSERT INTO glossary_term (glo_id, term, language, import_id, create_date, last_update)".
00262                         " VALUES ('".$this->getGlossaryId()."', '".ilUtil::prepareDBString($this->term).
00263                         "', '".$this->language."','".$this->getImportId()."',now(), now())";
00264                 $this->ilias->db->query($q);
00265                 $this->setId($this->ilias->db->getLastInsertId());
00266         }
00267 
00268 
00272         function delete()
00273         {
00274                 require_once("content/classes/class.ilGlossaryDefinition.php");
00275                 $defs = ilGlossaryDefinition::getDefinitionList($this->getId());
00276                 foreach($defs as $def)
00277                 {
00278                         $def_obj =& new ilGlossaryDefinition($def["id"]);
00279                         $def_obj->delete();
00280                 }
00281                 $q = "DELETE FROM glossary_term ".
00282                         " WHERE id = '".$this->getId()."'";
00283                 $this->ilias->db->query($q);
00284         }
00285 
00286 
00290         function update()
00291         {
00292                 $q = "UPDATE glossary_term SET ".
00293                         " glo_id = '".$this->getGlossaryId()."', ".
00294                         " term = '".ilUtil::prepareDBString($this->getTerm())."', ".
00295                         " import_id = '".$this->getImportId()."', ".
00296                         " language = '".$this->getLanguage()."', ".
00297                         " last_update = now() ".
00298                         " WHERE id = '".$this->getId()."'";
00299                 $this->ilias->db->query($q);
00300         }
00301 
00305         function _lookGlossaryID($term_id)
00306         {
00307                 global $ilDB;
00308 
00309                 $query = "SELECT * FROM glossary_term WHERE id = '".$term_id."'";
00310                 $obj_set = $ilDB->query($query);
00311                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00312 
00313                 return $obj_rec["glo_id"];
00314         }
00315 
00319         function _lookGlossaryTerm($term_id)
00320         {
00321                 global $ilDB;
00322 
00323                 $query = "SELECT * FROM glossary_term WHERE id = '".$term_id."'";
00324                 $obj_set = $ilDB->query($query);
00325                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00326 
00327                 return $obj_rec["term"];
00328         }
00329         
00333         function _lookLanguage($term_id)
00334         {
00335                 global $ilDB;
00336 
00337                 $query = "SELECT * FROM glossary_term WHERE id = '".$term_id."'";
00338                 $obj_set = $ilDB->query($query);
00339                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00340 
00341                 return $obj_rec["language"];
00342         }
00343 
00351         function getTermList($a_glo_id, $searchterm="")
00352         {
00353                 global $ilDB;
00354                 
00355                 $terms = array();
00356                 
00357                 $searchterm = (!empty ($searchterm))
00358                         ? " AND term like '%".$searchterm."%'"
00359                         : "";
00360                 
00361                 // meta glossary
00362                 if (is_array($a_glo_id))
00363                 {
00364                         $where = "IN(".implode(",",$a_glo_id).") ";
00365                 }
00366                 else
00367                 {
00368                         $where = "='".$a_glo_id."' ";
00369                 }
00370                 
00371                 $q = "SELECT * FROM glossary_term WHERE glo_id ".$where.$searchterm." ORDER BY language, term";
00372                 $term_set = $ilDB->query($q);
00373 
00374                 while ($term_rec = $term_set->fetchRow(DB_FETCHMODE_ASSOC))
00375                 {
00376                         $terms[] = array("term" => $term_rec["term"],
00377                                 "language" => $term_rec["language"], "id" => $term_rec["id"], "glo_id" => $term_rec["glo_id"]);
00378                 }
00379                 return $terms;
00380         }
00381 
00385         function exportXML(&$a_xml_writer, $a_inst)
00386         {
00387                 //include_once("content/classes/class..php");
00388 
00389                 $attrs = array();
00390                 $attrs["Language"] = $this->getLanguage();
00391                 $attrs["Id"] = "il_".IL_INST_ID."_git_".$this->getId();
00392                 $a_xml_writer->xmlStartTag("GlossaryItem", $attrs);
00393 
00394                 $attrs = array();
00395                 $a_xml_writer->xmlElement("GlossaryTerm", $attrs, $this->getTerm());
00396 
00397                 $defs = ilGlossaryDefinition::getDefinitionList($this->getId());
00398 
00399                 foreach($defs as $def)
00400                 {
00401                         $definition = new ilGlossaryDefinition($def["id"]);
00402                         $definition->exportXML($a_xml_writer, $a_inst);
00403                 }
00404 
00405                 $a_xml_writer->xmlEndTag("GlossaryItem");
00406         }
00407 
00408 } // END class ilGlossaryTerm
00409 
00410 ?>

Generated on Fri Dec 13 2013 13:52:09 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1