ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilSoapLMStructureReader.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22  */
23 
24 
32 {
33  public function _parseStructure(): void
34  {
36  $obect = $this->object;
37 
38  $ctree = $obect->getLMTree();
39 
40  $nodes = $ctree->getSubTree($ctree->getNodeData($ctree->getRootId()));
41 
42  $currentParentStructureObject = $this->structureObject;
43  $currentParent = 1;
44 
45  $parents = [];
46  $parents[$currentParent] = $currentParentStructureObject;
47 
48  $lastStructureObject = null;
49  $lastNode = null;
50  foreach ($nodes as $node) {
51  // only pages and chapters
52  if ($node["type"] === "st" || $node["type"] === "pg") {
53  // parent has changed, to build a tree
54  if ((int) $currentParent !== (int) $node["parent"]) {
55  // did we passed this parent before?
56 
57  if (array_key_exists($node["parent"], $parents)) {
58  $currentParentStructureObject = $parents[$node["parent"]];
59  } elseif ($lastNode["type"] !== "pg") {
60  // no, we did not, so use the last inserted structure as new parent
61  $parents[$lastNode["child"]] = $lastStructureObject;
62  $currentParentStructureObject = $lastStructureObject;
63  }
64  $currentParent = $lastNode["child"];
65  }
66 
67  $lastNode = $node;
68 
69  $lastStructureObject = ilSoapStructureObjectFactory::getInstance(
70  $node["obj_id"],
71  $node["type"],
72  $node["title"],
73  $node["description"],
74  $this->getObject()->getRefId()
75  );
76 
77  $currentParentStructureObject->addStructureObject($lastStructureObject);
78  }
79  }
80  }
81 }
Abstract classs for reading structure objects.
ilSoapStructureObject $structureObject
getInstance(int $objId, string $type, string $title, string $description, int $parentRefId)