ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilStructureObject.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected \ILIAS\Help\Map\MapManager $help_map;
27  public string $origin_id;
28  public ilLMTree $tree;
29 
30  public function __construct(
31  ilObjLearningModule $a_content_obj,
32  int $a_id = 0
33  ) {
34  global $DIC;
35 
36  $this->setType("st");
37  parent::__construct($a_content_obj, $a_id);
38  $this->tree = new ilLMTree($this->getLMId());
39  $this->help_map = $DIC->help()->internal()->domain()->map();
40  }
41 
42  public function delete(bool $a_delete_meta_data = true): void
43  {
44  // only relevant for online help authoring
45  $this->help_map->removeScreenIdsOfChapter($this->getId());
46 
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(
56  ilLMTree $a_tree,
57  bool $a_delete_meta_data = true
58  ): void {
59  $childs = $a_tree->getChilds($this->getId());
60  foreach ($childs as $child) {
61  $obj = ilLMObjectFactory::getInstance($this->content_object, $child["obj_id"], false);
62  if (is_object($obj)) {
63  if ($obj->getType() == "st") {
64  $obj->delete_rec($a_tree, $a_delete_meta_data);
65  }
66  if ($obj->getType() == "pg") {
67  $obj->delete($a_delete_meta_data);
68  }
69  }
70  unset($obj);
71  }
72  parent::delete($a_delete_meta_data);
73  }
74 
78  public function copy(
79  ilObjLearningModule $a_target_lm
81  $chap = new ilStructureObject($a_target_lm);
82  $chap->setTitle($this->getTitle());
83  if ($this->getLMId() != $a_target_lm->getId()) {
84  $chap->setImportId("il__st_" . $this->getId());
85  }
86  $chap->setLMId($a_target_lm->getId());
87  $chap->setType($this->getType());
88  $chap->setDescription($this->getDescription());
89  $chap->create(true);
90  $a_copied_nodes[$this->getId()] = $chap->getId();
91 
92  // copy meta data
93  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
94  $new_md = $md->cloneMD($a_target_lm->getId(), $chap->getId(), $this->getType());
95 
96  // copy translations
97  ilLMObjTranslation::copy($this->getId(), $chap->getId());
98 
99 
100  return $chap;
101  }
102 
103  public function exportXML(
104  ilXmlWriter $a_xml_writer,
105  int $a_inst,
106  ilLog $expLog
107  ): void {
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  $a_xml_writer->xmlEndTag("StructureObject");
122  }
123 
124  public function exportXMLMetaData(
125  ilXmlWriter $a_xml_writer
126  ): void {
127  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
128  $md2xml->setExportMode(true);
129  $md2xml->startExport();
130  $a_xml_writer->appendXML($md2xml->getXML());
131  }
132 
133  public function modifyExportIdentifier(
134  string $a_tag,
135  string $a_param,
136  string $a_value
137  ): string {
138  if ($a_tag == "Identifier" && $a_param == "Entry") {
139  $a_value = "il_" . IL_INST_ID . "_st_" . $this->getId();
140  }
141 
142  return $a_value;
143  }
144 
145  public static function _getPresentationTitle(
146  int $a_st_id,
147  string $a_mode = self::CHAPTER_TITLE,
148  bool $a_include_numbers = false,
149  bool $a_time_scheduled_activation = false,
150  bool $a_force_content = false,
151  int $a_lm_id = 0,
152  string $a_lang = "-",
153  bool $a_include_short = false
154  ): string {
155  global $DIC;
156 
157  $ilDB = $DIC->database();
158 
159  if ($a_lm_id == 0) {
160  $a_lm_id = ilLMObject::_lookupContObjID($a_st_id);
161  }
162 
163  if ($a_lm_id == 0) {
164  return "";
165  }
166 
167  // this is optimized when ilLMObject::preloadDataByLM is invoked (e.g. done in ilLMExplorerGUI)
168  $title = "";
169  if ($a_include_short) {
170  $title = trim(ilLMObject::_lookupShortTitle($a_st_id));
171  }
172  if ($title == "") {
173  $title = ilLMObject::_lookupTitle($a_st_id);
174  }
175 
176  // this is also optimized since ilObjectTranslation re-uses instances for one lm
177  $ot = ilObjectTranslation::getInstance($a_lm_id);
178  $languages = $ot->getLanguages();
179 
180  if ($a_lang != "-" && $ot->getContentActivated()) {
181  $lmobjtrans = new ilLMObjTranslation($a_st_id, $a_lang);
182  $trans_title = "";
183  if ($a_include_short) {
184  $trans_title = trim($lmobjtrans->getShortTitle());
185  }
186  if ($trans_title == "") {
187  $trans_title = $lmobjtrans->getTitle();
188  }
189  if ($trans_title == "") {
190  $lmobjtrans = new ilLMObjTranslation($a_st_id, $ot->getFallbackLanguage());
191  $trans_title = $lmobjtrans->getTitle();
192  }
193  if ($trans_title != "") {
194  $title = $trans_title;
195  }
196  }
197 
198  $tree = ilLMTree::getInstance($a_lm_id);
199 
200  $nr = "";
201  if ($a_include_numbers) {
202  // this is optimized, since isInTree is cached
203  if ($tree->isInTree($a_st_id)) {
204  // optimization needed from here
205 
206  // get chapter tree node
207  $query = "SELECT * FROM lm_tree WHERE child = " .
208  $ilDB->quote($a_st_id, "integer") . " AND lm_id = " .
209  $ilDB->quote($a_lm_id, "integer");
210  $tree_set = $ilDB->query($query);
211  $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
212  $depth = $tree_node["depth"];
213 
214  $nr = $tree->getChildSequenceNumber($tree_node, "st") . " ";
215  for ($i = $depth - 1; $i > 1; $i--) {
216  // get next parent tree node
217  $query = "SELECT * FROM lm_tree WHERE child = " .
218  $ilDB->quote($tree_node["parent"], "integer") . " AND lm_id = " .
219  $ilDB->quote($a_lm_id, "integer");
220  $tree_set = $ilDB->query($query);
221  $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
222  $seq = $tree->getChildSequenceNumber($tree_node, "st");
223 
224  $nr = $seq . "." . $nr;
225  }
226  }
227  }
228 
229  return $nr . $title;
230  }
231 
232  public function exportXMLPageObjects(
233  ilXmlWriter $a_xml_writer,
234  int $a_inst = 0
235  ): void {
236  $childs = $this->tree->getChilds($this->getId());
237  foreach ($childs as $child) {
238  if ($child["type"] != "pg") {
239  continue;
240  }
241 
242  // export xml to writer object
243  ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
244  }
245  }
246 
247  public function exportXMLStructureObjects(
248  ilXmlWriter $a_xml_writer,
249  int $a_inst,
250  ilLog $expLog
251  ): void {
252  $childs = $this->tree->getChilds($this->getId());
253  foreach ($childs as $child) {
254  if ($child["type"] != "st") {
255  continue;
256  }
257 
258  // export xml to writer object
259  $structure_obj = new ilStructureObject(
260  $this->getContentObject(),
261  $child["obj_id"]
262  );
263  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
264  unset($structure_obj);
265  }
266  }
267 
268 
269  public static function getChapterList(
270  int $a_lm_id
271  ): array {
272  $tree = new ilLMTree($a_lm_id);
273 
274  $chapters = array();
275  $ndata = $tree->getNodeData($tree->readRootId());
276  $childs = $tree->getSubTree($ndata);
277  foreach ($childs as $child) {
278  if ($child["type"] == "st") {
279  $chapters[] = $child;
280  }
281  }
282  return $chapters;
283  }
284 }
modifyExportIdentifier(string $a_tag, string $a_param, string $a_value)
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)
static _exportXMLAlias(ilXmlWriter $a_xml_writer, int $a_id, int $a_inst=0)
export page alias to xml
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exportXMLPageObjects(ilXmlWriter $a_xml_writer, int $a_inst=0)
const IL_INST_ID
Definition: constants.php:40
exportXML(ilXmlWriter $a_xml_writer, int $a_inst, ilLog $expLog)
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
copy(ilObjLearningModule $a_target_lm)
copy chapter
static getInstance(ilObjLearningModule $a_content_obj, int $a_id=0, bool $a_halt=true)
exportXMLStructureObjects(ilXmlWriter $a_xml_writer, int $a_inst, ilLog $expLog)
isInTree(?int $a_node_id)
get all information of a node.
setType(string $a_type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupShortTitle(int $a_obj_id)
appendXML(string $a_str)
append xml string to document
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:30
static getInstance(int $a_tree_id)
xmlEndTag(string $tag)
Writes an endtag.
static _lookupTitle(int $a_obj_id)
global $DIC
Definition: feed.php:28
static getChapterList(int $a_lm_id)
delete_rec(ilLMTree $a_tree, bool $a_delete_meta_data=true)
Delete sub tree.
__construct(VocabulariesInterface $vocabularies)
static copy(string $a_source_id, string $a_target_id)
Copy all translations of an object.
static getInstance(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Help Map MapManager $help_map
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exportXMLMetaData(ilXmlWriter $a_xml_writer)
static _lookupContObjID(int $a_id)
get learning module id for lm object
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
write(string $a_msg, $a_log_level=null)
logging
getChildSequenceNumber(array $a_node, string $type="")
get sequence number of node in sibling sequence
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjLearningModule $a_content_obj, int $a_id=0)