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

content/classes/class.ilGlossaryDefinition.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 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 require_once("content/classes/Pages/class.ilPageObject.php");
00025 
00034 class ilGlossaryDefinition
00035 {
00036         var $ilias;
00037         var $lng;
00038         var $tpl;
00039 
00040         var $id;
00041         var $term_id;
00042         var $glo_id;
00043         var $meta_data;
00044         var $page_object;
00045         var $short_text;
00046         var $nr;
00047 
00052         function ilGlossaryDefinition($a_id = 0)
00053         {
00054                 global $lng, $ilias, $tpl;
00055 
00056                 $this->lng =& $lng;
00057                 $this->ilias =& $ilias;
00058                 $this->tpl =& $tpl;
00059 
00060                 $this->id = $a_id;
00061                 if ($a_id == 0)
00062                 {
00063                         $new_meta =& new ilMetaData();
00064                         $this->assignMetaData($new_meta);
00065                 }
00066                 else
00067                 {
00068                         $this->read();
00069                 }
00070         }
00071 
00075         function read()
00076         {
00077                 $q = "SELECT * FROM glossary_definition WHERE id = '".$this->id."'";
00078                 $def_set = $this->ilias->db->query($q);
00079                 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00080 
00081                 $this->setTermId($def_rec["term_id"]);
00082                 $this->setShortText($def_rec["short_text"]);
00083                 $this->setNr($def_rec["nr"]);
00084 
00085                 $this->page_object =& new ilPageObject("gdf", $this->id);
00086                 $this->meta_data =& new ilMetaData("gdf", $this->id);
00087         }
00088 
00089         function setId($a_id)
00090         {
00091                 $this->id = $a_id;
00092         }
00093 
00094         function getId()
00095         {
00096                 return $this->id;
00097         }
00098 
00099         function assignMetaData(&$a_meta_data)
00100         {
00101                 $this->meta_data =& $a_meta_data;
00102         }
00103 
00104         function &getMetaData()
00105         {
00106                 return $this->meta_data;
00107         }
00108 
00109         function getType()
00110         {
00111                 return "gdf";
00112         }
00113 
00114         function setTermId($a_term_id)
00115         {
00116                 $this->term_id = $a_term_id;
00117         }
00118 
00119         function getTermId()
00120         {
00121                 return $this->term_id;
00122         }
00123 
00124         function setShortText($a_text)
00125         {
00126                 $this->short_text = $a_text;
00127         }
00128 
00129         function getShortText()
00130         {
00131                 return $this->short_text;
00132         }
00133 
00134         function setNr($a_nr)
00135         {
00136                 $this->nr = $a_nr;
00137         }
00138 
00139         function getNr()
00140         {
00141                 return $this->nr;
00142         }
00143 
00144         function assignPageObject(&$a_page_object)
00145         {
00146                 $this->page_object =& $a_page_object;
00147         }
00148 
00149         function &getPageObject()
00150         {
00151                 return $this->page_object;
00152         }
00153 
00159         function getTitle()
00160         {
00161 //              return parent::getTitle();
00162                 return $this->meta_data->getTitle();
00163         }
00164 
00168         function setTitle($a_title)
00169         {
00170 //              parent::setTitle($a_title);
00171                 $this->meta_data->setTitle($a_title);
00172         }
00173 
00179         function getDescription()
00180         {
00181 //              return parent::getDescription();
00182                 return $this->meta_data->getDescription();
00183         }
00184 
00188         function setDescription($a_description)
00189         {
00190 //              parent::setTitle($a_title);
00191                 $this->meta_data->setDescription($a_description);
00192         }
00193 
00194         function create()
00195         {
00196                 $term =& new ilGlossaryTerm($this->getTermId());
00197 
00198                 // lock glossary_definition table
00199                 $q = "LOCK TABLES glossary_definition WRITE";
00200                 $this->ilias->db->query($q);
00201 
00202                 // get maximum definition number
00203                 $q = "SELECT max(nr) AS max_nr FROM glossary_definition WHERE term_id = '".$this->getTermId()."'";
00204                 $max_set = $this->ilias->db->query($q);
00205                 $max_rec = $max_set->fetchRow(DB_FETCHMODE_ASSOC);
00206                 $max = (int) $max_rec["max_nr"];
00207 
00208                 // insert new definition record
00209                 $q = "INSERT INTO glossary_definition (term_id, short_text, nr)".
00210                         " VALUES ('".$this->getTermId()."','".ilUtil::prepareDBString($this->getShortText())."', '".($max + 1)."')";
00211                 $this->ilias->db->query($q);
00212 
00213                 // unlock glossary definition table
00214                 $q = "UNLOCK TABLES";
00215                 $this->ilias->db->query($q);
00216 
00217                 $this->setId($this->ilias->db->getLastInsertId());
00218 
00219                 // get number
00220                 $q = "SELECT nr FROM glossary_definition WHERE id = '".$this->id."'";
00221                 $def_set = $this->ilias->db->query($q);
00222                 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00223                 $this->setNr($def_rec["nr"]);
00224 
00225                 $this->meta_data->setId($this->getId());
00226                 $this->meta_data->setType($this->getType());
00227                 $this->meta_data->setTitle($this->getTitle());
00228                 $this->meta_data->setDescription($this->getDescription());
00229                 $this->meta_data->setObject($this);
00230                 $this->meta_data->create();
00231 
00232                 //$this->meta_data->setId($this->getId());
00233                 //$this->meta_data->setType($this->getType());
00234                 //$this->meta_data->create();
00235                 $this->page_object =& new ilPageObject("gdf");
00236                 $this->page_object->setId($this->getId());
00237                 $this->page_object->setParentId($term->getGlossaryId());
00238                 $this->page_object->create();
00239         }
00240 
00241         function delete()
00242         {
00243                 // lock glossary_definition table
00244                 $q = "LOCK TABLES glossary_definition WRITE";
00245                 $this->ilias->db->query($q);
00246 
00247                 // be sure to get the right number
00248                 $q = "SELECT * FROM glossary_definition WHERE id = '".$this->id."'";
00249                 $def_set = $this->ilias->db->query($q);
00250                 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00251                 $this->setNr($def_rec["nr"]);
00252 
00253                 // update numbers of other definitions
00254                 $q = "UPDATE glossary_definition SET ".
00255                         " nr = nr - 1 ".
00256                         " WHERE term_id = '".$this->getTermId()."' ".
00257                         " AND nr > ".$this->getNr();
00258                 $this->ilias->db->query($q);
00259 
00260                 // delete current definition
00261                 $q = "DELETE FROM glossary_definition ".
00262                         " WHERE id = '".$this->getId()."' ";
00263                 $this->ilias->db->query($q);
00264 
00265                 // unlock glossary_definition table
00266                 $q = "UNLOCK TABLES";
00267                 $this->ilias->db->query($q);
00268 
00269                 // delete page and meta data
00270                 $this->page_object->delete();
00271 
00272                 // delete meta data
00273                 $nested = new ilNestedSetXML();
00274                 $nested->init($this->getId(), $this->getType());
00275                 $nested->deleteAllDBData();
00276 
00277         }
00278 
00279 
00280         function moveUp()
00281         {
00282                 // lock glossary_definition table
00283                 $q = "LOCK TABLES glossary_definition WRITE";
00284                 $this->ilias->db->query($q);
00285 
00286                 // be sure to get the right number
00287                 $q = "SELECT * FROM glossary_definition WHERE id = '".$this->id."'";
00288                 $def_set = $this->ilias->db->query($q);
00289                 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00290                 $this->setNr($def_rec["nr"]);
00291 
00292                 if ($this->getNr() < 2)
00293                 {
00294                         $q = "UNLOCK TABLES";
00295                         $this->ilias->db->query($q);
00296                         return;
00297                 }
00298 
00299                 // update numbers of other definitions
00300                 $q = "UPDATE glossary_definition SET ".
00301                         " nr = nr + 1 ".
00302                         " WHERE term_id = '".$this->getTermId()."' ".
00303                         " AND nr = ".($this->getNr() - 1);
00304                 $this->ilias->db->query($q);
00305 
00306                 // delete current definition
00307                 $q = "UPDATE glossary_definition SET ".
00308                         " nr = nr - 1 ".
00309                         " WHERE term_id = '".$this->getTermId()."' ".
00310                         " AND id = ".$this->getId();
00311                 $this->ilias->db->query($q);
00312 
00313                 // unlock glossary_definition table
00314                 $q = "UNLOCK TABLES";
00315                 $this->ilias->db->query($q);
00316 
00317         }
00318 
00319 
00320         function moveDown()
00321         {
00322                 // lock glossary_definition table
00323                 $q = "LOCK TABLES glossary_definition WRITE";
00324                 $this->ilias->db->query($q);
00325 
00326                 // be sure to get the right number
00327                 $q = "SELECT * FROM glossary_definition WHERE id = '".$this->id."'";
00328                 $def_set = $this->ilias->db->query($q);
00329                 $def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC);
00330                 $this->setNr($def_rec["nr"]);
00331 
00332                 // get max number
00333                 $q = "SELECT max(nr) as max_nr FROM glossary_definition WHERE term_id = '".$this->getTermId()."'";
00334                 $max_set = $this->ilias->db->query($q);
00335                 $max_rec = $max_set->fetchRow(DB_FETCHMODE_ASSOC);
00336 
00337                 if ($this->getNr() >= $max_rec["max_nr"])
00338                 {
00339                         $q = "UNLOCK TABLES";
00340                         $this->ilias->db->query($q);
00341                         return;
00342                 }
00343 
00344                 // update numbers of other definitions
00345                 $q = "UPDATE glossary_definition SET ".
00346                         " nr = nr - 1 ".
00347                         " WHERE term_id = '".$this->getTermId()."' ".
00348                         " AND nr = ".($this->getNr() + 1);
00349                 $this->ilias->db->query($q);
00350 
00351                 // delete current definition
00352                 $q = "UPDATE glossary_definition SET ".
00353                         " nr = nr + 1 ".
00354                         " WHERE term_id = '".$this->getTermId()."' ".
00355                         " AND id = ".$this->getId();
00356                 $this->ilias->db->query($q);
00357 
00358                 // unlock glossary_definition table
00359                 $q = "UNLOCK TABLES";
00360                 $this->ilias->db->query($q);
00361 
00362         }
00363 
00364 
00365         function update()
00366         {
00367                 $q = "UPDATE glossary_definition SET ".
00368                         " term_id = '".$this->getTermId()."', ".
00369                         " nr = '".$this->getNr()."', ".
00370                         " short_text = '".ilUtil::prepareDBString($this->getShortText())."' ".
00371                         " WHERE id = '".$this->getId()."'";
00372                 $this->ilias->db->query($q);
00373         }
00374 
00375         function updateMetaData()
00376         {
00377                 $this->meta_data->update();
00378                 $this->setTitle($this->meta_data->getTitle());
00379                 $this->setDescription($this->meta_data->getDescription());
00380         }
00381 
00382         function updateShortText()
00383         {
00384                 $this->page_object->buildDom();
00385                 $text = $this->page_object->getFirstParagraphText();
00386                 //$this->setShortText(ilUtil::shortenText($text, 180, true));
00387                 $text = str_replace("<br/>", "<br>", $text);
00388 
00389                 $this->setShortText(ilUtil::shortenText(strip_tags($text, "<br>"), 180, true));
00390                 $this->update();
00391         }
00392 
00396         function getDefinitionList($a_term_id)
00397         {
00398                 $defs = array();
00399                 $q = "SELECT * FROM glossary_definition WHERE term_id ='".$a_term_id."' ORDER BY nr";
00400                 $def_set = $this->ilias->db->query($q);
00401                 while ($def_rec = $def_set->fetchRow(DB_FETCHMODE_ASSOC))
00402                 {
00403                         $defs[] = array("term_id" => $def_rec["term_id"],
00404                                 "page_id" => $def_rec["page_id"], "id" => $def_rec["id"],
00405                                 "short_text" => strip_tags($def_rec["short_text"], "<br>"),
00406                                 "nr" => $def_rec["nr"]);
00407                 }
00408                 return $defs;
00409         }
00410 
00414         function exportXML(&$a_xml_writer, $a_inst)
00415         {
00416                 $attrs = array();
00417                 $a_xml_writer->xmlStartTag("Definition", $attrs);
00418 
00419                 $this->exportXMLMetaData($a_xml_writer);
00420                 $this->exportXMLDefinition($a_xml_writer, $a_inst);
00421 
00422                 $a_xml_writer->xmlEndTag("Definition");
00423         }
00424 
00425 
00432         function exportXMLMetaData(&$a_xml_writer)
00433         {
00434                 $nested = new ilNestedSetXML();
00435                 $nested->setParameterModifier($this, "modifyExportIdentifier");
00436                 $a_xml_writer->appendXML($nested->export($this->getId(),
00437                         $this->getType()));
00438         }
00439 
00440 
00444         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00445         {
00446                 if ($a_tag == "Identifier" && $a_param == "Entry")
00447                 {
00448                         $a_value = "il_".IL_INST_ID."_gdf_".$this->getId();
00449                 }
00450 
00451                 return $a_value;
00452         }
00453 
00454 
00461         function exportXMLDefinition(&$a_xml_writer, $a_inst = 0)
00462         {
00463 
00464                 $this->page_object->buildDom();
00465                 $this->page_object->insertInstIntoIDs($a_inst);
00466                 $this->mobs_contained = $this->page_object->collectMediaObjects(false);
00467                 $this->files_contained = $this->page_object->collectFileItems();
00468                 $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
00469                 $xml = str_replace("&","&amp;", $xml);
00470                 $a_xml_writer->appendXML($xml);
00471 
00472                 $this->page_object->freeDom();
00473         }
00474 
00475 
00476 } // END class ilGlossaryDefinition
00477 
00478 ?>

Generated on Fri Dec 13 2013 09:06:35 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1