ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilECSTreeReader.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
28  private ilLogger $logger;
29 
30  private int $server_id;
31  private int $mid;
32 
36  public function __construct(int $server_id, int $mid)
37  {
38  global $DIC;
39 
40  $this->logger = $DIC->logger()->wsrv();
41 
42  $this->server_id = $server_id;
43  $this->mid = $mid;
44  }
45 
46 
47 
53  public function read(): void
54  {
55  $this->logger->debug('Begin read');
56  $dir_reader = new ilECSDirectoryTreeConnector(
57  ilECSSetting::getInstanceByServerId($this->server_id)
58  );
59  $trees = $dir_reader->getDirectoryTrees();
60  $this->logger->debug(print_r($trees, true));
61  if ($trees instanceof ilECSUriList) {
62  foreach ($trees->getLinkIds() as $tree_id) {
63  if (!ilECSCmsData::treeExists($this->server_id, $this->mid, $tree_id)) {
64  $result = $dir_reader->getDirectoryTree($tree_id);
65  $this->storeTree($tree_id, $result->getResult());
66  }
67  }
68  }
69  }
70 
71  protected function storeTree($tree_id, $a_nodes): void
72  {
73  $tree = new ilECSCmsTree($tree_id);
74 
75 
76  $cms_tree = $a_nodes;
77 
78  $data = new ilECSCmsData();
79  $data->setServerId($this->server_id);
80  $data->setMid($this->mid);
81  $data->setCmsId($cms_tree->rootID);
82  $data->setTreeId($tree_id);
83  $data->setTitle($cms_tree->directoryTitle);
84  $data->setTerm($cms_tree->term);
85  $data->save();
86 
87  $tree->insertRootNode($tree_id, $data->getObjId());
88  $tree->setRootId($data->getObjId());
89 
90 
91  foreach ((array) $cms_tree->nodes as $node) {
92  // Add data entry
93  $data = new ilECSCmsData();
94  $data->setServerId($this->server_id);
95  $data->setMid($this->mid);
96  $data->setCmsId($node->id);
97  $data->setTreeId($tree_id);
98  $data->setTitle($node->title);
99  $data->setTerm($node->term);
100  $data->save();
101 
102  // add to tree
103  if ($node->parent->id) {
104  $parent_id = ilECSCmsData::lookupObjId(
105  $this->server_id,
106  $this->mid,
107  $tree_id,
108  $node->parent->id
109  );
110  $tree->insertNode($data->getObjId(), $parent_id);
111  }
112  }
113  }
114 }
read()
Read trees from ecs.
static treeExists(int $a_server_id, int $a_mid, int $a_tree_id)
static lookupObjId(int $a_server_id, int $a_mid, int $a_tree_id, string $cms_id)
Presentation of ecs uril (http://...campusconnect/courselinks)
__construct(int $server_id, int $mid)
Constructor.
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
global $DIC
Definition: shib_login.php:22
Reads and store cms tree in database.
storeTree($tree_id, $a_nodes)