ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilStructureObject.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
16 {
17  public $is_alias;
18  public $origin_id;
19  public $tree;
20 
25  public function __construct(&$a_content_obj, $a_id = 0)
26  {
27  $this->setType("st");
28  parent::__construct($a_content_obj, $a_id);
29  }
30 
31  public function create($a_upload = false)
32  {
33  parent::create($a_upload);
34  }
35 
39  public function delete($a_delete_meta_data = true)
40  {
41  // only relevant for online help authoring
43 
44  $this->tree = new ilTree($this->getLmId());
45  $this->tree->setTableNames('lm_tree', 'lm_data');
46  $this->tree->setTreeTablePK("lm_id");
47  $node_data = $this->tree->getNodeData($this->getId());
48  $this->delete_rec($this->tree, $a_delete_meta_data);
49  $this->tree->deleteTree($node_data);
50  }
51 
55  private function delete_rec(&$a_tree, $a_delete_meta_data = true)
56  {
57  $childs = $a_tree->getChilds($this->getId());
58  foreach ($childs as $child) {
59  $obj = ilLMObjectFactory::getInstance($this->content_object, $child["obj_id"], false);
60  if (is_object($obj)) {
61  if ($obj->getType() == "st") {
62  $obj->delete_rec($a_tree, $a_delete_meta_data);
63  }
64  if ($obj->getType() == "pg") {
65  $obj->delete($a_delete_meta_data);
66  }
67  }
68  unset($obj);
69  }
70  parent::delete($a_delete_meta_data);
71  }
72 
76  public function copy($a_target_lm)
77  {
78  $chap = new ilStructureObject($a_target_lm);
79  $chap->setTitle($this->getTitle());
80  if ($this->getLMId() != $a_target_lm->getId()) {
81  $chap->setImportId("il__st_" . $this->getId());
82  }
83  $chap->setLMId($a_target_lm->getId());
84  $chap->setType($this->getType());
85  $chap->setDescription($this->getDescription());
86  $chap->create(true);
87  $a_copied_nodes[$this->getId()] = $chap->getId();
88 
89  // copy meta data
90  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
91  $new_md = $md->cloneMD($a_target_lm->getId(), $chap->getId(), $this->getType());
92 
93  // copy translations
94  ilLMObjTranslation::copy($this->getId(), $chap->getId());
95 
96 
97  return $chap;
98  }
99 
106  public function exportXML(&$a_xml_writer, $a_inst, &$expLog)
107  {
108  $expLog->write(date("[y-m-d H:i:s] ") . "Structure Object " . $this->getId());
109  $attrs = array();
110  $a_xml_writer->xmlStartTag("StructureObject", $attrs);
111 
112  // MetaData
113  $this->exportXMLMetaData($a_xml_writer);
114 
115  // StructureObjects
116  $this->exportXMLPageObjects($a_xml_writer, $a_inst);
117 
118  // PageObjects
119  $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
120 
121  // Layout
122  // not implemented
123 
124  $a_xml_writer->xmlEndTag("StructureObject");
125  }
126 
127 
134  public function exportXMLMetaData(&$a_xml_writer)
135  {
136  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
137  $md2xml->setExportMode(true);
138  $md2xml->startExport();
139  $a_xml_writer->appendXML($md2xml->getXML());
140  }
141 
142  public function modifyExportIdentifier($a_tag, $a_param, $a_value)
143  {
144  if ($a_tag == "Identifier" && $a_param == "Entry") {
145  $a_value = "il_" . IL_INST_ID . "_st_" . $this->getId();
146  }
147 
148  return $a_value;
149  }
150 
155  public static function _getPresentationTitle(
156  $a_st_id,
157  $a_mode = self::CHAPTER_TITLE,
158  $a_include_numbers = false,
159  $a_time_scheduled_activation = false,
160  $a_force_content = false,
161  $a_lm_id = 0,
162  $a_lang = "-",
163  $a_include_short = false
164  ) {
165  global $DIC;
166 
167  $ilDB = $DIC->database();
168 
169  if ($a_lm_id == 0) {
170  $a_lm_id = ilLMObject::_lookupContObjID($a_st_id);
171  }
172 
173  if ($a_lm_id == 0) {
174  return "";
175  }
176 
177  // this is optimized when ilLMObject::preloadDataByLM is invoked (e.g. done in ilLMExplorerGUI)
178  $title = "";
179  if ($a_include_short) {
180  $title = trim(ilLMObject::_lookupShortTitle($a_st_id));
181  }
182  if ($title == "") {
183  $title = ilLMObject::_lookupTitle($a_st_id);
184  }
185 
186  // this is also optimized since ilObjectTranslation re-uses instances for one lm
187  $ot = ilObjectTranslation::getInstance($a_lm_id);
188  $languages = $ot->getLanguages();
189 
190  if ($a_lang != "-" && $ot->getContentActivated() && isset($languages[$a_lang])) {
191  $lmobjtrans = new ilLMObjTranslation($a_st_id, $a_lang);
192  $trans_title = "";
193  if ($a_include_short) {
194  $trans_title = trim($lmobjtrans->getShortTitle());
195  }
196  if ($trans_title == "") {
197  $trans_title = $lmobjtrans->getTitle();
198  }
199  if ($trans_title != "") {
200  $title = $trans_title;
201  }
202  }
203 
204  $tree = ilLMTree::getInstance($a_lm_id);
205 
206  if ($a_include_numbers) {
207  // this is optimized, since isInTree is cached
208  if ($tree->isInTree($a_st_id)) {
209  // optimization needed from here
210 
211  // get chapter tree node
212  $query = "SELECT * FROM lm_tree WHERE child = " .
213  $ilDB->quote($a_st_id, "integer") . " AND lm_id = " .
214  $ilDB->quote($a_lm_id, "integer");
215  $tree_set = $ilDB->query($query);
216  $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
217  $depth = $tree_node["depth"];
218 
219  $nr = $tree->getChildSequenceNumber($tree_node, "st") . " ";
220  for ($i = $depth - 1; $i > 1; $i--) {
221  // get next parent tree node
222  $query = "SELECT * FROM lm_tree WHERE child = " .
223  $ilDB->quote($tree_node["parent"], "integer") . " AND lm_id = " .
224  $ilDB->quote($a_lm_id, "integer");
225  $tree_set = $ilDB->query($query);
226  $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
227  $seq = $tree->getChildSequenceNumber($tree_node, "st");
228 
229  $nr = $seq . "." . $nr;
230  }
231  }
232  }
233 
234  return $nr . $title;
235  }
236 
237 
238 
245  public function exportXMLPageObjects(&$a_xml_writer, $a_inst = 0)
246  {
247  $this->tree = new ilTree($this->getLmId());
248  $this->tree->setTableNames('lm_tree', 'lm_data');
249  $this->tree->setTreeTablePK("lm_id");
250 
251  $childs = $this->tree->getChilds($this->getId());
252  foreach ($childs as $child) {
253  if ($child["type"] != "pg") {
254  continue;
255  }
256 
257  // export xml to writer object
258  ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
259  }
260  }
261 
262 
269  public function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
270  {
271  $this->tree = new ilTree($this->getLmId());
272  $this->tree->setTableNames('lm_tree', 'lm_data');
273  $this->tree->setTreeTablePK("lm_id");
274 
275  $childs = $this->tree->getChilds($this->getId());
276  foreach ($childs as $child) {
277  if ($child["type"] != "st") {
278  continue;
279  }
280 
281  // export xml to writer object
282  $structure_obj = new ilStructureObject(
283  $this->getContentObject(),
284  $child["obj_id"]
285  );
286  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
287  unset($structure_obj);
288  }
289  }
290 
297  public function exportFO(&$a_xml_writer)
298  {
299 
300  // fo:block (complete)
301  $attrs = array();
302  $attrs["font-family"] = "Times";
303  $attrs["font-size"] = "14pt";
304  $a_xml_writer->xmlElement("fo:block", $attrs, $this->getTitle());
305 
306  // page objects
307  $this->exportFOPageObjects($a_xml_writer);
308  }
309 
316  public function exportFOPageObjects(&$a_xml_writer)
317  {
318  $this->tree = new ilTree($this->getLmId());
319  $this->tree->setTableNames('lm_tree', 'lm_data');
320  $this->tree->setTreeTablePK("lm_id");
321 
322  $childs = $this->tree->getChilds($this->getId());
323  foreach ($childs as $child) {
324  if ($child["type"] != "pg") {
325  continue;
326  }
327 
328  // export xml to writer object
329  $page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
330  $page_obj->exportFO($a_xml_writer);
331  }
332  }
333 
340  public static function getChapterList($a_lm_id)
341  {
342  $tree = new ilTree($a_lm_id);
343  $tree->setTableNames('lm_tree', 'lm_data');
344  $tree->setTreeTablePK("lm_id");
345 
346  $chapters = array();
347  $ndata = $tree->getNodeData($tree->readRootId());
348  $childs = $tree->getSubtree($ndata);
349  foreach ($childs as $child) {
350  if ($child["type"] == "st") {
351  $chapters[] = $child;
352  }
353  }
354  return $chapters;
355  }
356 }
static getChapterList($a_lm_id)
export (sub)structure objects of structure object (see ilias_co.dtd)
__construct(&$a_content_obj, $a_id=0)
Constructor public.
setType($a_type)
static _lookupShortTitle($a_obj_id)
Lookup short title.
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
static removeScreenIdsOfChapter($a_chap, $a_module_id=0)
Remove screen ids of chapter.
delete_rec(&$a_tree, $a_delete_meta_data=true)
Delete sub tree.
static _lookupTitle($a_obj_id)
Lookup title.
Class ilLMPageObject.
modifyExportIdentifier($a_tag, $a_param, $a_value)
static getInstance($a_tree_id)
Get Instance.
static _getPresentationTitle( $a_st_id, $a_mode=self::CHAPTER_TITLE, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_force_content=false, $a_lm_id=0, $a_lang="-", $a_include_short=false)
get presentation title
static getInstance(&$a_content_obj, $a_id=0, $a_halt=true)
exportXML(&$a_xml_writer, $a_inst, &$expLog)
export object to xml (see ilias_co.dtd)
exportXMLMetaData(&$a_xml_writer)
export structure objects meta data to xml (see ilias_co.dtd)
$query
exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
export (sub)structure objects of structure object (see ilias_co.dtd)
copy($a_target_lm)
copy chapter
exportFOPageObjects(&$a_xml_writer)
export page objects of structure object (see ilias_co.dtd)
getTitle()
get title of lm object
Class ilStructreObject.
__construct(Container $dic, ilPlugin $plugin)
static getInstance($a_obj_id)
Get instance.
global $ilDB
$DIC
Definition: xapitoken.php:46
exportXMLPageObjects(&$a_xml_writer, $a_inst=0)
export page objects of structure object (see ilias_co.dtd)
static _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst=0)
export page alias to xml
Translation information on lm object.
Class ilLMObject.
exportFO(&$a_xml_writer)
export object to fo
static copy($a_source_id, $a_target_id)
Copy all translations of an object.
$i
Definition: metadata.php:24