ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilStructureObject.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  public string $origin_id;
27  public ilLMTree $tree;
28 
29  public function __construct(
30  ilObjLearningModule $a_content_obj,
31  int $a_id = 0
32  ) {
33  $this->setType("st");
34  parent::__construct($a_content_obj, $a_id);
35  $this->tree = new ilLMTree($this->getLMId());
36  }
37 
38  public function delete(bool $a_delete_meta_data = true): void
39  {
40  // only relevant for online help authoring
42 
43  $node_data = $this->tree->getNodeData($this->getId());
44  $this->delete_rec($this->tree, $a_delete_meta_data);
45  $this->tree->deleteTree($node_data);
46  }
47 
51  private function delete_rec(
52  ilLMTree $a_tree,
53  bool $a_delete_meta_data = true
54  ): void {
55  $childs = $a_tree->getChilds($this->getId());
56  foreach ($childs as $child) {
57  $obj = ilLMObjectFactory::getInstance($this->content_object, $child["obj_id"], false);
58  if (is_object($obj)) {
59  if ($obj->getType() == "st") {
60  $obj->delete_rec($a_tree, $a_delete_meta_data);
61  }
62  if ($obj->getType() == "pg") {
63  $obj->delete($a_delete_meta_data);
64  }
65  }
66  unset($obj);
67  }
68  parent::delete($a_delete_meta_data);
69  }
70 
74  public function copy(
75  ilObjLearningModule $a_target_lm
77  $chap = new ilStructureObject($a_target_lm);
78  $chap->setTitle($this->getTitle());
79  if ($this->getLMId() != $a_target_lm->getId()) {
80  $chap->setImportId("il__st_" . $this->getId());
81  }
82  $chap->setLMId($a_target_lm->getId());
83  $chap->setType($this->getType());
84  $chap->setDescription($this->getDescription());
85  $chap->create(true);
86  $a_copied_nodes[$this->getId()] = $chap->getId();
87 
88  // copy meta data
89  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
90  $new_md = $md->cloneMD($a_target_lm->getId(), $chap->getId(), $this->getType());
91 
92  // copy translations
93  ilLMObjTranslation::copy($this->getId(), $chap->getId());
94 
95 
96  return $chap;
97  }
98 
99  public function exportXML(
100  ilXmlWriter $a_xml_writer,
101  int $a_inst,
102  ilLog $expLog
103  ): void {
104  $expLog->write(date("[y-m-d H:i:s] ") . "Structure Object " . $this->getId());
105  $attrs = array();
106  $a_xml_writer->xmlStartTag("StructureObject", $attrs);
107 
108  // MetaData
109  $this->exportXMLMetaData($a_xml_writer);
110 
111  // StructureObjects
112  $this->exportXMLPageObjects($a_xml_writer, $a_inst);
113 
114  // PageObjects
115  $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
116 
117  $a_xml_writer->xmlEndTag("StructureObject");
118  }
119 
120  public function exportXMLMetaData(
121  ilXmlWriter $a_xml_writer
122  ): void {
123  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
124  $md2xml->setExportMode(true);
125  $md2xml->startExport();
126  $a_xml_writer->appendXML($md2xml->getXML());
127  }
128 
129  public function modifyExportIdentifier(
130  string $a_tag,
131  string $a_param,
132  string $a_value
133  ): string {
134  if ($a_tag == "Identifier" && $a_param == "Entry") {
135  $a_value = "il_" . IL_INST_ID . "_st_" . $this->getId();
136  }
137 
138  return $a_value;
139  }
140 
141  public static function _getPresentationTitle(
142  int $a_st_id,
143  string $a_mode = self::CHAPTER_TITLE,
144  bool $a_include_numbers = false,
145  bool $a_time_scheduled_activation = false,
146  bool $a_force_content = false,
147  int $a_lm_id = 0,
148  string $a_lang = "-",
149  bool $a_include_short = false
150  ): string {
151  global $DIC;
152 
153  $ilDB = $DIC->database();
154 
155  if ($a_lm_id == 0) {
156  $a_lm_id = ilLMObject::_lookupContObjID($a_st_id);
157  }
158 
159  if ($a_lm_id == 0) {
160  return "";
161  }
162 
163  // this is optimized when ilLMObject::preloadDataByLM is invoked (e.g. done in ilLMExplorerGUI)
164  $title = "";
165  if ($a_include_short) {
166  $title = trim(ilLMObject::_lookupShortTitle($a_st_id));
167  }
168  if ($title == "") {
169  $title = ilLMObject::_lookupTitle($a_st_id);
170  }
171 
172  // this is also optimized since ilObjectTranslation re-uses instances for one lm
173  $ot = ilObjectTranslation::getInstance($a_lm_id);
174  $languages = $ot->getLanguages();
175 
176  if ($a_lang != "-" && $ot->getContentActivated()) {
177  $lmobjtrans = new ilLMObjTranslation($a_st_id, $a_lang);
178  $trans_title = "";
179  if ($a_include_short) {
180  $trans_title = trim($lmobjtrans->getShortTitle());
181  }
182  if ($trans_title == "") {
183  $trans_title = $lmobjtrans->getTitle();
184  }
185  if ($trans_title == "") {
186  $lmobjtrans = new ilLMObjTranslation($a_st_id, $ot->getFallbackLanguage());
187  $trans_title = $lmobjtrans->getTitle();
188  }
189  if ($trans_title != "") {
190  $title = $trans_title;
191  }
192  }
193 
194  $tree = ilLMTree::getInstance($a_lm_id);
195 
196  $nr = "";
197  if ($a_include_numbers) {
198  // this is optimized, since isInTree is cached
199  if ($tree->isInTree($a_st_id)) {
200  // optimization needed from here
201 
202  // get chapter tree node
203  $query = "SELECT * FROM lm_tree WHERE child = " .
204  $ilDB->quote($a_st_id, "integer") . " AND lm_id = " .
205  $ilDB->quote($a_lm_id, "integer");
206  $tree_set = $ilDB->query($query);
207  $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
208  $depth = $tree_node["depth"];
209 
210  $nr = $tree->getChildSequenceNumber($tree_node, "st") . " ";
211  for ($i = $depth - 1; $i > 1; $i--) {
212  // get next parent tree node
213  $query = "SELECT * FROM lm_tree WHERE child = " .
214  $ilDB->quote($tree_node["parent"], "integer") . " AND lm_id = " .
215  $ilDB->quote($a_lm_id, "integer");
216  $tree_set = $ilDB->query($query);
217  $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
218  $seq = $tree->getChildSequenceNumber($tree_node, "st");
219 
220  $nr = $seq . "." . $nr;
221  }
222  }
223  }
224 
225  return $nr . $title;
226  }
227 
228  public function exportXMLPageObjects(
229  ilXmlWriter $a_xml_writer,
230  int $a_inst = 0
231  ): void {
232  $childs = $this->tree->getChilds($this->getId());
233  foreach ($childs as $child) {
234  if ($child["type"] != "pg") {
235  continue;
236  }
237 
238  // export xml to writer object
239  ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
240  }
241  }
242 
243  public function exportXMLStructureObjects(
244  ilXmlWriter $a_xml_writer,
245  int $a_inst,
246  ilLog $expLog
247  ): void {
248  $childs = $this->tree->getChilds($this->getId());
249  foreach ($childs as $child) {
250  if ($child["type"] != "st") {
251  continue;
252  }
253 
254  // export xml to writer object
255  $structure_obj = new ilStructureObject(
256  $this->getContentObject(),
257  $child["obj_id"]
258  );
259  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
260  unset($structure_obj);
261  }
262  }
263 
264  public function exportFO(
265  ilXmlWriter $a_xml_writer
266  ): void {
267 
268  // fo:block (complete)
269  $attrs = array();
270  $attrs["font-family"] = "Times";
271  $attrs["font-size"] = "14pt";
272  $a_xml_writer->xmlElement("fo:block", $attrs, $this->getTitle());
273 
274  // page objects
275  $this->exportFOPageObjects($a_xml_writer);
276  }
277 
278  public function exportFOPageObjects(
279  ilXmlWriter $a_xml_writer
280  ): void {
281  $childs = $this->tree->getChilds($this->getId());
282  foreach ($childs as $child) {
283  if ($child["type"] != "pg") {
284  continue;
285  }
286 
287  // export xml to writer object
288  $page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
289  $page_obj->exportFO($a_xml_writer);
290  }
291  }
292 
293  public static function getChapterList(
294  int $a_lm_id
295  ): array {
296  $tree = new ilLMTree($a_lm_id);
297 
298  $chapters = array();
299  $ndata = $tree->getNodeData($tree->readRootId());
300  $childs = $tree->getSubTree($ndata);
301  foreach ($childs as $child) {
302  if ($child["type"] == "st") {
303  $chapters[] = $child;
304  }
305  }
306  return $chapters;
307  }
308 }
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...
exportFO(ilXmlWriter $a_xml_writer)
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.
static copy(string $a_source_id, string $a_target_id)
Copy all translations of an object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $obj_id)
$query
exportFOPageObjects(ilXmlWriter $a_xml_writer)
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(Container $dic, ilPlugin $plugin)
exportXMLMetaData(ilXmlWriter $a_xml_writer)
static removeScreenIdsOfChapter(int $a_chap, int $a_module_id=0)
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.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
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)
$i
Definition: metadata.php:41