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

Modules/LearningModule/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("./Modules/LearningModule/classes/class.ilLMObject.php");
00025 require_once("./Services/COPage/classes/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                 // copy page 
00136                 $lm_page =& new ilLMPageObject($this->getContentObject());
00137                 $lm_page->setTitle($this->getTitle());
00138                 $lm_page->setLMId($this->getLMId());
00139                 $lm_page->setType($this->getType());
00140                 $lm_page->setDescription($this->getDescription());
00141                 $lm_page->create(true);         // setting "upload" flag to true prevents creating of meta data
00142 
00143                 // copy meta data
00144                 include_once("Services/MetaData/classes/class.ilMD.php");
00145                 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
00146                 $new_md =& $md->cloneMD($this->getLMId(), $lm_page->getId(), $this->getType());
00147 
00148                 // copy page content
00149                 $page =& $lm_page->getPageObject();
00150                 $page->setXMLContent($this->page_object->getXMLContent());
00151                 $page->buildDom();
00152                 $page->update();
00153 
00154                 return $lm_page;
00155         }
00156 
00160         function &copyToOtherContObject(&$a_cont_obj, &$a_copied_nodes)
00161         {
00162                 // copy page
00163                 $lm_page =& new ilLMPageObject($a_cont_obj);
00164                 $lm_page->setTitle($this->getTitle());
00165                 $lm_page->setLMId($a_cont_obj->getId());
00166                 $lm_page->setImportId("il__pg_".$this->getId());
00167                 $lm_page->setType($this->getType());
00168                 $lm_page->setDescription($this->getDescription());
00169                 $lm_page->create(true);         // setting "upload" flag to true prevents creating of meta data
00170                 $a_copied_nodes[$this->getId()] = $lm_page->getId();
00171 
00172                 // copy meta data
00173                 include_once("Services/MetaData/classes/class.ilMD.php");
00174                 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
00175                 $new_md =& $md->cloneMD($a_cont_obj->getId(), $lm_page->getId(), $this->getType());
00176 
00177                 // copy page content
00178                 $page =& $lm_page->getPageObject();
00179                 $page->setXMLContent($this->page_object->getXMLContent());
00180                 $page->buildDom();
00181                 $page->update();
00182 
00183                 return $lm_page;
00184         }
00185         
00193         function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
00194         {
00195                 // get content object (learning module / digilib book)
00196                 $lm_id = ilLMObject::_lookupContObjID($a_page_id);
00197                 $type = ilObject::_lookupType($lm_id, false);
00198                 switch ($type)
00199                 {
00200                         case "lm":
00201                                 include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
00202                                 $cont_obj = new ilObjLearningModule($lm_id, false);
00203                                 break;
00204 
00205                         case "dbk":
00206                                 include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
00207                                 $cont_obj = new ilObjDlBook($lm_id, false);
00208                                 break;
00209                 }
00210 
00211                 $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
00212 
00213                 // create new page
00214                 $lm_page =& new ilLMPageObject($cont_obj);
00215                 $lm_page->setTitle($source_lm_page->getTitle());
00216                 $lm_page->setLMId($source_lm_page->getLMId());
00217                 $lm_page->setType($source_lm_page->getType());
00218                 $lm_page->setDescription($source_lm_page->getDescription());
00219                 $lm_page->create(true);
00220                 
00221                 // copy meta data
00222                 include_once("Services/MetaData/classes/class.ilMD.php");
00223                 $md = new ilMD($source_lm_page->getLMId(), $a_page_id, $source_lm_page->getType());
00224                 $new_md =& $md->cloneMD($source_lm_page->getLMId(), $lm_page->getId(), $source_lm_page->getType());
00225 
00226                 // copy complete content of source page to new page
00227                 $source_page =& $source_lm_page->getPageObject();
00228                 $page =& $lm_page->getPageObject();
00229                 $page->setXMLContent($source_page->getXMLContent());
00230                 $page->buildDom();
00231 
00232                 // insert new page in tree (after original page)
00233                 $tree = new ilTree($cont_obj->getId());
00234                 $tree->setTableNames('lm_tree','lm_data');
00235                 $tree->setTreeTablePK("lm_id");
00236                 if ($tree->isInTree($source_lm_page->getId()))
00237                 {
00238                         $parent_node = $tree->getParentNodeData($source_lm_page->getId());
00239                         $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId());
00240                 }
00241                 
00242                 // remove all nodes < hierarchical id from new page (incl. update)
00243                 $page->addHierIds();
00244                 $page->deleteContentBeforeHierId($a_hier_id);
00245 
00246                 // remove all nodes >= hierarchical id from source page
00247                 $source_page->buildDom();
00248                 $source_page->addHierIds();
00249                 $source_page->deleteContentFromHierId($a_hier_id);
00250                                 
00251                 return $lm_page;
00252                 
00253         }
00254 
00262         function _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
00263         {
00264                 // get content object (learning module / digilib book)
00265                 $lm_id = ilLMObject::_lookupContObjID($a_page_id);
00266                 $type = ilObject::_lookupType($lm_id, false);
00267                 switch ($type)
00268                 {
00269                         case "lm":
00270                                 include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
00271                                 $cont_obj = new ilObjLearningModule($lm_id, false);
00272                                 break;
00273 
00274                         case "dbk":
00275                                 include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
00276                                 $cont_obj = new ilObjDlBook($lm_id, false);
00277                                 break;
00278                 }
00279                 $tree = new ilTree($cont_obj->getId());
00280                 $tree->setTableNames('lm_tree','lm_data');
00281                 $tree->setTreeTablePK("lm_id");
00282 
00283                 $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
00284                 $source_page =& $source_lm_page->getPageObject();
00285                 
00286                 // get next page
00287                 $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
00288                 if ($succ["child"] > 0)
00289                 {
00290                         $target_lm_page =& new ilLMPageObject($cont_obj, $succ["child"]);
00291                         $target_page =& $target_lm_page->getPageObject();
00292                         $target_page->buildDom();
00293                         $target_page->addHierIds();
00294                         
00295                         // move nodes to target page
00296                         $source_page->buildDom();
00297                         $source_page->addHierIds();
00298                         ilPageObject::_moveContentAfterHierId($source_page, $target_page, $a_hier_id);
00299                         //$source_page->deleteContentFromHierId($a_hier_id);
00300                         
00301                         return $succ["child"];
00302                 }
00303                                 
00304         }
00305 
00306         
00312         function assignPageObject(&$a_page_obj)
00313         {
00314                 $this->page_object =& $a_page_obj;
00315         }
00316 
00317         
00323         function &getPageObject()
00324         {
00325                 return $this->page_object;
00326         }
00327 
00328         
00332         function setId($a_id)
00333         {
00334                 $this->id = $a_id;
00335         }
00336 
00337         function getId()
00338         {
00339                 return $this->id;
00340         }
00341 
00345         function setAlias($a_is_alias)
00346         {
00347                 $this->is_alias = $a_is_alias;
00348         }
00349 
00350         function isAlias()
00351         {
00352                 return $this->is_alias;
00353         }
00354 
00355         // only for page aliases
00356         function setOriginID($a_id)
00357         {
00358                 return $this->origin_id = $a_id;
00359         }
00360 
00361         // only for page aliases
00362         function getOriginID()
00363         {
00364                 return $this->origin_id;
00365         }
00366 
00370         function getPageList($lm_id)
00371         {
00372                 return ilLMObject::getObjectList($lm_id, "pg");
00373         }
00374 
00375 
00382         function _getPresentationTitle($a_pg_id, $a_mode = IL_CHAPTER_TITLE,
00383                 $a_include_numbers = false)
00384         {
00385                 global $ilDB;
00386 
00387                 // select
00388                 $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_pg_id);
00389                 $pg_set = $ilDB->query($query);
00390                 $pg_rec = $pg_set->fetchRow(DB_FETCHMODE_ASSOC);
00391 
00392                 if($a_mode == IL_NO_HEADER)
00393                 {
00394                         return "";
00395                 }
00396 
00397                 $tree = new ilTree($pg_rec["lm_id"]);
00398                 $tree->setTableNames('lm_tree','lm_data');
00399                 $tree->setTreeTablePK("lm_id");
00400 
00401                 if($a_mode == IL_PAGE_TITLE)
00402                 {
00403                         $nr = "";
00404                         return $nr.$pg_rec["title"];
00405                 }
00406 
00407                 if ($tree->isInTree($pg_rec["obj_id"]))
00408                 {
00409                         $pred_node = $tree->fetchPredecessorNode($pg_rec["obj_id"], "st");
00410                         $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
00411                         $cnt_str = "";
00412                         if(count($childs) > 1)
00413                         {
00414                                 $cnt = 0;
00415                                 foreach($childs as $child)
00416                                 {
00417                                         if ($child["type"] != "pg" || ilLMPageObject::_lookupActive($child["obj_id"]))
00418                                         {
00419                                                 $cnt++;
00420                                         }
00421                                         if($child["obj_id"] == $pg_rec["obj_id"])
00422                                         {
00423                                                 $cur_cnt = $cnt;
00424                                         }
00425                                 }
00426                                 if ($cnt > 1)
00427                                 {
00428                                         $cnt_str = " (".$cur_cnt."/".$cnt.")";
00429                                 }
00430                         }
00431                         require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
00432                         //$struct_obj =& new ilStructureObject($pred_node["obj_id"]);
00433                         //return $struct_obj->getTitle();
00434                         return ilStructureObject::_getPresentationTitle($pred_node["obj_id"],
00435                                 $a_include_numbers).$cnt_str;
00436                         //return $pred_node["title"].$cnt_str;
00437                 }
00438                 else
00439                 {
00440                         return $pg_rec["title"];
00441                 }
00442         }
00443 
00450         function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
00451         {
00452                 global $ilBench;
00453 
00454                 $attrs = array();
00455                 $a_xml_writer->xmlStartTag("PageObject", $attrs);
00456 
00457                 switch ($a_mode)
00458                 {
00459                         case "normal":
00460                                 // MetaData
00461                                 $ilBench->start("ContentObjectExport", "exportPageObject_XML_Meta");
00462                                 $this->exportXMLMetaData($a_xml_writer);
00463                                 $ilBench->stop("ContentObjectExport", "exportPageObject_XML_Meta");
00464 
00465                                 // PageContent
00466                                 $ilBench->start("ContentObjectExport", "exportPageObject_XML_PageContent");
00467                                 $this->exportXMLPageContent($a_xml_writer, $a_inst);
00468                                 $ilBench->stop("ContentObjectExport", "exportPageObject_XML_PageContent");
00469                                 break;
00470 
00471                         case "alias":
00472                                 $attrs = array();
00473                                 $attrs["OriginId"] = "il_".$a_inst.
00474                                         "_pg_".$this->getId();
00475                                 $a_xml_writer->xmlElement("PageAlias", $attrs);
00476                                 break;
00477                 }
00478 
00479                 // Layout
00480                 // not implemented
00481 
00482                 $a_xml_writer->xmlEndTag("PageObject");
00483         }
00484 
00488         function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
00489         {
00490                 $attrs = array();
00491                 $a_xml_writer->xmlStartTag("PageObject", $attrs);
00492 
00493                 $attrs = array();
00494                 $attrs["OriginId"] = "il_".$a_inst.
00495                         "_pg_".$a_id;
00496                 $a_xml_writer->xmlElement("PageAlias", $attrs);
00497 
00498                 $a_xml_writer->xmlEndTag("PageObject");
00499         }
00500 
00501 
00508         function exportXMLMetaData(&$a_xml_writer)
00509         {
00510                 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00511                 $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
00512                 $md2xml->setExportMode(true);
00513                 $md2xml->startExport();
00514                 $a_xml_writer->appendXML($md2xml->getXML());
00515         }
00516 
00517         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00518         {
00519                 if ($a_tag == "Identifier" && $a_param == "Entry")
00520                 {
00521                         $a_value = "il_".IL_INST_ID."_pg_".$this->getId();
00522                         //$a_value = ilUtil::insertInstIntoID($a_value);
00523                 }
00524 
00525                 return $a_value;
00526         }
00527 
00528 
00535         function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
00536         {
00537 //echo "exportxmlpagecontent:$a_inst:<br>";
00538                 $cont_obj =& $this->getContentObject();
00539                 //$page_obj = new ilPageObject($cont_obj->getType(), $this->getId());
00540 
00541                 $this->page_object->buildDom();
00542                 $this->page_object->insertInstIntoIDs($a_inst);
00543                 $this->mobs_contained = $this->page_object->collectMediaObjects(false);
00544                 $this->files_contained = $this->page_object->collectFileItems();
00545                 $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
00546                 $xml = str_replace("&","&amp;", $xml);
00547                 $a_xml_writer->appendXML($xml);
00548 
00549                 $this->page_object->freeDom();
00550         }
00551 
00557         function getMediaObjectIds()
00558         {
00559                 return $this->mobs_contained;
00560         }
00561 
00567         function getFileItemIds()
00568         {
00569                 return $this->files_contained;
00570         }
00571 
00578         function exportFO(&$a_xml_writer)
00579         {
00580                 global $ilBench;
00581 
00582                 //$attrs = array();
00583                 //$a_xml_writer->xmlStartTag("PageObject", $attrs);
00584                 $title = ilLMPageObject::_getPresentationTitle($this->getId());
00585                 if ($title != "")
00586                 {
00587                         $attrs = array();
00588                         $attrs["font-family"] = "Times";
00589                         $attrs["font-size"] = "14pt";
00590                         $a_xml_writer->xmlElement("fo:block", $attrs, $title);
00591                 }
00592 
00593                 // PageContent
00594                 $this->page_object->buildDom();
00595                 $fo = $this->page_object->getFO();
00596                 $a_xml_writer->appendXML($fo);
00597 
00598                 //$a_xml_writer->xmlEndTag("PageObject");
00599         }
00600 
00601 }
00602 ?>

Generated on Fri Dec 13 2013 17:56:51 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1