• 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, $ilAccess;
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                         // Permission check
00163                         if ($ilAccess->checkAccess("read", "", $ref_id))
00164                         {
00165                                 // don't redirect anymore, just set parameters
00166                                 // (goto.php includes  "ilias.php")
00167                                 $_GET["baseClass"] = "ilLMPresentationGUI";
00168                                 $_GET["obj_id"] = $a_target;
00169                                 $_GET["ref_id"] = $ref_id;
00170                                 return;
00171                         }
00172                 }
00173                 $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
00174         }
00175 
00176 
00183         function exportXML(&$a_xml_writer, $a_inst, &$expLog)
00184         {
00185                 global $ilBench;
00186 
00187                 $expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
00188                 $attrs = array();
00189                 $a_xml_writer->xmlStartTag("StructureObject", $attrs);
00190 
00191                 // MetaData
00192                 $ilBench->start("ContentObjectExport", "exportStructureObject_exportMeta");
00193                 $this->exportXMLMetaData($a_xml_writer);
00194                 $ilBench->stop("ContentObjectExport", "exportStructureObject_exportMeta");
00195 
00196                 // StructureObjects
00197                 $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
00198                 $this->exportXMLPageObjects($a_xml_writer, $a_inst);
00199                 $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
00200 
00201                 // PageObjects
00202                 $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
00203 
00204                 // Layout
00205                 // not implemented
00206 
00207                 $a_xml_writer->xmlEndTag("StructureObject");
00208         }
00209 
00210 
00217         function exportXMLMetaData(&$a_xml_writer)
00218         {
00219                 include_once("Services/MetaData/classes/class.ilMD2XML.php");
00220                 $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
00221                 $md2xml->setExportMode(true);
00222                 $md2xml->startExport();
00223                 $a_xml_writer->appendXML($md2xml->getXML());
00224         }
00225 
00226         function modifyExportIdentifier($a_tag, $a_param, $a_value)
00227         {
00228                 if ($a_tag == "Identifier" && $a_param == "Entry")
00229                 {
00230                         $a_value = "il_".IL_INST_ID."_st_".$this->getId();
00231                         //$a_value = ilUtil::insertInstIntoID($a_value);
00232                 }
00233 
00234                 return $a_value;
00235         }
00236 
00241         function _getPresentationTitle($a_st_id, $a_include_numbers = false)
00242         {
00243                 global $ilDB;
00244 
00245                 // get chapter data
00246                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_st_id."'";
00247                 $st_set = $ilDB->query($query);
00248                 $st_rec = $st_set->fetchRow(DB_FETCHMODE_ASSOC);
00249 
00250                 $tree = new ilTree($st_rec["lm_id"]);
00251                 $tree->setTableNames('lm_tree','lm_data');
00252                 $tree->setTreeTablePK("lm_id");
00253 
00254                 if ($a_include_numbers)
00255                 {
00256                         if ($tree->isInTree($st_rec["obj_id"]))
00257                         {
00258                                 // get chapter tree node
00259                                 $query = "SELECT * FROM lm_tree WHERE child = ".
00260                                         $ilDB->quote($a_st_id)." AND lm_id = ".
00261                                         $ilDB->quote($st_rec["lm_id"]);
00262                                 $tree_set = $ilDB->query($query);
00263                                 $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
00264                                 $depth = $tree_node["depth"];
00265 
00266                                 $nr = $tree->getChildSequenceNumber($tree_node, "st")." ";
00267                                 for ($i = $depth - 1; $i > 1; $i --)
00268                                 {
00269                                         // get next parent tree node
00270                                         $query = "SELECT * FROM lm_tree WHERE child = ".
00271                                         $ilDB->quote($tree_node["parent"])." AND lm_id = ".
00272                                         $ilDB->quote($st_rec["lm_id"]);
00273                                         $tree_set = $ilDB->query($query);
00274                                         $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
00275                                         $seq = $tree->getChildSequenceNumber($tree_node, "st");
00276 
00277                                         $nr = $seq.".".$nr;
00278                                 }
00279                         }
00280                 }
00281 
00282                 return $nr.$st_rec["title"];
00283         }
00284 
00285 
00286 
00293         function exportXMLPageObjects(&$a_xml_writer, $a_inst = 0)
00294         {
00295                 include_once './content/classes/class.ilLMPageObject.php';
00296 
00297                 global $ilBench;
00298 
00299                 $this->tree = new ilTree($this->getLmId());
00300                 $this->tree->setTableNames('lm_tree', 'lm_data');
00301                 $this->tree->setTreeTablePK("lm_id");
00302 
00303                 $childs = $this->tree->getChilds($this->getId());
00304                 foreach ($childs as $child)
00305                 {
00306                         if($child["type"] != "pg")
00307                         {
00308                                 continue;
00309                         }
00310 
00311                         // export xml to writer object
00312                         $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00313                         //$ilBench->start("ContentObjectExport", "exportStructureObject_getLMPageObject");
00314                         //$page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
00315                         //$ilBench->stop("ContentObjectExport", "exportStructureObject_getLMPageObject");
00316                         ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
00317                         //$page_obj->exportXML($a_xml_writer, "alias", $a_inst);
00318                         //unset($page_obj);
00319                         $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00320                 }
00321         }
00322 
00323 
00330         function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
00331         {
00332                 $this->tree = new ilTree($this->getLmId());
00333                 $this->tree->setTableNames('lm_tree', 'lm_data');
00334                 $this->tree->setTreeTablePK("lm_id");
00335 
00336                 $childs = $this->tree->getChilds($this->getId());
00337                 foreach ($childs as $child)
00338                 {
00339                         if($child["type"] != "st")
00340                         {
00341                                 continue;
00342                         }
00343 
00344                         // export xml to writer object
00345                         $structure_obj = new ilStructureObject($this->getContentObject(),
00346                                 $child["obj_id"]);
00347                         $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
00348                         unset($structure_obj);
00349                 }
00350         }
00351 
00358         function exportFO(&$a_xml_writer)
00359         {
00360                 global $ilBench;
00361 
00362                 //$expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
00363 
00364                 // fo:block (complete)
00365                 $attrs = array();
00366                 $attrs["font-family"] = "Times";
00367                 $attrs["font-size"] = "14pt";
00368                 $a_xml_writer->xmlElement("fo:block", $attrs, $this->getTitle());
00369 
00370                 // page objects
00371                 //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
00372                 $this->exportFOPageObjects($a_xml_writer);
00373                 //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
00374 
00375                 // structure objects
00376                 //$this->exportFOStructureObjects($a_xml_writer);
00377 
00378         }
00379 
00386         function exportFOPageObjects(&$a_xml_writer)
00387         {
00388                 global $ilBench;
00389 
00390                 $this->tree = new ilTree($this->getLmId());
00391                 $this->tree->setTableNames('lm_tree', 'lm_data');
00392                 $this->tree->setTreeTablePK("lm_id");
00393 
00394                 $childs = $this->tree->getChilds($this->getId());
00395                 foreach ($childs as $child)
00396                 {
00397                         if($child["type"] != "pg")
00398                         {
00399                                 continue;
00400                         }
00401 
00402                         // export xml to writer object
00403                         //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00404 
00405                         $page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
00406                         $page_obj->exportFO($a_xml_writer);
00407 
00408                         //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
00409                 }
00410         }
00411 
00412 }
00413 ?>

Generated on Fri Dec 13 2013 11:57:57 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1