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

content/classes/class.ilLMPageObject.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/class.ilLMObject.php");
00025 require_once("content/classes/Pages/class.ilPageObject.php");
00026 
00027 define ("IL_CHAPTER_TITLE", "st_title");
00028 define ("IL_PAGE_TITLE", "pg_title");
00029 define ("IL_NO_HEADER", "none");
00030 
00048 class ilLMPageObject extends ilLMObject
00049 {
00050         var $is_alias;
00051         var $origin_id;
00052         var $id;
00053         var $ilias;
00054         var $dom;
00055         var $page_object;
00056 
00061         function ilLMPageObject(&$a_content_obj, $a_id = 0, $a_halt = true)
00062         {
00063                 global $ilias, $ilBench;
00064 
00065                 $ilBench->start("ContentPresentation", "ilLMPageObject_Constructor");
00066 
00067                 parent::ilLMObject($a_content_obj, $a_id);
00068                 $this->setType("pg");
00069                 $this->id = $a_id;
00070                 $this->ilias =& $ilias;
00071 
00072                 $this->is_alias = false;
00073                 $this->contains_int_link = false;
00074                 $this->mobs_contained  = array();
00075                 $this->files_contained  = array();
00076                 $this->halt_on_error = $a_halt;
00077 
00078                 if($a_id != 0)
00079                 {
00080                         $this->read();
00081                 }
00082 
00083                 $ilBench->stop("ContentPresentation", "ilLMPageObject_Constructor");
00084         }
00085 
00086         function _ilLMPageObject()
00087         {
00088                 if(is_object($this->page_object))
00089                 {
00090                         unset($this->page_object);
00091                 }
00092         }
00093 
00097         function read()
00098         {
00099                 global $ilBench;
00100 
00101                 $ilBench->start("ContentPresentation", "ilLMPageObject_read");
00102                 parent::read();
00103 
00104                 $this->page_object =& new ilPageObject($this->content_object->getType(),
00105                         $this->id, $this->halt_on_error);
00106 
00107                 $ilBench->stop("ContentPresentation", "ilLMPageObject_read");
00108         }
00109 
00110         function create($a_upload = false)
00111         {
00112                 parent::create($a_upload);
00113                 if(!is_object($this->page_object))
00114                 {
00115                         $this->page_object =& new ilPageObject($this->content_object->getType());
00116                 }
00117                 $this->page_object->setId($this->getId());
00118                 $this->page_object->setParentId($this->getLMId());
00119                 $this->page_object->create($a_upload);
00120         }
00121 
00122         function delete($a_delete_meta_data = true)
00123         {
00124                 parent::delete($a_delete_meta_data);
00125                 $this->page_object->delete();
00126         }
00127 
00128         
00132         function &copy()
00133         {
00134 
00135                 $meta =& new ilMetaData();
00136                 $lm_page =& new ilLMPageObject($this->getContentObject());
00137                 $lm_page->assignMetaData($meta);
00138                 $lm_page->setTitle($this->getTitle());
00139                 $lm_page->setLMId($this->getLMId());
00140                 $lm_page->setType($this->getType());
00141                 $lm_page->setDescription($this->getDescription());
00142                 $lm_page->create();
00143 
00144                 $page =& $lm_page->getPageObject();
00145                 $page->setXMLContent($this->page_object->getXMLContent());
00146                 $page->buildDom();
00147                 $page->update();
00148 
00149                 return $lm_page;
00150         }
00151 
00155         function &copyToOtherContObject(&$a_cont_obj)
00156         {
00157 //echo "<br>from page lm:".$this->getLMId().", pg: ".$this->getId();
00158                 $meta =& new ilMetaData();
00159                 $lm_page =& new ilLMPageObject($a_cont_obj);
00160                 $lm_page->assignMetaData($meta);
00161                 $lm_page->setTitle($this->getTitle());
00162                 $lm_page->setLMId($a_cont_obj->getId());
00163                 $lm_page->setType($this->getType());
00164                 $lm_page->setDescription($this->getDescription());
00165                 $lm_page->create();
00166 //echo "<br>to page lm:".$lm_page->getLMId().", pg: ".$lm_page->getId();
00167 
00168                 $page =& $lm_page->getPageObject();
00169                 $page->setXMLContent($this->page_object->getXMLContent());
00170                 $page->buildDom();
00171                 $page->update();
00172 
00173                 return $lm_page;
00174         }
00175         
00183         function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
00184         {
00185                 // get content object (learning module / digilib book)
00186                 $lm_id = ilLMObject::_lookupContObjID($a_page_id);
00187                 $type = ilObject::_lookupType($lm_id, false);
00188                 switch ($type)
00189                 {
00190                         case "lm":
00191                                 include_once ("content/classes/class.ilObjLearningModule.php");
00192                                 $cont_obj = new ilObjLearningModule($lm_id, false);
00193                                 break;
00194 
00195                         case "dbk":
00196                                 include_once ("content/classes/class.ilObjDlBook.php");
00197                                 $cont_obj = new ilObjDlBook($lm_id, false);
00198                                 break;
00199                 }
00200 
00201                 $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
00202 
00203                 // create new page
00204                 $meta =& new ilMetaData();
00205                 $lm_page =& new ilLMPageObject($cont_obj);
00206                 $lm_page->assignMetaData($meta);
00207                 $lm_page->setTitle($source_lm_page->getTitle());
00208                 $lm_page->setLMId($source_lm_page->getLMId());
00209                 $lm_page->setType($source_lm_page->getType());
00210                 $lm_page->setDescription($source_lm_page->getDescription());
00211                 $lm_page->create();
00212 
00213                 // copy complete content of source page to new page
00214                 $source_page =& $source_lm_page->getPageObject();
00215                 $page =& $lm_page->getPageObject();
00216                 $page->setXMLContent($source_page->getXMLContent());
00217                 $page->buildDom();
00218                 
00219                 // insert new page in tree (after original page)
00220                 $tree = new ilTree($cont_obj->getId());
00221                 $tree->setTableNames('lm_tree','lm_data');
00222                 $tree->setTreeTablePK("lm_id");
00223                 if ($tree->isInTree($source_lm_page->getId()))
00224                 {
00225                         $parent_node = $tree->getParentNodeData($source_lm_page->getId());
00226                         $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId());
00227                 }
00228                 
00229                 // remove all nodes >= hierarchical id from source page
00230                 $source_page->buildDom();
00231                 $source_page->addHierIds();
00232                 $source_page->deleteContentFromHierId($a_hier_id);
00233                 
00234                 // remove all nodes < hierarchical id from new page (incl. update)
00235                 $page->addHierIds();
00236                 $page->deleteContentBeforeHierId($a_hier_id);
00237                 
00238                 return $lm_page;
00239                 
00240         }
00241 
00249         function _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
00250         {
00251                 // get content object (learning module / digilib book)
00252                 $lm_id = ilLMObject::_lookupContObjID($a_page_id);
00253                 $type = ilObject::_lookupType($lm_id, false);
00254                 switch ($type)
00255                 {
00256                         case "lm":
00257                                 include_once ("content/classes/class.ilObjLearningModule.php");
00258                                 $cont_obj = new ilObjLearningModule($lm_id, false);
00259                                 break;
00260 
00261                         case "dbk":
00262                                 include_once ("content/classes/class.ilObjDlBook.php");
00263                                 $cont_obj = new ilObjDlBook($lm_id, false);
00264                                 break;
00265                 }
00266                 $tree = new ilTree($cont_obj->getId());
00267                 $tree->setTableNames('lm_tree','lm_data');
00268                 $tree->setTreeTablePK("lm_id");
00269 
00270                 $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
00271                 $source_page =& $source_lm_page->getPageObject();
00272                 
00273                 // get next page
00274                 $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
00275                 if ($succ["child"] > 0)
00276                 {
00277                         $target_lm_page =& new ilLMPageObject($cont_obj, $succ["child"]);
00278                         $target_page =& $target_lm_page->getPageObject();
00279                         $target_page->buildDom();
00280                         $target_page->addHierIds();
00281                         
00282                         // move nodes to target page
00283                         $source_page->buildDom();
00284                         $source_page->addHierIds();
00285                         ilPageObject::_moveContentAfterHierId($source_page, $target_page, $a_hier_id);
00286                         //$source_page->deleteContentFromHierId($a_hier_id);
00287                         
00288                         return $succ["child"];
00289                 }
00290                                 
00291         }
00292 
00293         
00299         function assignPageObject(&$a_page_obj)
00300         {
00301                 $this->page_object =& $a_page_obj;
00302         }
00303 
00304         
00310         function &getPageObject()
00311         {
00312                 return $this->page_object;
00313         }
00314 
00315         
00319         function setId($a_id)
00320         {
00321                 $this->id = $a_id;
00322         }
00323 
00324         function getId()
00325         {
00326                 return $this->id;
00327         }
00328 
00332         function setAlias($a_is_alias)
00333         {
00334                 $this->is_alias = $a_is_alias;
00335         }
00336 
00337         function isAlias()
00338         {
00339                 return $this->is_alias;
00340         }
00341 
00342         // only for page aliases
00343         function setOriginID($a_id)
00344         {
00345                 return $this->origin_id = $a_id;
00346         }
00347 
00348         // only for page aliases
00349         function getOriginID()
00350         {
00351                 return $this->origin_id;
00352         }
00353 
00357         function getPageList($lm_id)
00358         {
00359                 return ilLMObject::getObjectList($lm_id, "pg");
00360         }
00361 
00362 
00369         function _getPresentationTitle($a_pg_id, $a_mode = IL_CHAPTER_TITLE,
00370                 $a_include_numbers = false)
00371         {
00372                 global $ilDB;
00373 
00374                 // select
00375                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_pg_id."'";
00376                 $pg_set = $ilDB->query($query);
00377                 $pg_rec = $pg_set->fetchRow(DB_FETCHMODE_ASSOC);
00378 
00379                 if($a_mode == IL_NO_HEADER)
00380                 {
00381                         return "";
00382                 }
00383 
00384                 $tree = new ilTree($pg_rec["lm_id"]);
00385                 $tree->setTableNames('lm_tree','lm_data');
00386                 $tree->setTreeTablePK("lm_id");
00387 
00388                 if($a_mode == IL_PAGE_TITLE)
00389                 {
00390                         $nr = "";
00391 
00392                         /*
00393                         if ($a_include_numbers)
00394                         {
00395                                 if ($tree->isInTree($pg_rec["obj_id"]))
00396                                 {
00397                                         // get page tree node
00398                                         $query = "SELECT * FROM lm_tree WHERE child = ".
00399                                                 $ilDB->quote($a_pg_id)." AND lm_id = ".
00400                                                 $ilDB->quote($pg_rec["lm_id"]);
00401                                         $tree_set = $ilDB->query($query);
00402                                         $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
00403                                         $depth = $tree_node["depth"];
00404 
00405                                         //$nr = $tree->getChildSequenceNumber($tree_node)." ";
00406                                         $nr = " ";
00407                                         $dot = "";
00408                                         for ($i = $depth - 1; $i > 1; $i --)
00409                                         {
00410                                                 // get next parent tree node
00411                                                 $query = "SELECT * FROM lm_tree WHERE child = ".
00412                                                 $ilDB->quote($tree_node["parent"])." AND lm_id = ".
00413                                                 $ilDB->quote($pg_rec["lm_id"]);
00414                                                 $tree_set = $ilDB->query($query);
00415                                                 $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
00416                                                 $seq = $tree->getChildSequenceNumber($tree_node);
00417 
00418                                                 $nr = $seq.$dot.$nr;
00419                                                 $dot = ".";
00420                                         }
00421                                 }
00422                         }*/
00423                         
00424                         return $nr.$pg_rec["title"];
00425                 }
00426 
00427                 if ($tree->isInTree($pg_rec["obj_id"]))
00428                 {
00429                         $pred_node = $tree->fetchPredecessorNode($pg_rec["obj_id"], "st");
00430                         $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
00431                         $cnt_str = "";
00432                         if(count($childs) > 1)
00433                         {
00434                                 $cur_cnt = 0;
00435                                 foreach($childs as $child)
00436                                 {
00437                                         $cur_cnt++;
00438                                         if($child["obj_id"] == $pg_rec["obj_id"])
00439                                         {
00440                                                 break;
00441                                         }
00442                                 }
00443                                 $cnt_str = " (".$cur_cnt."/".count($childs).")";
00444                         }
00445                         /*
00446                         require_once("content/classes/class.ilStructureObject.php");
00447                         $struct_obj =& new ilStructureObject($pred_node["obj_id"]);
00448                         return $struct_obj->getTitle();*/
00449                         return $pred_node["title"].$cnt_str;
00450                 }
00451                 else
00452                 {
00453                         return $pg_rec["title"];
00454                 }
00455         }
00456 
00463         function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
00464         {
00465                 global $ilBench;
00466 
00467                 $attrs = array();
00468                 $a_xml_writer->xmlStartTag("PageObject", $attrs);
00469 
00470                 switch ($a_mode)
00471                 {
00472                         case "normal":
00473                                 // MetaData
00474                                 $ilBench->start("ContentObjectExport", "exportPageObject_XML_Meta");
00475                                 $this->exportXMLMetaData($a_xml_writer);
00476                                 $ilBench->stop("ContentObjectExport", "exportPageObject_XML_Meta");
00477 
00478                                 // PageContent
00479                                 $ilBench->start("ContentObjectExport", "exportPageObject_XML_PageContent");
00480                                 $this->exportXMLPageContent($a_xml_writer, $a_inst);
00481                                 $ilBench->stop("ContentObjectExport", "exportPageObject_XML_PageContent");
00482                                 break;
00483 
00484                         case "alias":
00485                                 $attrs = array();
00486                                 $attrs["OriginId"] = "il_".$a_inst.
00487                                         "_pg_".$this->getId();
00488                                 $a_xml_writer->xmlElement("PageAlias", $attrs);
00489                                 break;
00490                 }
00491 
00492                 // Layout
00493                 // not implemented
00494 
00495                 $a_xml_writer->xmlEndTag("PageObject");
00496         }
00497 
00501         function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
00502         {
00503                 $attrs = array();
00504                 $a_xml_writer->xmlStartTag("PageObject", $attrs);
00505 
00506                 $attrs = array();
00507                 $attrs["OriginId"] = "il_".$a_inst.
00508                         "_pg_".$a_id;
00509                 $a_xml_writer->xmlElement("PageAlias", $attrs);
00510 
00511                 $a_xml_writer->xmlEndTag("PageObject");
00512         }
00513 
00514 
00521         function exportXMLMetaData(&$a_xml_writer)
00522         {
00523                 $nested = new ilNestedSetXML();
00524                 $nested->setParameterModifier($this, "modifyExportIdentifier");
00525                 $a_xml_writer->appendXML($nested->export($this->getId(),
00526                         $this->getType()));
00527         }
00528 
00529         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00530         {
00531                 if ($a_tag == "Identifier" && $a_param == "Entry")
00532                 {
00533                         $a_value = "il_".IL_INST_ID."_pg_".$this->getId();
00534                         //$a_value = ilUtil::insertInstIntoID($a_value);
00535                 }
00536 
00537                 return $a_value;
00538         }
00539 
00540 
00547         function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
00548         {
00549 //echo "exportxmlpagecontent:$a_inst:<br>";
00550                 $cont_obj =& $this->getContentObject();
00551                 //$page_obj = new ilPageObject($cont_obj->getType(), $this->getId());
00552 
00553                 $this->page_object->buildDom();
00554                 $this->page_object->insertInstIntoIDs($a_inst);
00555                 $this->mobs_contained = $this->page_object->collectMediaObjects(false);
00556                 $this->files_contained = $this->page_object->collectFileItems();
00557                 $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
00558                 $xml = str_replace("&","&amp;", $xml);
00559                 $a_xml_writer->appendXML($xml);
00560 
00561                 $this->page_object->freeDom();
00562         }
00563 
00569         function getMediaObjectIds()
00570         {
00571                 return $this->mobs_contained;
00572         }
00573 
00579         function getFileItemIds()
00580         {
00581                 return $this->files_contained;
00582         }
00583 
00590         function exportFO(&$a_xml_writer)
00591         {
00592                 global $ilBench;
00593 
00594                 //$attrs = array();
00595                 //$a_xml_writer->xmlStartTag("PageObject", $attrs);
00596                 $title = ilLMPageObject::_getPresentationTitle($this->getId());
00597                 if ($title != "")
00598                 {
00599                         $attrs = array();
00600                         $attrs["font-family"] = "Times";
00601                         $attrs["font-size"] = "14pt";
00602                         $a_xml_writer->xmlElement("fo:block", $attrs, $title);
00603                 }
00604 
00605                 // PageContent
00606                 $this->page_object->buildDom();
00607                 $fo = $this->page_object->getFO();
00608                 $a_xml_writer->appendXML($fo);
00609 
00610                 //$a_xml_writer->xmlEndTag("PageObject");
00611         }
00612 
00613 
00619         function _goto($a_target)
00620         {
00621                 global $rbacsystem, $ilErr, $lng;
00622 
00623                 // determine learning object
00624                 $lm_id = ilLMObject::_lookupContObjID($a_target);
00625 
00626                 // get all references
00627                 $ref_ids = ilObject::_getAllReferences($lm_id);
00628 
00629                 // check read permissions
00630                 foreach ($ref_ids as $ref_id)
00631                 {
00632                         include_once 'classes/class.ilSearch.php';
00633                 
00634                         // Added this additional check (ParentConditions) to avoid calls of objects inside e.g courses.
00635                         // Will be replaced in future releases by ilAccess::checkAccess()
00636                         if ($rbacsystem->checkAccess("read", $ref_id) and ilSearch::_checkParentConditions($ref_id))
00637                         {
00638                                 ilUtil::redirect("content/lm_presentation.php?ref_id=$ref_id".
00639                                         "&obj_id=$a_target");
00640                         }
00641                 }
00642 
00643                 $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
00644         }
00645 
00646 }
00647 ?>

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