ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilGlossaryTerm.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
34 {
35  var $ilias;
36  var $lng;
37  var $tpl;
38 
39  var $id;
40  var $glossary;
41  var $term;
42  var $language;
43  var $glo_id;
45 
50  function ilGlossaryTerm($a_id = 0)
51  {
52  global $lng, $ilias, $tpl;
53 
54  $this->lng =& $lng;
55  $this->ilias =& $ilias;
56  $this->tpl =& $tpl;
57 
58  $this->id = $a_id;
59  $this->type = "term";
60  if ($a_id != 0)
61  {
62  $this->read();
63  }
64  }
65 
69  function read()
70  {
71  global $ilDB;
72 
73  $q = "SELECT * FROM glossary_term WHERE id = ".$ilDB->quote($this->id);
74  $term_set = $this->ilias->db->query($q);
75  $term_rec = $term_set->fetchRow(DB_FETCHMODE_ASSOC);
76 
77  $this->setTerm($term_rec["term"]);
78  $this->setImportId($term_rec["import_id"]);
79  $this->setLanguage($term_rec["language"]);
80  $this->setGlossaryId($term_rec["glo_id"]);
81 
82  }
83 
91  function _getIdForImportId($a_import_id)
92  {
93  global $ilDB;
94 
95  $q = "SELECT * FROM glossary_term WHERE import_id = ".$ilDB->quote($a_import_id).
96  " ORDER BY create_date DESC LIMIT 1";
97  $term_set = $ilDB->query($q);
98  while ($term_rec = $term_set->fetchRow(DB_FETCHMODE_ASSOC))
99  {
100  $glo_id = ilGlossaryTerm::_lookGlossaryID($term_rec["id"]);
101 
103  {
104  return $term_rec["id"];
105  }
106  }
107 
108  return 0;
109  }
110 
111 
119  function _exists($a_id)
120  {
121  global $ilDB;
122 
123  include_once("./Services/COPage/classes/class.ilInternalLink.php");
124  if (is_int(strpos($a_id, "_")))
125  {
127  }
128 
129  $q = "SELECT * FROM glossary_term WHERE id = ".$ilDB->quote($a_id);
130  $obj_set = $ilDB->query($q);
131  if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
132  {
133  return true;
134  }
135  else
136  {
137  return false;
138  }
139 
140  }
141 
142 
148  function setId($a_id)
149  {
150  $this->id = $a_id;
151  }
152 
153 
159  function getId()
160  {
161  return $this->id;
162  }
163 
169  function setGlossary(&$a_glossary)
170  {
171  $this->glossary =& $a_glossary;
172  $this->setGlossaryId($a_glossary->getId());
173  }
174 
175 
181  function setGlossaryId($a_glo_id)
182  {
183  $this->glo_id = $a_glo_id;
184  }
185 
186 
192  function getGlossaryId()
193  {
194  return $this->glo_id;
195  }
196 
197 
203  function setTerm($a_term)
204  {
205  $this->term = $a_term;
206  }
207 
208 
214  function getTerm()
215  {
216  return $this->term;
217  }
218 
219 
225  function setLanguage($a_language)
226  {
227  $this->language = $a_language;
228  }
229 
234  function getLanguage()
235  {
236  return $this->language;
237  }
238 
239 
243  function setImportId($a_import_id)
244  {
245  $this->import_id = $a_import_id;
246  }
247 
248 
252  function getImportId()
253  {
254  return $this->import_id;
255  }
256 
257 
261  function create()
262  {
263  global $ilDB;
264 
265  $q = "INSERT INTO glossary_term (glo_id, term, language, import_id, create_date, last_update)".
266  " VALUES (".$ilDB->quote($this->getGlossaryId()).", ".
267  $ilDB->quote($this->term).
268  ", ".$ilDB->quote($this->language).",".$ilDB->quote($this->getImportId()).",now(), now())";
269  $this->ilias->db->query($q);
270  $this->setId($this->ilias->db->getLastInsertId());
271  }
272 
273 
277  function delete()
278  {
279  global $ilDB;
280 
281  require_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
283  foreach($defs as $def)
284  {
285  $def_obj =& new ilGlossaryDefinition($def["id"]);
286  $def_obj->delete();
287  }
288  $q = "DELETE FROM glossary_term ".
289  " WHERE id = ".$ilDB->quote($this->getId());
290  $this->ilias->db->query($q);
291  }
292 
293 
297  function update()
298  {
299  global $ilDB;
300 
301  $q = "UPDATE glossary_term SET ".
302  " glo_id = ".$ilDB->quote($this->getGlossaryId()).", ".
303  " term = ".$ilDB->quote($this->getTerm()).", ".
304  " import_id = ".$ilDB->quote($this->getImportId()).", ".
305  " language = ".$ilDB->quote($this->getLanguage()).", ".
306  " last_update = now() ".
307  " WHERE id = ".$ilDB->quote($this->getId());
308  $this->ilias->db->query($q);
309  }
310 
314  function _lookGlossaryID($term_id)
315  {
316  global $ilDB;
317 
318  $query = "SELECT * FROM glossary_term WHERE id = ".$ilDB->quote($term_id);
319  $obj_set = $ilDB->query($query);
320  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
321 
322  return $obj_rec["glo_id"];
323  }
324 
328  function _lookGlossaryTerm($term_id)
329  {
330  global $ilDB;
331 
332  $query = "SELECT * FROM glossary_term WHERE id = ".$ilDB->quote($term_id);
333  $obj_set = $ilDB->query($query);
334  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
335 
336  return $obj_rec["term"];
337  }
338 
342  function _lookLanguage($term_id)
343  {
344  global $ilDB;
345 
346  $query = "SELECT * FROM glossary_term WHERE id = ".$ilDB->quote($term_id);
347  $obj_set = $ilDB->query($query);
348  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
349 
350  return $obj_rec["language"];
351  }
352 
360  function getTermList($a_glo_id, $searchterm="")
361  {
362  global $ilDB;
363 
364  $terms = array();
365 
366  $searchterm = (!empty ($searchterm))
367  ? " AND term like ".$ilDB->quote("%".$searchterm."%")." "
368  : "";
369 
370  // meta glossary
371  if (is_array($a_glo_id))
372  {
373  $where = "IN(".implode(",",$a_glo_id).") ";
374  }
375  else
376  {
377  $where = "= ".$ilDB->quote($a_glo_id)." ";
378  }
379 
380  $q = "SELECT * FROM glossary_term WHERE glo_id ".$where.$searchterm." ORDER BY language, term";
381  $term_set = $ilDB->query($q);
382 
383  while ($term_rec = $term_set->fetchRow(DB_FETCHMODE_ASSOC))
384  {
385  $terms[] = array("term" => $term_rec["term"],
386  "language" => $term_rec["language"], "id" => $term_rec["id"], "glo_id" => $term_rec["glo_id"]);
387  }
388  return $terms;
389  }
390 
394  function exportXML(&$a_xml_writer, $a_inst)
395  {
396 
397  $attrs = array();
398  $attrs["Language"] = $this->getLanguage();
399  $attrs["Id"] = "il_".IL_INST_ID."_git_".$this->getId();
400  $a_xml_writer->xmlStartTag("GlossaryItem", $attrs);
401 
402  $attrs = array();
403  $a_xml_writer->xmlElement("GlossaryTerm", $attrs, $this->getTerm());
404 
406 
407  foreach($defs as $def)
408  {
409  $definition = new ilGlossaryDefinition($def["id"]);
410  $definition->exportXML($a_xml_writer, $a_inst);
411  }
412 
413  $a_xml_writer->xmlEndTag("GlossaryItem");
414  }
415 
416 } // END class ilGlossaryTerm
417 
418 ?>