ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilGlossaryDefinition.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Modules/Glossary/classes/class.ilGlossaryDefPage.php");
5 
15 {
16  var $ilias;
17  var $lng;
18  var $tpl;
19 
20  var $id;
21  var $term_id;
22  var $glo_id;
25  var $nr;
26  var $short_text_dirty = false;
27 
32  function __construct($a_id = 0)
33  {
34  global $lng, $ilias, $tpl;
35 
36  $this->lng = $lng;
37  $this->ilias = $ilias;
38  $this->tpl = $tpl;
39 
40  $this->id = $a_id;
41  if ($a_id != 0)
42  {
43  $this->read();
44  }
45  }
46 
50  function read()
51  {
52  global $ilDB;
53 
54  $q = "SELECT * FROM glossary_definition WHERE id = ".
55  $ilDB->quote($this->id, "integer");
56  $def_set = $ilDB->query($q);
57  $def_rec = $ilDB->fetchAssoc($def_set);
58 
59  $this->setTermId($def_rec["term_id"]);
60  $this->setShortText($def_rec["short_text"]);
61  $this->setNr($def_rec["nr"]);
62  $this->setShortTextDirty($def_rec["short_text_dirty"]);
63 
64  $this->page_object = new ilGlossaryDefPage($this->id);
65  }
66 
67  function setId($a_id)
68  {
69  $this->id = $a_id;
70  }
71 
72  function getId()
73  {
74  return $this->id;
75  }
76 
77  function getType()
78  {
79  return "gdf";
80  }
81 
82  function setTermId($a_term_id)
83  {
84  $this->term_id = $a_term_id;
85  }
86 
87  function getTermId()
88  {
89  return $this->term_id;
90  }
91 
92  function setShortText($a_text)
93  {
94  $this->short_text = $this->shortenShortText($a_text);
95  }
96 
97  function getShortText()
98  {
99  return $this->short_text;
100  }
101 
102  function setNr($a_nr)
103  {
104  $this->nr = $a_nr;
105  }
106 
107  function getNr()
108  {
109  return $this->nr;
110  }
111 
112  function assignPageObject(&$a_page_object)
113  {
114  $this->page_object = $a_page_object;
115  }
116 
117  function &getPageObject()
118  {
119  return $this->page_object;
120  }
121 
127  function getTitle()
128  {
129  return $this->title;
130  }
131 
135  function setTitle($a_title)
136  {
137  $this->title = $a_title;
138  }
139 
145  function getDescription()
146  {
147  return $this->description;
148  }
149 
155  function setDescription($a_description)
156  {
157  $this->description = $a_description;
158  }
159 
165  function setShortTextDirty($a_val)
166  {
167  $this->short_text_dirty = $a_val;
168  }
169 
175  function getShortTextDirty()
176  {
178  }
184  function create($a_upload = false, $a_omit_page_creation = false)
185  {
186  global $ilDB;
187 
188  $term = new ilGlossaryTerm($this->getTermId());
189 
190  $this->setId($ilDB->nextId("glossary_definition"));
191 
192  $ilAtomQuery = $ilDB->buildAtomQuery();
193  $ilAtomQuery->addTableLock('glossary_definition');
194 
195  $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) {
196 
197  // get maximum definition number
198  $q = "SELECT max(nr) AS max_nr FROM glossary_definition WHERE term_id = " .
199  $ilDB->quote($this->getTermId(), "integer");
200  $max_set = $ilDB->query($q);
201  $max_rec = $ilDB->fetchAssoc($max_set);
202  $max = (int)$max_rec["max_nr"];
203 
204  // insert new definition record
205  $ilDB->manipulate("INSERT INTO glossary_definition (id, term_id, short_text, nr, short_text_dirty)" .
206  " VALUES (" .
207  $ilDB->quote($this->getId(), "integer") . "," .
208  $ilDB->quote($this->getTermId(), "integer") . "," .
209  $ilDB->quote($this->getShortText(), "text") . ", " .
210  $ilDB->quote(($max + 1), "integer") . ", " .
211  $ilDB->quote($this->getShortTextDirty(), "integer") .
212  ")");
213 
214  });
215 
216  $ilAtomQuery->run();
217 
218  // get number
219  $q = "SELECT nr FROM glossary_definition WHERE id = ".
220  $ilDB->quote($this->id, "integer");
221  $def_set = $ilDB->query($q);
222  $def_rec = $ilDB->fetchAssoc($def_set);
223  $this->setNr($def_rec["nr"]);
224 
225  // meta data will be created by
226  // import parser
227  if (!$a_upload)
228  {
229  $this->createMetaData();
230  }
231 
232  if (!$a_omit_page_creation)
233  {
234  $this->page_object = new ilGlossaryDefPage();
235  $this->page_object->setId($this->getId());
236  $this->page_object->setParentId($term->getGlossaryId());
237  $this->page_object->create();
238  }
239  }
240 
241  function delete()
242  {
243  global $ilDB;
244 
245  $ilAtomQuery = $ilDB->buildAtomQuery();
246  $ilAtomQuery->addTableLock("glossary_definition");
247 
248  $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB){
249 
250  // be sure to get the right number
251  $q = "SELECT * FROM glossary_definition WHERE id = ".
252  $ilDB->quote($this->id, "integer");
253  $def_set = $ilDB->query($q);
254  $def_rec = $ilDB->fetchAssoc($def_set);
255  $this->setNr($def_rec["nr"]);
256 
257  // update numbers of other definitions
258  $ilDB->manipulate("UPDATE glossary_definition SET ".
259  " nr = nr - 1 ".
260  " WHERE term_id = ".$ilDB->quote($this->getTermId(), "integer")." ".
261  " AND nr > ".$ilDB->quote($this->getNr(), "integer"));
262 
263  // delete current definition
264  $ilDB->manipulate("DELETE FROM glossary_definition ".
265  " WHERE id = ".$ilDB->quote($this->getId(), "integer"));
266 
267  });
268  $ilAtomQuery->run();
269 
270  // delete page and meta data
271  $this->page_object->delete();
272 
273  // delete meta data
274  $this->deleteMetaData();
275  }
276 
277 
278  function moveUp()
279  {
280  global $ilDB;
281 
282  $ilAtomQuery = $ilDB->buildAtomQuery();
283  $ilAtomQuery->addTableLock('glossary_definition');
284 
285  $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) {
286 
287  // be sure to get the right number
288  $q = "SELECT * FROM glossary_definition WHERE id = " .
289  $ilDB->quote($this->id, "integer");
290  $def_set = $ilDB->query($q);
291  $def_rec = $ilDB->fetchAssoc($def_set);
292  $this->setNr($def_rec["nr"]);
293 
294  if ($this->getNr() < 2) {
295  return;
296  }
297 
298  // update numbers of other definitions
299  $ilDB->manipulate("UPDATE glossary_definition SET " .
300  " nr = nr + 1 " .
301  " WHERE term_id = " . $ilDB->quote($this->getTermId(), "integer") . " " .
302  " AND nr = " . $ilDB->quote(($this->getNr() - 1), "integer"));
303 
304  // delete current definition
305  $ilDB->manipulate("UPDATE glossary_definition SET " .
306  " nr = nr - 1 " .
307  " WHERE term_id = " . $ilDB->quote($this->getTermId(), "integer") . " " .
308  " AND id = " . $ilDB->quote($this->getId(), "integer"));
309 
310  });
311  $ilAtomQuery->run();
312  }
313 
314  function moveDown()
315  {
316  global $ilDB;
317 
318  $ilAtomQuery = $ilDB->buildAtomQuery();
319  $ilAtomQuery->addTableLock('glossary_definition');
320 
321  $ilAtomQuery->addQueryCallable(function(ilDBInterface $ilDB){
322 
323  // be sure to get the right number
324  $q = "SELECT * FROM glossary_definition WHERE id = ".
325  $ilDB->quote($this->id, "integer");
326  $def_set = $ilDB->query($q);
327  $def_rec = $ilDB->fetchAssoc($def_set);
328  $this->setNr($def_rec["nr"]);
329 
330  // get max number
331  $q = "SELECT max(nr) as max_nr FROM glossary_definition WHERE term_id = ".
332  $ilDB->quote($this->getTermId(), "integer");
333  $max_set = $ilDB->query($q);
334  $max_rec = $ilDB->fetchAssoc($max_set);
335 
336  if ($this->getNr() >= $max_rec["max_nr"])
337  {
338  return;
339  }
340 
341  // update numbers of other definitions
342  $ilDB->manipulate("UPDATE glossary_definition SET ".
343  " nr = nr - 1 ".
344  " WHERE term_id = ".$ilDB->quote($this->getTermId(), "integer")." ".
345  " AND nr = ".$ilDB->quote(($this->getNr() + 1), "integer"));
346 
347  // delete current definition
348  $ilDB->manipulate("UPDATE glossary_definition SET ".
349  " nr = nr + 1 ".
350  " WHERE term_id = ".$ilDB->quote($this->getTermId(), "integer")." ".
351  " AND id = ".$ilDB->quote($this->getId(), "integer"));
352 
353  });
354 
355  $ilAtomQuery->run();
356  }
357 
358 
359  function update()
360  {
361  global $ilDB;
362 
363  $this->updateMetaData();
364 
365  $ilDB->manipulate("UPDATE glossary_definition SET ".
366  " term_id = ".$ilDB->quote($this->getTermId(), "integer").", ".
367  " nr = ".$ilDB->quote($this->getNr(), "integer").", ".
368  " short_text = ".$ilDB->quote($this->getShortText(), "text").", ".
369  " short_text_dirty = ".$ilDB->quote($this->getShortTextDirty(), "integer")." ".
370  " WHERE id = ".$ilDB->quote($this->getId(), "integer"));
371  }
372 
380  {
381  $a_length = 196;
382 
383  if ($this->getTermId() > 0)
384  {
385  include_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
386  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
387  $glo_id = ilGlossaryTerm::_lookGlossaryId($this->getTermId());
388  $snippet_length = ilObjGlossary::lookupSnippetLength($glo_id);
389  if ($snippet_length > 0)
390  {
391  $a_length = $snippet_length;
392  }
393  }
394 
395  $text = str_replace("<br/>", "<br>", $text);
396  $text = strip_tags($text, "<br>");
397  if (is_int(strpos(substr($text, $a_length - 16 - 5, 10), "[tex]")))
398  {
399  $offset = 5;
400  }
401  $short = ilUtil::shortenText($text, $a_length - 16 + $offset, true);
402 
403  // make short text longer, if tex end tag is missing
404  $ltexs = strrpos($short, "[tex]");
405  $ltexe = strrpos($short, "[/tex]");
406  if ($ltexs > $ltexe)
407  {
408  $ltexe = strpos($text, "[/tex]", $ltexs);
409  if ($ltexe > 0)
410  {
411  $short = ilUtil::shortenText($text, $ltexe+6, true);
412  }
413  }
414 
415  $short = ilUtil::shortenText($text, $a_length, true);
416 
417  return $short;
418  }
419 
420  function updateShortText()
421  {
422  $this->page_object->buildDom();
423  $text = $this->page_object->getFirstParagraphText();
424 
425  $short = $this->shortenShortText($text);
426 
427  $this->setShortText($short);
428  $this->setShortTextDirty(false);
429  $this->update();
430  }
431 
435  static function getDefinitionList($a_term_id)
436  {
437  global $ilDB;
438 
439  $defs = array();
440  $q = "SELECT * FROM glossary_definition WHERE term_id = ".
441  $ilDB->quote($a_term_id, "integer").
442  " ORDER BY nr";
443  $def_set = $ilDB->query($q);
444  while ($def_rec = $ilDB->fetchAssoc($def_set))
445  {
446  $defs[] = array("term_id" => $def_rec["term_id"],
447  "page_id" => $def_rec["page_id"], "id" => $def_rec["id"],
448  "short_text" => strip_tags($def_rec["short_text"], "<br>"),
449  "nr" => $def_rec["nr"],
450  "short_text_dirty" => $def_rec["short_text_dirty"]);
451  }
452  return $defs;
453  }
454 
458  function exportXML(&$a_xml_writer, $a_inst)
459  {
460  $attrs = array();
461  $a_xml_writer->xmlStartTag("Definition", $attrs);
462 
463  $this->exportXMLMetaData($a_xml_writer);
464  $this->exportXMLDefinition($a_xml_writer, $a_inst);
465 
466  $a_xml_writer->xmlEndTag("Definition");
467  }
468 
469 
476  function exportXMLMetaData(&$a_xml_writer)
477  {
478  $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
479  include_once("Services/MetaData/classes/class.ilMD2XML.php");
480  $md2xml = new ilMD2XML($glo_id, $this->getId(), $this->getType());
481  $md2xml->setExportMode(true);
482  $md2xml->startExport();
483  $a_xml_writer->appendXML($md2xml->getXML());
484  }
485 
489  function modifyExportIdentifier($a_tag, $a_param, $a_value)
490  {
491  if ($a_tag == "Identifier" && $a_param == "Entry")
492  {
493  $a_value = "il_".IL_INST_ID."_gdf_".$this->getId();
494  }
495 
496  return $a_value;
497  }
498 
499 
506  function exportXMLDefinition(&$a_xml_writer, $a_inst = 0)
507  {
508 
509  $this->page_object->buildDom();
510  $this->page_object->insertInstIntoIDs($a_inst);
511  $this->mobs_contained = $this->page_object->collectMediaObjects(false);
512  include_once("./Services/COPage/classes/class.ilPCFileList.php");
513  $this->files_contained = ilPCFileList::collectFileItems($this->page_object, $this->page_object->getDomDoc());
514  $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
515  $xml = str_replace("&","&amp;", $xml);
516  $a_xml_writer->appendXML($xml);
517 
518  $this->page_object->freeDom();
519  }
520 
524  function createMetaData()
525  {
526  include_once 'Services/MetaData/classes/class.ilMDCreator.php';
527 
528  global $ilUser;
529 
530  $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
532  $md_creator = new ilMDCreator($glo_id,$this->getId(),$this->getType());
533  $md_creator->setTitle($this->getTitle());
534  $md_creator->setTitleLanguage($lang);
535  $md_creator->setDescription($this->getDescription());
536  $md_creator->setDescriptionLanguage($lang);
537  $md_creator->setKeywordLanguage($lang);
538  $md_creator->setLanguage($lang);
539 //echo "-".$this->getTitle()."-"; exit;
540  $md_creator->create();
541 
542  return true;
543  }
544 
548  function updateMetaData()
549  {
550  include_once("Services/MetaData/classes/class.ilMD.php");
551  include_once("Services/MetaData/classes/class.ilMDGeneral.php");
552  include_once("Services/MetaData/classes/class.ilMDDescription.php");
553 
554  $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
555  $md = new ilMD($glo_id, $this->getId(), $this->getType());
556  $md_gen = $md->getGeneral();
557  $md_gen->setTitle($this->getTitle());
558 
559  // sets first description (maybe not appropriate)
560  $md_des_ids = $md_gen->getDescriptionIds();
561  if (count($md_des_ids) > 0)
562  {
563  $md_des = $md_gen->getDescription($md_des_ids[0]);
564  $md_des->setDescription($this->getDescription());
565  $md_des->update();
566  }
567  $md_gen->update();
568  }
569 
573  function deleteMetaData()
574  {
575  // Delete meta data
576  include_once('Services/MetaData/classes/class.ilMD.php');
577  $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
578  $md = new ilMD($glo_id, $this->getId(), $this->getType());
579  $md->deleteAll();
580  }
581 
596  function MDUpdateListener($a_element)
597  {
598  include_once 'Services/MetaData/classes/class.ilMD.php';
599 
600  switch($a_element)
601  {
602  case 'General':
603 
604  // Update Title and description
605  $glo_id = ilGlossaryTerm::_lookGlossaryID($this->getTermId());
606  $md = new ilMD($glo_id, $this->getId(), $this->getType());
607  $md_gen = $md->getGeneral();
608 
609  //ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
610  $this->setTitle($md_gen->getTitle());
611 
612  foreach($md_gen->getDescriptionIds() as $id)
613  {
614  $md_des = $md_gen->getDescription($id);
615  //ilObject::_writeDescription($this->getId(),$md_des->getDescription());
616  $this->setDescription($md_des->getDescription());
617  break;
618  }
619 
620  break;
621 
622  default:
623  }
624  return true;
625  }
626 
632  static function _lookupTermId($a_def_id)
633  {
634  global $ilDB;
635 
636  $q = "SELECT * FROM glossary_definition WHERE id = ".
637  $ilDB->quote($a_def_id, "integer");
638  $def_set = $ilDB->query($q);
639  $def_rec = $ilDB->fetchAssoc($def_set);
640 
641  return $def_rec["term_id"];
642  }
643 
650  static function setShortTextsDirty($a_glo_id)
651  {
652  global $ilDB;
653 
654  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
655  $term_ids = ilGlossaryTerm::getTermsOfGlossary($a_glo_id);
656 
657  foreach ($term_ids as $term_id)
658  {
659  $ilDB->manipulate("UPDATE glossary_definition SET ".
660  " short_text_dirty = ".$ilDB->quote(1, "integer").
661  " WHERE term_id = ".$ilDB->quote($term_id, "integer")
662  );
663  }
664  }
665 }
666 
667 ?>
static getDefinitionList($a_term_id)
static
__construct($a_id=0)
Constructor public.
modifyExportIdentifier($a_tag, $a_param, $a_value)
updateMetaData()
update meta data entry
Class ilGlossaryTerm.
getTitle()
get title of content object
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
setShortTextDirty($a_val)
Set short text dirty.
static _lookupTermId($a_def_id)
Looks up term id for a definition id.
setDescription($a_description)
Set description.
Interface ilDBInterface.
quote($value, $type)
static collectFileItems($a_page, $a_domdoc)
Get all file items that are used within the page.
deleteMetaData()
delete meta data entry
setTitle($a_title)
set title of content object
exportXMLDefinition(&$a_xml_writer, $a_inst=0)
export page objects meta data to xml (see ilias_co.dtd)
$ilUser
Definition: imgupload.php:18
redirection script todo: (a better solution should control the processing via a xml file) ...
read()
read data of content object
static _lookLanguage($term_id)
lookup term language
Glossary definition page object.
Create styles array
The data for the language used.
MDUpdateListener($a_element)
Meta data update listener.
static _lookGlossaryID($term_id)
get glossary id form term id
Class ilGlossaryDefinition.
createMetaData()
create meta data entry
exportXML(&$a_xml_writer, $a_inst)
export xml
global $ilDB
query($query)
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
fetchAssoc($query_result)
$text
static getTermsOfGlossary($a_glo_id)
Get terms of glossary.
exportXMLMetaData(&$a_xml_writer)
export content objects meta data to xml (see ilias_co.dtd)
shortenShortText($text)
Shorten short text.
manipulate($query)
static setShortTextsDirty($a_glo_id)
Set short texts dirty.
getShortTextDirty()
Get short text dirty.
static lookupSnippetLength($a_id)
Lookup snippet length.
create($a_upload=false, $a_omit_page_creation=false)
Create definition.