ILIAS  release_7 Revision v7.30-3-g800a261c036
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 == "") {
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()) {
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 $lmobjtrans = new ilLMObjTranslation($a_st_id, $ot->getFallbackLanguage());
201 $trans_title = $lmobjtrans->getTitle();
202 }
203 if ($trans_title != "") {
204 $title = $trans_title;
205 }
206 }
207
208 $tree = ilLMTree::getInstance($a_lm_id);
209
210 if ($a_include_numbers) {
211 // this is optimized, since isInTree is cached
212 if ($tree->isInTree($a_st_id)) {
213 // optimization needed from here
214
215 // get chapter tree node
216 $query = "SELECT * FROM lm_tree WHERE child = " .
217 $ilDB->quote($a_st_id, "integer") . " AND lm_id = " .
218 $ilDB->quote($a_lm_id, "integer");
219 $tree_set = $ilDB->query($query);
220 $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
221 $depth = $tree_node["depth"];
222
223 $nr = $tree->getChildSequenceNumber($tree_node, "st") . " ";
224 for ($i = $depth - 1; $i > 1; $i--) {
225 // get next parent tree node
226 $query = "SELECT * FROM lm_tree WHERE child = " .
227 $ilDB->quote($tree_node["parent"], "integer") . " AND lm_id = " .
228 $ilDB->quote($a_lm_id, "integer");
229 $tree_set = $ilDB->query($query);
230 $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
231 $seq = $tree->getChildSequenceNumber($tree_node, "st");
232
233 $nr = $seq . "." . $nr;
234 }
235 }
236 }
237
238 return $nr . $title;
239 }
240
241
242
249 public function exportXMLPageObjects(&$a_xml_writer, $a_inst = 0)
250 {
251 $this->tree = new ilTree($this->getLmId());
252 $this->tree->setTableNames('lm_tree', 'lm_data');
253 $this->tree->setTreeTablePK("lm_id");
254
255 $childs = $this->tree->getChilds($this->getId());
256 foreach ($childs as $child) {
257 if ($child["type"] != "pg") {
258 continue;
259 }
260
261 // export xml to writer object
262 ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
263 }
264 }
265
266
273 public function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
274 {
275 $this->tree = new ilTree($this->getLmId());
276 $this->tree->setTableNames('lm_tree', 'lm_data');
277 $this->tree->setTreeTablePK("lm_id");
278
279 $childs = $this->tree->getChilds($this->getId());
280 foreach ($childs as $child) {
281 if ($child["type"] != "st") {
282 continue;
283 }
284
285 // export xml to writer object
286 $structure_obj = new ilStructureObject(
287 $this->getContentObject(),
288 $child["obj_id"]
289 );
290 $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
291 unset($structure_obj);
292 }
293 }
294
301 public function exportFO(&$a_xml_writer)
302 {
303
304 // fo:block (complete)
305 $attrs = array();
306 $attrs["font-family"] = "Times";
307 $attrs["font-size"] = "14pt";
308 $a_xml_writer->xmlElement("fo:block", $attrs, $this->getTitle());
309
310 // page objects
311 $this->exportFOPageObjects($a_xml_writer);
312 }
313
320 public function exportFOPageObjects(&$a_xml_writer)
321 {
322 $this->tree = new ilTree($this->getLmId());
323 $this->tree->setTableNames('lm_tree', 'lm_data');
324 $this->tree->setTreeTablePK("lm_id");
325
326 $childs = $this->tree->getChilds($this->getId());
327 foreach ($childs as $child) {
328 if ($child["type"] != "pg") {
329 continue;
330 }
331
332 // export xml to writer object
333 $page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
334 $page_obj->exportFO($a_xml_writer);
335 }
336 }
337
344 public static function getChapterList($a_lm_id)
345 {
346 $tree = new ilTree($a_lm_id);
347 $tree->setTableNames('lm_tree', 'lm_data');
348 $tree->setTreeTablePK("lm_id");
349
350 $chapters = array();
351 $ndata = $tree->getNodeData($tree->readRootId());
352 $childs = $tree->getSubtree($ndata);
353 foreach ($childs as $child) {
354 if ($child["type"] == "st") {
355 $chapters[] = $child;
356 }
357 }
358 return $chapters;
359 }
360}
An exception for terminatinating execution or to throw for unit testing.
static removeScreenIdsOfChapter($a_chap, $a_module_id=0)
Remove screen ids of chapter.
Translation information on lm object.
static copy($a_source_id, $a_target_id)
Copy all translations of an object.
static getInstance(&$a_content_obj, $a_id=0, $a_halt=true)
Class ilLMObject.
static _lookupShortTitle($a_obj_id)
Lookup short title.
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
getTitle()
get title of lm object
static _lookupTitle($a_obj_id)
Lookup title.
setType($a_type)
Class ilLMPageObject.
static _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst=0)
export page alias to xml
static getInstance($a_tree_id)
Get Instance.
static getInstance($a_obj_id)
Get instance.
Class ilStructreObject.
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)
__construct(&$a_content_obj, $a_id=0)
Constructor @access public.
static getChapterList($a_lm_id)
export (sub)structure objects of structure object (see ilias_co.dtd)
exportFO(&$a_xml_writer)
export object to fo
delete_rec(&$a_tree, $a_delete_meta_data=true)
Delete sub tree.
exportXMLPageObjects(&$a_xml_writer, $a_inst=0)
export page objects of structure object (see ilias_co.dtd)
exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
export (sub)structure objects of structure object (see ilias_co.dtd)
modifyExportIdentifier($a_tag, $a_param, $a_value)
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
copy($a_target_lm)
copy chapter
exportFOPageObjects(&$a_xml_writer)
export page objects of structure object (see ilias_co.dtd)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
global $ilDB