ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilStructureObject.php
Go to the documentation of this file.
1<?php
2
21
28{
29 protected \ILIAS\Help\Map\MapManager $help_map;
30 protected LOMServices $lom_services;
31 public string $origin_id;
33
34 public function __construct(
35 ilObjLearningModule $a_content_obj,
36 int $a_id = 0
37 ) {
38 global $DIC;
39
40 $this->setType("st");
41 parent::__construct($a_content_obj, $a_id);
42 $this->tree = new ilLMTree($this->getLMId());
43 $this->help_map = $DIC->help()->internal()->domain()->map();
44 $this->lom_services = $DIC->learningObjectMetadata();
45 }
46
47 public function delete(bool $a_delete_meta_data = true): void
48 {
49 // only relevant for online help authoring
50 $this->help_map->removeScreenIdsOfChapter($this->getId());
51
52 $node_data = $this->tree->getNodeData($this->getId());
53 $this->delete_rec($this->tree, $a_delete_meta_data);
54 $this->tree->deleteTree($node_data);
55 }
56
60 private function delete_rec(
61 ilLMTree $a_tree,
62 bool $a_delete_meta_data = true
63 ): void {
64 $childs = $a_tree->getChilds($this->getId());
65 foreach ($childs as $child) {
66 $obj = ilLMObjectFactory::getInstance($this->content_object, $child["obj_id"], false);
67 if (is_object($obj)) {
68 if ($obj->getType() == "st") {
69 $obj->delete_rec($a_tree, $a_delete_meta_data);
70 }
71 if ($obj->getType() == "pg") {
72 $obj->delete($a_delete_meta_data);
73 }
74 }
75 unset($obj);
76 }
77 parent::delete($a_delete_meta_data);
78 }
79
83 public function copy(
84 ilObjLearningModule $a_target_lm
86 $chap = new ilStructureObject($a_target_lm);
87 $chap->setTitle($this->getTitle());
88 if ($this->getLMId() != $a_target_lm->getId()) {
89 $chap->setImportId("il__st_" . $this->getId());
90 }
91 $chap->setLMId($a_target_lm->getId());
92 $chap->setType($this->getType());
93 $chap->setDescription($this->getDescription());
94 $chap->create(true);
95 $a_copied_nodes[$this->getId()] = $chap->getId();
96
97 // copy meta data
98 $this->lom_services->derive()
99 ->fromObject($this->getLMId(), $this->getId(), $this->getType())
100 ->forObject($a_target_lm->getId(), $chap->getId(), $this->getType());
101
102 // copy translations
103 ilLMObjTranslation::copy($this->getId(), $chap->getId());
104
105
106 return $chap;
107 }
108
109 public function exportXML(
110 ilXmlWriter $a_xml_writer,
111 int $a_inst,
112 ilLog $expLog
113 ): void {
114 $expLog->write(date("[y-m-d H:i:s] ") . "Structure Object " . $this->getId());
115 $attrs = array();
116 $a_xml_writer->xmlStartTag("StructureObject", $attrs);
117
118 // MetaData
119 $this->exportXMLMetaData($a_xml_writer);
120
121 // StructureObjects
122 $this->exportXMLPageObjects($a_xml_writer, $a_inst);
123
124 // PageObjects
125 $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
126
127 $a_xml_writer->xmlEndTag("StructureObject");
128 }
129
130 public function exportXMLMetaData(
131 ilXmlWriter $a_xml_writer
132 ): void {
133 /*
134 * As far as I can tell, this is unused.
135 *
136 * I traced usages of this method up to ilObjContentObjectGUI::export and
137 * ilObjMediaPoolGUI::export (both via ilObjContentObject::exportXML), which have
138 * both been made redundant by the usual export mechanisms.
139 */
140 /*$md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
141 $md2xml->setExportMode(true);
142 $md2xml->startExport();
143 $a_xml_writer->appendXML($md2xml->getXML());*/
144 }
145
146 public function modifyExportIdentifier(
147 string $a_tag,
148 string $a_param,
149 string $a_value
150 ): string {
151 if ($a_tag == "Identifier" && $a_param == "Entry") {
152 $a_value = "il_" . IL_INST_ID . "_st_" . $this->getId();
153 }
154
155 return $a_value;
156 }
157
158 public static function _getPresentationTitle(
159 int $a_st_id,
160 string $a_mode = self::CHAPTER_TITLE,
161 bool $a_include_numbers = false,
162 bool $a_time_scheduled_activation = false,
163 bool $a_force_content = false,
164 int $a_lm_id = 0,
165 string $a_lang = "-",
166 bool $a_include_short = false
167 ): string {
168 global $DIC;
169
170 $ilDB = $DIC->database();
171
172 if ($a_lm_id == 0) {
173 $a_lm_id = ilLMObject::_lookupContObjID($a_st_id);
174 }
175
176 if ($a_lm_id == 0) {
177 return "";
178 }
179
180 // this is optimized when ilLMObject::preloadDataByLM is invoked (e.g. done in ilLMExplorerGUI)
181 $title = "";
182 if ($a_include_short) {
183 $title = trim(ilLMObject::_lookupShortTitle($a_st_id));
184 }
185 if ($title == "") {
186 $title = ilLMObject::_lookupTitle($a_st_id);
187 }
188
189 $ot = (new TranslationsRepository($ilDB))->getFor($a_lm_id);
190
191 if ($a_lang != "-" && $ot->getContentTranslationActivated()) {
192 $lmobjtrans = new ilLMObjTranslation($a_st_id, $a_lang);
193 $trans_title = "";
194 if ($a_include_short) {
195 $trans_title = trim($lmobjtrans->getShortTitle());
196 }
197 if ($trans_title == "") {
198 $trans_title = $lmobjtrans->getTitle();
199 }
200 if ($trans_title == "") {
201 $lmobjtrans = new ilLMObjTranslation($a_st_id, $ot->getDefaultLanguage());
202 $trans_title = $lmobjtrans->getTitle();
203 }
204 if ($trans_title != "") {
205 $title = $trans_title;
206 }
207 }
208
209 $tree = ilLMTree::getInstance($a_lm_id);
210
211 $nr = "";
212 if ($a_include_numbers) {
213 // this is optimized, since isInTree is cached
214 if ($tree->isInTree($a_st_id)) {
215 // optimization needed from here
216
217 // get chapter tree node
218 $query = "SELECT * FROM lm_tree WHERE child = " .
219 $ilDB->quote($a_st_id, "integer") . " AND lm_id = " .
220 $ilDB->quote($a_lm_id, "integer");
221 $tree_set = $ilDB->query($query);
222 $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
223 $depth = $tree_node["depth"];
224
225 $nr = $tree->getChildSequenceNumber($tree_node, "st") . " ";
226 for ($i = $depth - 1; $i > 1; $i--) {
227 // get next parent tree node
228 $query = "SELECT * FROM lm_tree WHERE child = " .
229 $ilDB->quote($tree_node["parent"], "integer") . " AND lm_id = " .
230 $ilDB->quote($a_lm_id, "integer");
231 $tree_set = $ilDB->query($query);
232 $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
233 $seq = $tree->getChildSequenceNumber($tree_node, "st");
234
235 $nr = $seq . "." . $nr;
236 }
237 }
238 }
239
240 return $nr . $title;
241 }
242
243 public function exportXMLPageObjects(
244 ilXmlWriter $a_xml_writer,
245 int $a_inst = 0
246 ): void {
247 $childs = $this->tree->getChilds($this->getId());
248 foreach ($childs as $child) {
249 if ($child["type"] != "pg") {
250 continue;
251 }
252
253 // export xml to writer object
254 ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
255 }
256 }
257
259 ilXmlWriter $a_xml_writer,
260 int $a_inst,
261 ilLog $expLog
262 ): void {
263 $childs = $this->tree->getChilds($this->getId());
264 foreach ($childs as $child) {
265 if ($child["type"] != "st") {
266 continue;
267 }
268
269 // export xml to writer object
270 $structure_obj = new ilStructureObject(
271 $this->getContentObject(),
272 $child["obj_id"]
273 );
274 $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
275 unset($structure_obj);
276 }
277 }
278
279
280 public static function getChapterList(
281 int $a_lm_id
282 ): array {
283 $tree = new ilLMTree($a_lm_id);
284
285 $chapters = array();
286 $ndata = $tree->getNodeData($tree->readRootId());
287 $childs = $tree->getSubTree($ndata);
288 foreach ($childs as $child) {
289 if ($child["type"] == "st") {
290 $chapters[] = $child;
291 }
292 }
293 return $chapters;
294 }
295}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static copy(string $a_source_id, string $a_target_id)
Copy all translations of an object.
static getInstance(ilObjLearningModule $a_content_obj, int $a_id=0, bool $a_halt=true)
Class ilLMObject.
static _lookupShortTitle(int $a_obj_id)
static _lookupContObjID(int $a_id)
get learning module id for lm object
static _lookupTitle(int $a_obj_id)
setType(string $a_type)
setTitle(string $a_title)
static _exportXMLAlias(ilXmlWriter $a_xml_writer, int $a_id, int $a_inst=0)
export page alias to xml
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $a_tree_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exportXMLStructureObjects(ilXmlWriter $a_xml_writer, int $a_inst, ilLog $expLog)
exportXML(ilXmlWriter $a_xml_writer, int $a_inst, ilLog $expLog)
__construct(ilObjLearningModule $a_content_obj, int $a_id=0)
static _getPresentationTitle(int $a_st_id, string $a_mode=self::CHAPTER_TITLE, bool $a_include_numbers=false, bool $a_time_scheduled_activation=false, bool $a_force_content=false, int $a_lm_id=0, string $a_lang="-", bool $a_include_short=false)
ILIAS Help Map MapManager $help_map
copy(ilObjLearningModule $a_target_lm)
copy chapter
exportXMLMetaData(ilXmlWriter $a_xml_writer)
delete_rec(ilLMTree $a_tree, bool $a_delete_meta_data=true)
Delete sub tree.
static getChapterList(int $a_lm_id)
exportXMLPageObjects(ilXmlWriter $a_xml_writer, int $a_inst=0)
getChildSequenceNumber(array $a_node, string $type="")
get sequence number of node in sibling sequence
isInTree(?int $a_node_id)
get all information of a node.
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
const IL_INST_ID
Definition: constants.php:40
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26