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

Modules/LearningModule/classes/class.ilStructureObject.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 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 
00036 class ilStructureObject extends ilLMObject
00037 {
00038         var $is_alias;
00039         var $origin_id;
00040         var $tree;
00041 
00046         function ilStructureObject(&$a_content_obj, $a_id = 0)
00047         {
00048                 $this->setType("st");
00049                 parent::ilLMObject($a_content_obj, $a_id);
00050         }
00051 
00052         function create($a_upload = false)
00053         {
00054                 parent::create($a_upload);
00055         }
00056 
00060         function delete($a_delete_meta_data = true)
00061         {
00062                 $this->tree = new ilTree($this->getLmId());
00063                 $this->tree->setTableNames('lm_tree', 'lm_data');
00064                 $this->tree->setTreeTablePK("lm_id");
00065                 $node_data = $this->tree->getNodeData($this->getId());
00066                 $this->delete_rec($this->tree, $a_delete_meta_data);
00067                 $this->tree->deleteTree($node_data);
00068         }
00069 
00073         function delete_rec(&$a_tree, $a_delete_meta_data = true)
00074         {
00075                 $childs = $a_tree->getChilds($this->getId());
00076                 foreach ($childs as $child)
00077                 {
00078                         $obj =& ilLMObjectFactory::getInstance($this->content_object, $child["obj_id"], false);
00079                         if (is_object($obj))
00080                         {
00081                                 if($obj->getType() == "st")
00082                                 {
00083                                         $obj->delete_rec($a_tree, $a_delete_meta_data);
00084                                 }
00085                                 if($obj->getType() == "pg")
00086                                 {
00087                                         $obj->delete($a_delete_meta_data);
00088                                 }
00089                         }
00090                         unset($obj);
00091                 }
00092                 parent::delete($a_delete_meta_data);
00093         }
00094 
00098         //function &copy(&$a_target_tree, $a_parent, $a_pos = IL_LAST_NODE, $a_copied_nodes = "")
00099         function &copy(&$a_target_tree, $a_parent, $a_pos, &$a_copied_nodes)
00100         {
00101                 $lm =& $this->getContentObject();
00102                 $source_tree = new ilTree($lm->getId());
00103                 $source_tree->setTableNames('lm_tree','lm_data');
00104                 $source_tree->setTreeTablePK("lm_id");
00105 
00106                 // copy chapter
00107                 $target_lm_id = $a_target_tree->getTreeId();
00108                 $target_lm = ilObjectFactory::getInstanceByObjId($target_lm_id);
00109                 $chap =& new ilStructureObject($target_lm);
00110                 $chap->setTitle($this->getTitle());
00111                 $chap->setLMId($target_lm_id);
00112                 $chap->setType($this->getType());
00113                 $chap->setDescription($this->getDescription());
00114                 $chap->create(true);
00115                 $a_copied_nodes[$this->getId()] = $chap->getId();
00116                 
00117                 // copy meta data
00118                 include_once("Services/MetaData/classes/class.ilMD.php");
00119                 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
00120                 $new_md =& $md->cloneMD($target_lm_id, $chap->getId(), $this->getType());
00121                 
00122                 // insert chapter in tree
00123                 $a_target_tree->insertNode($chap->getId(), $a_parent, $a_pos);
00124 
00125                 $childs =& $source_tree->getChilds($this->getId());
00126                 foreach($childs as $child)
00127                 {
00128                         $lmobj = ilLMObjectFactory::getInstance($this->getContentObject(), $child["obj_id"], true);
00129                         if ($child["type"] == "st")
00130                         {
00131                                 $newobj =& $lmobj->copy($a_target_tree, $chap->getId(), IL_LAST_NODE,
00132                                         $a_copied_nodes);
00133                         }
00134                         else
00135                         {
00136                                 $newobj =& $lmobj->copyToOtherContObject($target_lm, $a_copied_nodes);
00137                                 $a_target_tree->insertNode($newobj->getId(), $chap->getId());
00138                         }
00139                 }
00140 
00141                 return $chap;
00142         }
00143 
00150         function exportXML(&$a_xml_writer, $a_inst, &$expLog)
00151         {
00152                 global $ilBench;
00153 
00154                 $expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
00155                 $attrs = array();
00156                 $a_xml_writer->xmlStartTag("StructureObject", $attrs);
00157 
00158                 // MetaData
00159                 $ilBench->start("ContentObjectExport", "exportStructureObject_exportMeta");
00160                 $this->exportXMLMetaData($a_xml_writer);
00161                 $ilBench->stop("ContentObjectExport", "exportStructureObject_exportMeta");
00162 
00163                 // StructureObjects
00164                 $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
00165                 $this->exportXMLPageObjects($a_xml_writer, $a_inst);
00166                 $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
00167 
00168                 // PageObjects
00169                 $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
00170 
00171                 // Layout
00172                 // not implemented
00173 
00174                 $a_xml_writer->xmlEndTag("StructureObject");
00175         }
00176 
00177 
00184         function exportXMLMetaData(&$a_xml_writer)
00185         {
00186                 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00187                 $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
00188                 $md2xml->setExportMode(true);
00189                 $md2xml->startExport();
00190                 $a_xml_writer->appendXML($md2xml->getXML());
00191         }
00192 
00193         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00194         {
00195                 if ($a_tag == "Identifier" && $a_param == "Entry")
00196                 {
00197                         $a_value = "il_".IL_INST_ID."_st_".$this->getId();
00198                 }
00199 
00200                 return $a_value;
00201         }
00202 
00207         function _getPresentationTitle($a_st_id, $a_include_numbers = false)
00208         {
00209                 global $ilDB;
00210 
00211                 // get chapter data
00212                 $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_st_id);
00213                 $st_set = $ilDB->query($query);
00214                 $st_rec = $st_set->fetchRow(DB_FETCHMODE_ASSOC);
00215 
00216                 $tree = new ilTree($st_rec["lm_id"]);
00217                 $tree->setTableNames('lm_tree','lm_data');
00218                 $tree->setTreeTablePK("lm_id");
00219 
00220                 if ($a_include_numbers)
00221                 {
00222                         if ($tree->isInTree($st_rec["obj_id"]))
00223                         {
00224                                 // get chapter tree node
00225                                 $query = "SELECT * FROM lm_tree WHERE child = ".
00226                                         $ilDB->quote($a_st_id)." AND lm_id = ".
00227                                         $ilDB->quote($st_rec["lm_id"]);
00228                                 $tree_set = $ilDB->query($query);
00229                                 $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
00230                                 $depth = $tree_node["depth"];
00231 
00232                                 $nr = $tree->getChildSequenceNumber($tree_node, "st")." ";
00233                                 for ($i = $depth - 1; $i > 1; $i --)
00234                                 {
00235                                         // get next parent tree node
00236                                         $query = "SELECT * FROM lm_tree WHERE child = ".
00237                                                 $ilDB->quote($tree_node["parent"])." AND lm_id = ".
00238                                                 $ilDB->quote($st_rec["lm_id"]);
00239                                         $tree_set = $ilDB->query($query);
00240                                         $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
00241                                         $seq = $tree->getChildSequenceNumber($tree_node, "st");
00242 
00243                                         $nr = $seq.".".$nr;
00244                                 }
00245                         }
00246                 }
00247 
00248                 return $nr.$st_rec["title"];
00249         }
00250 
00251 
00252 
00259         function exportXMLPageObjects(&$a_xml_writer, $a_inst = 0)
00260         {
00261                 include_once './Modules/LearningModule/classes/class.ilLMPageObject.php';
00262 
00263                 global $ilBench;
00264 
00265                 $this->tree = new ilTree($this->getLmId());
00266                 $this->tree->setTableNames('lm_tree', 'lm_data');
00267                 $this->tree->setTreeTablePK("lm_id");
00268 
00269                 $childs = $this->tree->getChilds($this->getId());
00270                 foreach ($childs as $child)
00271                 {
00272                         if($child["type"] != "pg")
00273                         {
00274                                 continue;
00275                         }
00276 
00277                         // export xml to writer object
00278                         $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00279                         //$ilBench->start("ContentObjectExport", "exportStructureObject_getLMPageObject");
00280                         //$page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
00281                         //$ilBench->stop("ContentObjectExport", "exportStructureObject_getLMPageObject");
00282                         ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
00283                         //$page_obj->exportXML($a_xml_writer, "alias", $a_inst);
00284                         //unset($page_obj);
00285                         $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00286                 }
00287         }
00288 
00289 
00296         function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
00297         {
00298                 $this->tree = new ilTree($this->getLmId());
00299                 $this->tree->setTableNames('lm_tree', 'lm_data');
00300                 $this->tree->setTreeTablePK("lm_id");
00301 
00302                 $childs = $this->tree->getChilds($this->getId());
00303                 foreach ($childs as $child)
00304                 {
00305                         if($child["type"] != "st")
00306                         {
00307                                 continue;
00308                         }
00309 
00310                         // export xml to writer object
00311                         $structure_obj = new ilStructureObject($this->getContentObject(),
00312                                 $child["obj_id"]);
00313                         $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
00314                         unset($structure_obj);
00315                 }
00316         }
00317 
00324         function exportFO(&$a_xml_writer)
00325         {
00326                 global $ilBench;
00327 
00328                 //$expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
00329 
00330                 // fo:block (complete)
00331                 $attrs = array();
00332                 $attrs["font-family"] = "Times";
00333                 $attrs["font-size"] = "14pt";
00334                 $a_xml_writer->xmlElement("fo:block", $attrs, $this->getTitle());
00335 
00336                 // page objects
00337                 //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
00338                 $this->exportFOPageObjects($a_xml_writer);
00339                 //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
00340 
00341                 // structure objects
00342                 //$this->exportFOStructureObjects($a_xml_writer);
00343 
00344         }
00345 
00352         function exportFOPageObjects(&$a_xml_writer)
00353         {
00354                 global $ilBench;
00355 
00356                 $this->tree = new ilTree($this->getLmId());
00357                 $this->tree->setTableNames('lm_tree', 'lm_data');
00358                 $this->tree->setTreeTablePK("lm_id");
00359 
00360                 $childs = $this->tree->getChilds($this->getId());
00361                 foreach ($childs as $child)
00362                 {
00363                         if($child["type"] != "pg")
00364                         {
00365                                 continue;
00366                         }
00367 
00368                         // export xml to writer object
00369                         //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00370 
00371                         $page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
00372                         $page_obj->exportFO($a_xml_writer);
00373 
00374                         //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00375                 }
00376         }
00377 
00378 }
00379 ?>

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