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

content/classes/class.ilStructureObject.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 
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)
00099         {
00100                 $lm =& $this->getContentObject();
00101                 $source_tree = new ilTree($lm->getId());
00102                 $source_tree->setTableNames('lm_tree','lm_data');
00103                 $source_tree->setTreeTablePK("lm_id");
00104 
00105                 // copy chapter
00106                 $target_lm_id = $a_target_tree->getTreeId();
00107                 $target_lm = ilObjectFactory::getInstanceByObjId($target_lm_id);
00108                 $chap =& new ilStructureObject($target_lm);
00109                 $chap->setTitle($this->getTitle());
00110                 $chap->setLMId($target_lm_id);
00111                 $chap->setType($this->getType());
00112                 $chap->setDescription($this->getDescription());
00113                 $chap->create(true);
00114                 
00115                 // copy meta data
00116                 include_once("Services/MetaData/classes/class.ilMD.php");
00117                 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
00118                 $new_md =& $md->cloneMD($target_lm_id, $chap->getId(), $this->getType());
00119                 
00120                 // insert chapter in tree
00121                 $a_target_tree->insertNode($chap->getId(), $a_parent, $a_pos);
00122 
00123                 $childs =& $source_tree->getChilds($this->getId());
00124                 foreach($childs as $child)
00125                 {
00126                         $lmobj = ilLMObjectFactory::getInstance($this->getContentObject(), $child["obj_id"], true);
00127                         if ($child["type"] == "st")
00128                         {
00129                                 $newobj =& $lmobj->copy($a_target_tree, $chap->getId());
00130                         }
00131                         else
00132                         {
00133                                 $newobj =& $lmobj->copyToOtherContObject($target_lm);
00134                                 $a_target_tree->insertNode($newobj->getId(), $chap->getId());
00135                         }
00136                 }
00137 
00138                 return $chap;
00139         }
00140 
00141 
00147         function _goto($a_target)
00148         {
00149                 global $rbacsystem, $ilErr, $lng;
00150 
00151                 // determine learning object
00152                 $lm_id = ilLMObject::_lookupContObjID($a_target);
00153 
00154                 // get all references
00155                 $ref_ids = ilObject::_getAllReferences($lm_id);
00156 
00157                 // check read permissions
00158                 foreach ($ref_ids as $ref_id)
00159                 {
00160                         include_once 'classes/class.ilSearch.php';
00161                         
00162                         // Added this additional check (ParentConditions) to avoid calls of objects inside e.g courses.
00163                         // Will be replaced in future releases by ilAccess::checkAccess()
00164                         if ($rbacsystem->checkAccess("read", $ref_id) and ilSearch::_checkParentConditions($ref_id))
00165                         {
00166                                 ilUtil::redirect("content/lm_presentation.php?ref_id=$ref_id".
00167                                         "&obj_id=$a_target");
00168                         }
00169                 }
00170 
00171                 $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
00172         }
00173 
00174 
00181         function exportXML(&$a_xml_writer, $a_inst, &$expLog)
00182         {
00183                 global $ilBench;
00184 
00185                 $expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
00186                 $attrs = array();
00187                 $a_xml_writer->xmlStartTag("StructureObject", $attrs);
00188 
00189                 // MetaData
00190                 $ilBench->start("ContentObjectExport", "exportStructureObject_exportMeta");
00191                 $this->exportXMLMetaData($a_xml_writer);
00192                 $ilBench->stop("ContentObjectExport", "exportStructureObject_exportMeta");
00193 
00194                 // StructureObjects
00195                 $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
00196                 $this->exportXMLPageObjects($a_xml_writer, $a_inst);
00197                 $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
00198 
00199                 // PageObjects
00200                 $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
00201 
00202                 // Layout
00203                 // not implemented
00204 
00205                 $a_xml_writer->xmlEndTag("StructureObject");
00206         }
00207 
00208 
00215         function exportXMLMetaData(&$a_xml_writer)
00216         {
00217                 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00218                 $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
00219                 $md2xml->setExportMode(true);
00220                 $md2xml->startExport();
00221                 $a_xml_writer->appendXML($md2xml->getXML());
00222         }
00223 
00224         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00225         {
00226                 if ($a_tag == "Identifier" && $a_param == "Entry")
00227                 {
00228                         $a_value = "il_".IL_INST_ID."_st_".$this->getId();
00229                         //$a_value = ilUtil::insertInstIntoID($a_value);
00230                 }
00231 
00232                 return $a_value;
00233         }
00234 
00239         function _getPresentationTitle($a_st_id, $a_include_numbers = false)
00240         {
00241                 global $ilDB;
00242 
00243                 // get chapter data
00244                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_st_id."'";
00245                 $st_set = $ilDB->query($query);
00246                 $st_rec = $st_set->fetchRow(DB_FETCHMODE_ASSOC);
00247 
00248                 $tree = new ilTree($st_rec["lm_id"]);
00249                 $tree->setTableNames('lm_tree','lm_data');
00250                 $tree->setTreeTablePK("lm_id");
00251 
00252                 if ($a_include_numbers)
00253                 {
00254                         if ($tree->isInTree($st_rec["obj_id"]))
00255                         {
00256                                 // get chapter tree node
00257                                 $query = "SELECT * FROM lm_tree WHERE child = ".
00258                                         $ilDB->quote($a_st_id)." AND lm_id = ".
00259                                         $ilDB->quote($st_rec["lm_id"]);
00260                                 $tree_set = $ilDB->query($query);
00261                                 $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
00262                                 $depth = $tree_node["depth"];
00263 
00264                                 $nr = $tree->getChildSequenceNumber($tree_node, "st")." ";
00265                                 for ($i = $depth - 1; $i > 1; $i --)
00266                                 {
00267                                         // get next parent tree node
00268                                         $query = "SELECT * FROM lm_tree WHERE child = ".
00269                                         $ilDB->quote($tree_node["parent"])." AND lm_id = ".
00270                                         $ilDB->quote($st_rec["lm_id"]);
00271                                         $tree_set = $ilDB->query($query);
00272                                         $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
00273                                         $seq = $tree->getChildSequenceNumber($tree_node, "st");
00274 
00275                                         $nr = $seq.".".$nr;
00276                                 }
00277                         }
00278                 }
00279 
00280                 return $nr.$st_rec["title"];
00281         }
00282 
00283 
00284 
00291         function exportXMLPageObjects(&$a_xml_writer, $a_inst = 0)
00292         {
00293                 include_once './content/classes/class.ilLMPageObject.php';
00294 
00295                 global $ilBench;
00296 
00297                 $this->tree = new ilTree($this->getLmId());
00298                 $this->tree->setTableNames('lm_tree', 'lm_data');
00299                 $this->tree->setTreeTablePK("lm_id");
00300 
00301                 $childs = $this->tree->getChilds($this->getId());
00302                 foreach ($childs as $child)
00303                 {
00304                         if($child["type"] != "pg")
00305                         {
00306                                 continue;
00307                         }
00308 
00309                         // export xml to writer object
00310                         $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00311                         //$ilBench->start("ContentObjectExport", "exportStructureObject_getLMPageObject");
00312                         //$page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
00313                         //$ilBench->stop("ContentObjectExport", "exportStructureObject_getLMPageObject");
00314                         ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
00315                         //$page_obj->exportXML($a_xml_writer, "alias", $a_inst);
00316                         //unset($page_obj);
00317                         $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00318                 }
00319         }
00320 
00321 
00328         function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
00329         {
00330                 $this->tree = new ilTree($this->getLmId());
00331                 $this->tree->setTableNames('lm_tree', 'lm_data');
00332                 $this->tree->setTreeTablePK("lm_id");
00333 
00334                 $childs = $this->tree->getChilds($this->getId());
00335                 foreach ($childs as $child)
00336                 {
00337                         if($child["type"] != "st")
00338                         {
00339                                 continue;
00340                         }
00341 
00342                         // export xml to writer object
00343                         $structure_obj = new ilStructureObject($this->getContentObject(),
00344                                 $child["obj_id"]);
00345                         $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
00346                         unset($structure_obj);
00347                 }
00348         }
00349 
00356         function exportFO(&$a_xml_writer)
00357         {
00358                 global $ilBench;
00359 
00360                 //$expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
00361 
00362                 // fo:block (complete)
00363                 $attrs = array();
00364                 $attrs["font-family"] = "Times";
00365                 $attrs["font-size"] = "14pt";
00366                 $a_xml_writer->xmlElement("fo:block", $attrs, $this->getTitle());
00367 
00368                 // page objects
00369                 //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
00370                 $this->exportFOPageObjects($a_xml_writer);
00371                 //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
00372 
00373                 // structure objects
00374                 //$this->exportFOStructureObjects($a_xml_writer);
00375 
00376         }
00377 
00384         function exportFOPageObjects(&$a_xml_writer)
00385         {
00386                 global $ilBench;
00387 
00388                 $this->tree = new ilTree($this->getLmId());
00389                 $this->tree->setTableNames('lm_tree', 'lm_data');
00390                 $this->tree->setTreeTablePK("lm_id");
00391 
00392                 $childs = $this->tree->getChilds($this->getId());
00393                 foreach ($childs as $child)
00394                 {
00395                         if($child["type"] != "pg")
00396                         {
00397                                 continue;
00398                         }
00399 
00400                         // export xml to writer object
00401                         //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00402 
00403                         $page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
00404                         $page_obj->exportFO($a_xml_writer);
00405 
00406                         //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00407                 }
00408         }
00409 
00410 }
00411 ?>

Generated on Fri Dec 13 2013 10:18:29 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1